// CcosProcMFC.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "CcosProcMFC.h" #include #include #include "scf.h" #include "CDI.h" #include "LocalConfig.h" #include "WheelClient.h" #include "BusUnitClient.h" #include "CommonLogicClient.h" #include "WheelClient.h" //#include "AbstractSeq.h" #include "Logger.h" #include "common_api.h" //#include "SubSystem.h" #include "PacketAnalizer.h" //#include "CCOSLogicDeviceStructure.h" #include "ConsoleThread.h" #include "AutoDmp.h" #define CRTDBG_MAP_ALLOC #include #include #include "ShareMemory_Client.h" AutoDmp atdmp; ConsoleThread g_ConsoleThread; bool StartConsoleThreads(bool start) { bool ret = true; if (start) { ret &= (g_ConsoleThread).StartThread(); } else { (g_ConsoleThread).StopThread(100); } return ret; } #ifdef _DEBUG #define new DEBUG_NEW #endif // 唯一的应用程序对象 CWinApp theApp; using namespace std; bool WINAPI ConsoleHandler(DWORD msgType) { if ((msgType == CTRL_CLOSE_EVENT) || (msgType == CTRL_SHUTDOWN_EVENT)) { printf("Close console window!\n"); StartConsoleThreads(false); printf("StopThread Finished!\n"); GetCommandDispathIF()->WaitExit(100, true); printf("WaitExit Finished!\n"); Sleep(1000); /* Note: The system gives you very limited time to exit in this condition */ return true; } /* Other messages: CTRL_BREAK_EVENT Ctrl-Break pressed CTRL_LOGOFF_EVENT User log off CTRL_SHUTDOWN_EVENT System shutdown */ return false; } bool EntryCheck(int argc, _TCHAR* argv[]) { //only one driver exist if (argc < 2) { printf("not Driver exist.exit in 3sec\n"); Sleep(3000); return false; } for (int idx = 1; idx < argc; idx++) { printf("Add DriverConfig:%s\n", argv[idx]); if (AddDriverConfig(argv[idx]) == false) { printf("DriverConfig File not Right.%s \nexit in 3sec\n", argv[1]); Sleep(3000); return false; } } return true; } int main_entry(int argc, TCHAR* argv[], TCHAR* envp[]) { printf("Main Thread:%d\n", GetCurrentThreadId()); if (EntryCheck(argc, argv) == false) { return false; } bool status = true; Sleep(1000); if (GetCommandDispathIF()->InitAs(CCOS_PROC_MASTER, (UINT64)GetCurrentProcessId())) { if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, true)) { //WaitSomeInfo("Driver init Done.Press Any Key to show All Driver List\n", 1000); //1. do the bus test //Sleep(3000); { BusUnitClient buClient; if (buClient.Open((const char*)getRootpath(), ALL_ACCESS) == RET_SUCCEED) { //buClient.ExitDriverProc(); buClient.Close(); DWORD count = buClient.GetDeviceCount(); for (DWORD i = 0; i < count; i++) { UINT64 ProcId, Addr; ResDataObject DevType,devpath, MachineId; buClient.GetDeviceDescript(i, devpath, DevType, MachineId, ProcId, Addr); printf("path:%s\nProc:%I64u\nAddr:%I64u\n", (const char*)devpath, ProcId, Addr); CommonLogicClient DevClient; if (DevClient.Open((const char*)devpath, ALL_ACCESS) >= RET_SUCCEED) { DevClient.Close(); printf("Open Succeed\n"); } else { printf("Open Failed\n"); } } status = true; } else { status = false; } } //start work if (status) { if (StartConsoleThreads(true)) { printf("Done Init Channel.going to sleep...\n"); while (1){ if (GetCommandDispathIF()->WaitExit(500) == true) { StartConsoleThreads(false); return 1; } } } } printf("Can't Start Console Thread.Exit in 3sec\n"); Sleep(3000); return 0; } } return 0; } int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; HMODULE hModule = ::GetModuleHandle(NULL); if (hModule != NULL) { // 初始化 MFC 并在失败时显示错误 if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0)) { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("错误: MFC 初始化失败\n")); nRetCode = 1; } else { // TODO: 在此处为应用程序的行为编写代码。 return main_entry(argc, argv, envp); } } else { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("错误: GetModuleHandle 失败\n")); nRetCode = 1; } return nRetCode; }