// CCOS.Device.FPD.Test.cpp : 定义控制台应用程序的入口点。 // // CCOS.Device.Test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include #include #include using namespace std; using namespace std::placeholders; #include "CCOS.Dev.IODevice.hpp" #include "ResDataObject.h" #define CLEAR_BUFF {cin.ignore((std::numeric_limits::max)(), '\n');} #pragma warning(disable:26812) namespace eDEV = CCOS::Dev; static void OnNotify(int NotifyCode, std::string key, std::string context) { printf("OnNotify: code[%d], key[%s], value[%s] \n", NotifyCode, key.c_str(), context.c_str()); return; } static void OnDataNotify(int NotifyCode, std::string key, std::string in, std::string out, char* pImageData, int imageDataLength) { printf("OnDataNotify: code[%d], key[%s], in[%s], out[%s], ImageLengh[%d] \n", NotifyCode, key.c_str(), in.c_str(), out.c_str(), imageDataLength); return; } class t____Notify { public: void OnNotify___(int Code, std::string Key, std::string In) { } } Notify; //获取工作路径的目录 std::string LoadProcessDirectory() { string strProcessDIR = ""; char szTestProcess[MAX_PATH] = { 0 }; DWORD ret = ::GetModuleFileName(NULL, szTestProcess, MAX_PATH); if (ret == 0) { cout << "Get FPDTest process failed!!!" << endl; return strProcessDIR; } strProcessDIR = szTestProcess; string::size_type firstHit = strProcessDIR.find_last_of('\\'); if (firstHit == string::npos || firstHit == 0) { return strProcessDIR; } return strProcessDIR.substr(0, firstHit); } //加载测试配置 bool LoadTestCfg(const char* szConfigPath, std::string& strDllPath, std::string& strCfgPath) { ResDataObject TestCfg; if (!TestCfg.loadFile(szConfigPath)) { strDllPath = ""; strCfgPath = ""; cout << "Load test config filed!!!" << endl; return false; } try { strDllPath = (const char*)TestCfg["CONFIGURATION"]["LoadDll"]; strCfgPath = (const char*)TestCfg["CONFIGURATION"]["DriverXml"]; } catch (ResDataObjectExption& e) { strDllPath = ""; strCfgPath = ""; char szOut[256]; sprintf_s(szOut, "exception: %s\n", e.what()); cout << "Can not find config item, failed!!!" << endl; return false; } return true; } int _tmain(int argc, _TCHAR * argv[]) { cout << "-----StartFPDTest-----" << endl; string strConfigPath = LoadProcessDirectory().append("\\FPD.Test.xml"); string strDllPath = ""; string strCfgPath = ""; if (!LoadTestCfg(strConfigPath.c_str(), strDllPath, strCfgPath)) { return 0; } //加载测试设备DLL string strDllDir = strDllPath.substr(0, strDllPath.find_last_of('\\')); ::SetDllDirectory(strDllDir.c_str()); auto hDLL = ::LoadLibrary(strDllPath.c_str()); if (!hDLL) { DWORD dwErrorCode = ::GetLastError(); printf("LoadLibrary %s failed!!! ErrorCode: %d\n", strDllPath.c_str(), dwErrorCode); cin.get(); return 3; } cout << "Load dll success" << endl; auto fun = ::GetProcAddress(hDLL, "GetIODriver"); if (!fun) { DWORD dwErrorCode = ::GetLastError(); printf("LoadLibrary %s failed!!! ErrorCode: %d\n", strDllPath.c_str(), dwErrorCode); cin.get(); return 5; } //驱动入口 cout << "Driver loading..." << endl; auto pDriver = reinterpret_cast (fun()); assert(pDriver); pDriver->EventCenter->OnNotify.Push(OnNotify); pDriver->EventCenter->OnDataNotify.Push(OnDataNotify); pDriver->DriverEntry(strCfgPath); cout << "DriverEntry over" << endl; pDriver->Prepare(); cout << "Driver prepare over" << endl; pDriver->Connect(); cout << "Driver connect over" << endl; //string resResource = pDriver->GetResource(); //printf("\n\nGetDriverResource: %s \n ------------\n", resResource.c_str()); //设备入口 cout << "Device loading..." << endl; auto pDevice = pDriver->CreateDevice(0); assert(pDevice); cout << "Device create over" << endl; pDevice->Prepare(); cout << "Device prepare over" << endl; //string resResource = pDriver->GetResource(); //auto xguid = pDriver->GetGUID(); //pDriver->Connect(); //auto pDevice = pDriver->CreateDevice(0); //assert(pDevice); //resResource = pDevice->GetResource(); //printf("\nGetDeviceResource: 1\n %s \n ------1------\n", resResource.c_str()); //pDevice->Prepare(); //resResource = pDevice->GetResource(); //printf("\nGetDeviceResource: 2\n %s \n ------2------\n", resResource.c_str()); std::string rsp = ""; //pDevice->Action("EnterExam", R"({"ExamMode": "1"})", rsp); Sleep(8000); cout << "Start testing..." << endl; while (1) { char cOperation = { 0 }; std::string strInput = ""; char szParam[64] = { 0 }; std::string strParam = ""; rsp = ""; cout << "\nInput operation: 1(Action); 2(Get); 3(Set); 4(Exit)" << endl; cout << ">>>"; cOperation = getchar(); if ('1' == cOperation) { cout << "Input Action: "; CLEAR_BUFF cin >> strInput; cout << "Input Param: "; CLEAR_BUFF cin.getline(szParam, 64); strParam = szParam; cout << "Action: " << strInput << ", " << strParam << endl; pDevice->Action(strInput, strParam, rsp); cout << "Action over, return: " << rsp << endl; } else if ('2' == cOperation) { CLEAR_BUFF cout << "Input Get: "; cin >> strInput; cout << "Get: " << strInput << endl; pDevice->Get(strInput, rsp); cout << "Get over, return: " << rsp << endl; } else if ('3' == cOperation) { CLEAR_BUFF cout << "Input Set: "; cin >> strInput; cout << "Set: " << strInput << endl; pDevice->Set(strInput, rsp); cout << "Set over, return: " << rsp << endl; } else if ('4' == cOperation) { cout << "Quit test" << endl; break; } CLEAR_BUFF } cout << "Hit any key to quit" << endl; CLEAR_BUFF cin.get(); pDevice->Action("DisConnectFPD", "", rsp); cout << "Device disconnect over" << endl; ::FreeLibrary(hDLL); return 0; }