DiosProcMFC.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // CcosProcMFC.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "CcosProcMFC.h"
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include "scf.h"
  8. #include "CDI.h"
  9. #include "LocalConfig.h"
  10. #include "WheelClient.h"
  11. #include "BusUnitClient.h"
  12. #include "CommonLogicClient.h"
  13. #include "WheelClient.h"
  14. //#include "AbstractSeq.h"
  15. #include "Logger.h"
  16. #include "common_api.h"
  17. //#include "SubSystem.h"
  18. #include "PacketAnalizer.h"
  19. //#include "CCOSLogicDeviceStructure.h"
  20. #include "ConsoleThread.h"
  21. #include "AutoDmp.h"
  22. #define CRTDBG_MAP_ALLOC
  23. #include <stdlib.h>
  24. #include <crtdbg.h>
  25. #include "ShareMemory_Client.h"
  26. AutoDmp atdmp;
  27. ConsoleThread g_ConsoleThread;
  28. bool StartConsoleThreads(bool start)
  29. {
  30. bool ret = true;
  31. if (start)
  32. {
  33. ret &= (g_ConsoleThread).StartThread();
  34. }
  35. else
  36. {
  37. (g_ConsoleThread).StopThread(100);
  38. }
  39. return ret;
  40. }
  41. #ifdef _DEBUG
  42. #define new DEBUG_NEW
  43. #endif
  44. // 唯一的应用程序对象
  45. CWinApp theApp;
  46. using namespace std;
  47. bool WINAPI ConsoleHandler(DWORD msgType)
  48. {
  49. if ((msgType == CTRL_CLOSE_EVENT) ||
  50. (msgType == CTRL_SHUTDOWN_EVENT))
  51. {
  52. printf("Close console window!\n");
  53. StartConsoleThreads(false);
  54. printf("StopThread Finished!\n");
  55. GetCommandDispathIF()->WaitExit(100, true);
  56. printf("WaitExit Finished!\n");
  57. Sleep(1000);
  58. /* Note: The system gives you very limited time to exit in this condition */
  59. return true;
  60. }
  61. /*
  62. Other messages:
  63. CTRL_BREAK_EVENT Ctrl-Break pressed
  64. CTRL_LOGOFF_EVENT User log off
  65. CTRL_SHUTDOWN_EVENT System shutdown
  66. */
  67. return false;
  68. }
  69. bool EntryCheck(int argc, _TCHAR* argv[])
  70. {
  71. //only one driver exist
  72. if (argc < 2)
  73. {
  74. printf("not Driver exist.exit in 3sec\n");
  75. Sleep(3000);
  76. return false;
  77. }
  78. for (int idx = 1; idx < argc; idx++)
  79. {
  80. printf("Add DriverConfig:%s\n", argv[idx]);
  81. if (AddDriverConfig(argv[idx]) == false)
  82. {
  83. printf("DriverConfig File not Right.%s \nexit in 3sec\n", argv[1]);
  84. Sleep(3000);
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
  90. int main_entry(int argc, TCHAR* argv[], TCHAR* envp[])
  91. {
  92. printf("Main Thread:%d\n", GetCurrentThreadId());
  93. if (EntryCheck(argc, argv) == false)
  94. {
  95. return false;
  96. }
  97. bool status = true;
  98. Sleep(1000);
  99. if (GetCommandDispathIF()->InitAs(CCOS_PROC_MASTER, (UINT64)GetCurrentProcessId()))
  100. {
  101. if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, true))
  102. {
  103. //WaitSomeInfo("Driver init Done.Press Any Key to show All Driver List\n", 1000);
  104. //1. do the bus test
  105. //Sleep(3000);
  106. {
  107. BusUnitClient buClient;
  108. if (buClient.Open((const char*)getRootpath(), ALL_ACCESS) == RET_SUCCEED)
  109. {
  110. //buClient.ExitDriverProc();
  111. buClient.Close();
  112. DWORD count = buClient.GetDeviceCount();
  113. for (DWORD i = 0; i < count; i++)
  114. {
  115. UINT64 ProcId, Addr;
  116. ResDataObject DevType,devpath, MachineId;
  117. buClient.GetDeviceDescript(i, devpath, DevType, MachineId, ProcId, Addr);
  118. printf("path:%s\nProc:%I64u\nAddr:%I64u\n", (const char*)devpath, ProcId, Addr);
  119. CommonLogicClient DevClient;
  120. if (DevClient.Open((const char*)devpath, ALL_ACCESS) >= RET_SUCCEED)
  121. {
  122. DevClient.Close();
  123. printf("Open Succeed\n");
  124. }
  125. else
  126. {
  127. printf("Open Failed\n");
  128. }
  129. }
  130. status = true;
  131. }
  132. else
  133. {
  134. status = false;
  135. }
  136. }
  137. //start work
  138. if (status)
  139. {
  140. if (StartConsoleThreads(true))
  141. {
  142. printf("Done Init Channel.going to sleep...\n");
  143. while (1){
  144. if (GetCommandDispathIF()->WaitExit(500) == true)
  145. {
  146. StartConsoleThreads(false);
  147. return 1;
  148. }
  149. }
  150. }
  151. }
  152. printf("Can't Start Console Thread.Exit in 3sec\n");
  153. Sleep(3000);
  154. return 0;
  155. }
  156. }
  157. return 0;
  158. }
  159. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  160. {
  161. int nRetCode = 0;
  162. HMODULE hModule = ::GetModuleHandle(NULL);
  163. if (hModule != NULL)
  164. {
  165. // 初始化 MFC 并在失败时显示错误
  166. if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
  167. {
  168. // TODO: 更改错误代码以符合您的需要
  169. _tprintf(_T("错误: MFC 初始化失败\n"));
  170. nRetCode = 1;
  171. }
  172. else
  173. {
  174. // TODO: 在此处为应用程序的行为编写代码。
  175. return main_entry(argc, argv, envp);
  176. }
  177. }
  178. else
  179. {
  180. // TODO: 更改错误代码以符合您的需要
  181. _tprintf(_T("错误: GetModuleHandle 失败\n"));
  182. nRetCode = 1;
  183. }
  184. return nRetCode;
  185. }