DIOS.Device.FPD.Test.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // CCOS.Device.FPD.Test.cpp : 定义控制台应用程序的入口点。
  2. //
  3. // CCOS.Device.Test.cpp : 定义控制台应用程序的入口点。
  4. //
  5. #include "stdafx.h"
  6. #include <Windows.h>
  7. #include <assert.h>
  8. #include <iostream>
  9. #include <functional>
  10. using namespace std;
  11. using namespace std::placeholders;
  12. #include "CCOS.Dev.IODevice.hpp"
  13. #include "ResDataObject.h"
  14. #define CLEAR_BUFF {cin.ignore((std::numeric_limits<streamsize>::max)(), '\n');}
  15. #pragma warning(disable:26812)
  16. namespace eDEV = CCOS::Dev;
  17. static void OnNotify(int NotifyCode, std::string key, std::string context)
  18. {
  19. printf("OnNotify: code[%d], key[%s], value[%s] \n", NotifyCode, key.c_str(), context.c_str());
  20. return;
  21. }
  22. static void OnDataNotify(int NotifyCode, std::string key, std::string in, std::string out, char* pImageData, int imageDataLength)
  23. {
  24. printf("OnDataNotify: code[%d], key[%s], in[%s], out[%s], ImageLengh[%d] \n", NotifyCode, key.c_str(), in.c_str(), out.c_str(), imageDataLength);
  25. return;
  26. }
  27. class t____Notify
  28. {
  29. public:
  30. void OnNotify___(int Code, std::string Key, std::string In)
  31. {
  32. }
  33. } Notify;
  34. //获取工作路径的目录
  35. std::string LoadProcessDirectory()
  36. {
  37. string strProcessDIR = "";
  38. char szTestProcess[MAX_PATH] = { 0 };
  39. DWORD ret = ::GetModuleFileName(NULL, szTestProcess, MAX_PATH);
  40. if (ret == 0)
  41. {
  42. cout << "Get FPDTest process failed!!!" << endl;
  43. return strProcessDIR;
  44. }
  45. strProcessDIR = szTestProcess;
  46. string::size_type firstHit = strProcessDIR.find_last_of('\\');
  47. if (firstHit == string::npos || firstHit == 0)
  48. {
  49. return strProcessDIR;
  50. }
  51. return strProcessDIR.substr(0, firstHit);
  52. }
  53. //加载测试配置
  54. bool LoadTestCfg(const char* szConfigPath, std::string& strDllPath, std::string& strCfgPath)
  55. {
  56. ResDataObject TestCfg;
  57. if (!TestCfg.loadFile(szConfigPath))
  58. {
  59. strDllPath = "";
  60. strCfgPath = "";
  61. cout << "Load test config filed!!!" << endl;
  62. return false;
  63. }
  64. try
  65. {
  66. strDllPath = (const char*)TestCfg["CONFIGURATION"]["LoadDll"];
  67. strCfgPath = (const char*)TestCfg["CONFIGURATION"]["DriverXml"];
  68. }
  69. catch (ResDataObjectExption& e)
  70. {
  71. strDllPath = "";
  72. strCfgPath = "";
  73. char szOut[256];
  74. sprintf_s(szOut, "exception: %s\n", e.what());
  75. cout << "Can not find config item, failed!!!" << endl;
  76. return false;
  77. }
  78. return true;
  79. }
  80. int _tmain(int argc, _TCHAR * argv[])
  81. {
  82. cout << "-----StartFPDTest-----" << endl;
  83. string strConfigPath = LoadProcessDirectory().append("\\FPD.Test.xml");
  84. string strDllPath = "";
  85. string strCfgPath = "";
  86. if (!LoadTestCfg(strConfigPath.c_str(), strDllPath, strCfgPath))
  87. {
  88. return 0;
  89. }
  90. //加载测试设备DLL
  91. string strDllDir = strDllPath.substr(0, strDllPath.find_last_of('\\'));
  92. ::SetDllDirectory(strDllDir.c_str());
  93. auto hDLL = ::LoadLibrary(strDllPath.c_str());
  94. if (!hDLL)
  95. {
  96. DWORD dwErrorCode = ::GetLastError();
  97. printf("LoadLibrary %s failed!!! ErrorCode: %d\n", strDllPath.c_str(), dwErrorCode);
  98. cin.get();
  99. return 3;
  100. }
  101. cout << "Load dll success" << endl;
  102. auto fun = ::GetProcAddress(hDLL, "GetIODriver");
  103. if (!fun)
  104. {
  105. DWORD dwErrorCode = ::GetLastError();
  106. printf("LoadLibrary %s failed!!! ErrorCode: %d\n", strDllPath.c_str(), dwErrorCode);
  107. cin.get();
  108. return 5;
  109. }
  110. //驱动入口
  111. cout << "Driver loading..." << endl;
  112. auto pDriver = reinterpret_cast <eDEV::IODriver*> (fun());
  113. assert(pDriver);
  114. pDriver->EventCenter->OnNotify.Push(OnNotify);
  115. pDriver->EventCenter->OnDataNotify.Push(OnDataNotify);
  116. pDriver->DriverEntry(strCfgPath);
  117. cout << "DriverEntry over" << endl;
  118. pDriver->Prepare();
  119. cout << "Driver prepare over" << endl;
  120. pDriver->Connect();
  121. cout << "Driver connect over" << endl;
  122. //string resResource = pDriver->GetResource();
  123. //printf("\n\nGetDriverResource: %s \n ------------\n", resResource.c_str());
  124. //设备入口
  125. cout << "Device loading..." << endl;
  126. auto pDevice = pDriver->CreateDevice(0);
  127. assert(pDevice);
  128. cout << "Device create over" << endl;
  129. pDevice->Prepare();
  130. cout << "Device prepare over" << endl;
  131. //string resResource = pDriver->GetResource();
  132. //auto xguid = pDriver->GetGUID();
  133. //pDriver->Connect();
  134. //auto pDevice = pDriver->CreateDevice(0);
  135. //assert(pDevice);
  136. //resResource = pDevice->GetResource();
  137. //printf("\nGetDeviceResource: 1\n %s \n ------1------\n", resResource.c_str());
  138. //pDevice->Prepare();
  139. //resResource = pDevice->GetResource();
  140. //printf("\nGetDeviceResource: 2\n %s \n ------2------\n", resResource.c_str());
  141. std::string rsp = "";
  142. //pDevice->Action("EnterExam", R"({"ExamMode": "1"})", rsp);
  143. Sleep(8000);
  144. cout << "Start testing..." << endl;
  145. while (1)
  146. {
  147. char cOperation = { 0 };
  148. std::string strInput = "";
  149. char szParam[64] = { 0 };
  150. std::string strParam = "";
  151. rsp = "";
  152. cout << "\nInput operation: 1(Action); 2(Get); 3(Set); 4(Exit)" << endl;
  153. cout << ">>>";
  154. cOperation = getchar();
  155. if ('1' == cOperation)
  156. {
  157. cout << "Input Action: ";
  158. CLEAR_BUFF
  159. cin >> strInput;
  160. cout << "Input Param: ";
  161. CLEAR_BUFF
  162. cin.getline(szParam, 64);
  163. strParam = szParam;
  164. cout << "Action: " << strInput << ", " << strParam << endl;
  165. pDevice->Action(strInput, strParam, rsp);
  166. cout << "Action over, return: " << rsp << endl;
  167. }
  168. else if ('2' == cOperation)
  169. {
  170. CLEAR_BUFF
  171. cout << "Input Get: ";
  172. cin >> strInput;
  173. cout << "Get: " << strInput << endl;
  174. pDevice->Get(strInput, rsp);
  175. cout << "Get over, return: " << rsp << endl;
  176. }
  177. else if ('3' == cOperation)
  178. {
  179. CLEAR_BUFF
  180. cout << "Input Set: ";
  181. cin >> strInput;
  182. cout << "Set: " << strInput << endl;
  183. pDevice->Set(strInput, rsp);
  184. cout << "Set over, return: " << rsp << endl;
  185. }
  186. else if ('4' == cOperation)
  187. {
  188. cout << "Quit test" << endl;
  189. break;
  190. }
  191. CLEAR_BUFF
  192. }
  193. cout << "Hit any key to quit" << endl;
  194. CLEAR_BUFF
  195. cin.get();
  196. pDevice->Action("DisConnectFPD", "", rsp);
  197. cout << "Device disconnect over" << endl;
  198. ::FreeLibrary(hDLL);
  199. return 0;
  200. }