123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- // CcosProcMFC.cpp : 定义控制台应用程序的入口点。
- //
- #include "stdafx.h"
- #include "CcosProcMFC.h"
- #include <conio.h>
- #include <stdio.h>
- #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 <stdlib.h>
- #include <crtdbg.h>
- #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;
- }
|