GetDevInfoHelper.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. #pragma once
  2. #include "SpHelper.h"
  3. #include "SpFSM.h"
  4. #include "SimpleString.h"
  5. #include "Blob.h"
  6. #include "SpBase.h"
  7. #include <regex>
  8. /*------20200221------*/
  9. //modify by LZM
  10. ErrorCodeEnum VendorLogControlerEx(CEntityBase *pEntity,CSimpleStringA moduleName)
  11. {
  12. #ifdef RVC_WIN_OS
  13. //get Device Information.
  14. CSystemStaticInfo DevInfo;
  15. pEntity->GetFunction()->GetSystemStaticInfo(DevInfo);
  16. Dbg("Terminal NUM=%s",DevInfo.strTerminalID);
  17. //read root.ini and get vendor,version,batch.
  18. CSmartPointer<IConfigInfo> rootConfig;
  19. ErrorCodeEnum eErrDev = pEntity->GetFunction()->OpenConfig(Config_Root,rootConfig);
  20. if (eErrDev != Error_Succeed) {
  21. Dbg("open Config_Root file failed!");
  22. return eErrDev;
  23. }
  24. CSimpleStringA strVendor,strVersion,strBatch;
  25. CSimpleStringA strTmp = CSimpleStringA::Format("Device.%s",moduleName.GetData());
  26. Dbg("strTmp=%s",strTmp);
  27. eErrDev = rootConfig->ReadConfigValue(strTmp,"Vendor",strVendor);
  28. if(eErrDev != Error_Succeed || strVendor.IsNullOrEmpty()){
  29. Dbg("read vendor failed!");
  30. return eErrDev;
  31. }
  32. eErrDev = rootConfig->ReadConfigValue(strTmp,"Version",strVersion);
  33. if(eErrDev != Error_Succeed || strVersion.IsNullOrEmpty()){
  34. Dbg("read version failed!");
  35. return eErrDev;
  36. }
  37. eErrDev = rootConfig->ReadConfigValue(strTmp,"Batch",strBatch);
  38. if(eErrDev != Error_Succeed || strBatch.IsNullOrEmpty()){
  39. Dbg("read batch failed!");
  40. return eErrDev;
  41. }
  42. Dbg("strVendor=%s",strVendor);
  43. Dbg("strVersion=%s",strVersion);
  44. Dbg("strBatch=%s",strBatch);
  45. //read CenterSetting get VendorRecodeLevel,VendorRecodeType,WhiteNameSheet.
  46. CSmartPointer<IConfigInfo> centerConfig;
  47. eErrDev = pEntity->GetFunction()->OpenConfig(Config_CenterSetting,centerConfig);
  48. if (eErrDev != Error_Succeed) {
  49. Dbg("open Config_CenterSetting file failed!");
  50. return eErrDev;
  51. }
  52. CSimpleStringA strVendorRecodeLevel,strVendorRecodeType,strVendorDllName,strVendorLogPath;
  53. eErrDev = centerConfig->ReadConfigValue(moduleName,strVendor.GetData(),strVendorRecodeLevel);
  54. if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty())
  55. {
  56. eErrDev = centerConfig->ReadConfigValue(moduleName,"All",strVendorRecodeLevel);
  57. if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty())
  58. {
  59. //default level:OFF.
  60. strVendorRecodeLevel = "OFF";
  61. }
  62. }
  63. //WhiteNameSheet is avaliable.
  64. if (strVendorRecodeLevel.Compare("OFF") != 0)
  65. {
  66. //get WhiteNameSheet
  67. CSimpleStringA strWhiteNameSheet;
  68. eErrDev = centerConfig->ReadConfigValue(moduleName,"AllowTerminals",strWhiteNameSheet);
  69. if (!strWhiteNameSheet.IsNullOrEmpty())
  70. {
  71. bool bWhiteNameSheet = false;
  72. CAutoArray<CSimpleStringA> arrayWhiteNameSheet = strWhiteNameSheet.Split(',');
  73. for (int i=0;i<arrayWhiteNameSheet.GetCount();i++)
  74. {
  75. std::regex pattern(arrayWhiteNameSheet[i]);
  76. if(std::regex_match(DevInfo.strTerminalID.GetData(),pattern))
  77. {
  78. bWhiteNameSheet = true;
  79. break;
  80. }
  81. }
  82. //if this terminal is not at WhiteNameSheet,set level with "OFF".
  83. if(!bWhiteNameSheet) strVendorRecodeLevel = "OFF";
  84. }
  85. }
  86. eErrDev = centerConfig->ReadConfigValue(moduleName,"Type",strVendorRecodeType);
  87. if(eErrDev!=Error_Succeed || strVendorRecodeType.IsNullOrEmpty())
  88. {
  89. //default type:FILE.
  90. strVendorRecodeType = "FILE";
  91. }
  92. strVendorDllName = moduleName + "." + strVendor+"."+strVersion+"."+strBatch+".dll";
  93. TCHAR szPath[MAX_PATH] = {0};
  94. GetModuleFileNameA(NULL, szPath, MAX_PATH);
  95. CSimpleStringA strDir = szPath;
  96. strVendorLogPath = strDir.SubString(0,1);
  97. strVendorLogPath += ":/rvc/dbg";
  98. Dbg("VENDOR_RECODE_LEVEL=%s",strVendorRecodeLevel);
  99. Dbg("VENDOR_RECODE_TYPE=%s",strVendorRecodeType);
  100. Dbg("VENDOR_DLL_NAME=%s",strVendorDllName);
  101. Dbg("VENDOR_LOG_PATH=%s",strVendorLogPath);
  102. if(!SetEnvironmentVariableA("VENDOR_RECODE_LEVEL",strVendorRecodeLevel.GetData())){
  103. Dbg("Set VENDOR_RECODE_LEVEL Variable Failed.");
  104. }
  105. if(!SetEnvironmentVariableA("VENDOR_RECODE_TYPE",strVendorRecodeType.GetData())){
  106. Dbg("Set VENDOR_RECODE_TYPE Variable Failed.");
  107. }
  108. if(!SetEnvironmentVariableA("VENDOR_DLL_NAME",strVendorDllName.GetData())){
  109. Dbg("Set VENDOR_DLL_NAME Variable Failed.");
  110. }
  111. if(!SetEnvironmentVariableA("VENDOR_LOG_PATH",strVendorLogPath.GetData())){
  112. Dbg("Set VENDOR_LOG_PATH Variable Failed.");
  113. }
  114. #else
  115. #endif
  116. return Error_Succeed;
  117. }
  118. ErrorCodeEnum VendorLogControler(FSMBase *pFSM,CSimpleStringA moduleName)
  119. {
  120. return VendorLogControlerEx(pFSM->GetEntityBase(),moduleName);
  121. }
  122. /*--------------------*/
  123. //#define DeviceService_Method_GetDevInfo 65535
  124. //#define DeviceService_MethodSignature_GetDevInfo 296205965
  125. //
  126. //struct DeviceService_GetDevInfo_Req
  127. //{
  128. // void Serialize(SpBuffer &Buf)
  129. // {
  130. // }
  131. //};
  132. //
  133. //struct DeviceService_GetDevInfo_Ans
  134. //{
  135. // CSimpleStringA type;
  136. // CSimpleStringA model;
  137. // CSimpleStringA vendor;
  138. // int state;
  139. // WORD wMajor; //release major version
  140. // WORD wMinor; //release minor version
  141. // WORD wRevision; //bug repair version with the major and minor version remains the same
  142. // WORD wBuild; //compile version
  143. //
  144. // void Serialize(SpBuffer &Buf)
  145. // {
  146. // Buf & type & model & vendor & state & wMajor & wMinor & wRevision & wBuild;
  147. // }
  148. //};
  149. //
  150. //class DeviceService_ClientBase : public CClientSessionBase {
  151. //public:
  152. // DeviceService_ClientBase(CEntityBase *pEntity) : m_pEntityBase(pEntity), m_bSysManaged(false) {}
  153. //
  154. //protected:
  155. // virtual ~DeviceService_ClientBase() {}
  156. //
  157. //public:
  158. //
  159. // ErrorCodeEnum Connect(CSmartPointer<IAsynWaitSp> &spAsyncWait, const CSimpleStringA &strRemoteEntity)
  160. // {
  161. // CSmartPointer<IEntityFunction> pFunc = m_pEntityBase->GetFunction();
  162. //
  163. // CSimpleStringA strServiceName = strRemoteEntity + "Service";
  164. // ErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, (const char*)strRemoteEntity, (const char*)strServiceName, spAsyncWait);
  165. // if (Error == Error_Succeed) {
  166. // m_bSysManaged = true;
  167. // }
  168. // return Error;
  169. // }
  170. //
  171. // ErrorCodeEnum Connect(const CSimpleStringA &strRemoteEntity)
  172. // {
  173. // CSmartPointer<IAsynWaitSp> spAsyncWait;
  174. // ErrorCodeEnum Error = Connect(spAsyncWait, strRemoteEntity);
  175. // if (Error == Error_Succeed) {
  176. // Error = spAsyncWait->WaitAnswer();
  177. // }
  178. // return Error;
  179. // }
  180. //
  181. // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, CSmartPointer<IAsynWaitSp> &spAsyncWait, DWORD dwTimeout)
  182. // {
  183. // CSmartPointer<IClientSessionFunction> pFunc = GetFunction();
  184. // CAutoBuffer Buf = SpObject2Buffer(Req);
  185. // return pFunc->AsyncRequest(DeviceService_Method_GetDevInfo, DeviceService_MethodSignature_GetDevInfo, Buf, spAsyncWait, dwTimeout);
  186. // }
  187. //
  188. // ErrorCodeEnum GetDevInfo(DeviceService_GetDevInfo_Req &Req, DeviceService_GetDevInfo_Ans &Ans, DWORD dwTimeout)
  189. // {
  190. // CSmartPointer<IAsynWaitSp> spAsyncWait;
  191. // ErrorCodeEnum Error = GetDevInfo(Req, spAsyncWait, dwTimeout);
  192. // if (Error == Error_Succeed) {
  193. // bool bEnd = false;
  194. // Error = SpWaitAnswerObject(spAsyncWait, Ans, bEnd);
  195. // LOG_ASSERT(Error || bEnd);
  196. // }
  197. // return Error;
  198. // }
  199. //
  200. // bool SafeDelete()
  201. // {
  202. // if (!m_bSysManaged) {
  203. // delete this;
  204. // }
  205. // return m_bSysManaged;
  206. // }
  207. //
  208. //protected:
  209. // bool m_bSysManaged;
  210. // CEntityBase *m_pEntityBase;
  211. //};
  212. //
  213. //ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pEntity, const CSimpleStringA &devDevEntityName,
  214. // CSimpleStringA &strType, CSimpleStringA &strModel, CSimpleStringA &strVendor, int &nState, CBlob &blobVersion)
  215. //{
  216. // DeviceService_ClientBase *pClient = new DeviceService_ClientBase(pEntity);
  217. // ErrorCodeEnum rc = pClient->Connect(devDevEntityName);
  218. // if (rc == Error_Succeed)
  219. // {
  220. // DeviceService_GetDevInfo_Req req;
  221. // DeviceService_GetDevInfo_Ans ans;
  222. // rc = pClient->GetDevInfo(req, ans, 5000);
  223. // if (rc == Error_Succeed)
  224. // {
  225. // strType = ans.type;
  226. // strModel = ans.model;
  227. // strVendor = ans.vendor;
  228. // nState = ans.state;
  229. // blobVersion.Alloc(8);
  230. // ((BYTE*)blobVersion.m_pData)[0] = (ans.wMajor >> 8) & 0xFF;
  231. // ((BYTE*)blobVersion.m_pData)[1] = ans.wMajor & 0xFF;
  232. // ((BYTE*)blobVersion.m_pData)[2] = (ans.wMinor >> 8) & 0xFF;
  233. // ((BYTE*)blobVersion.m_pData)[3] = ans.wMinor & 0xFF;
  234. // ((BYTE*)blobVersion.m_pData)[4] = (ans.wRevision >> 8) & 0xFF;
  235. // ((BYTE*)blobVersion.m_pData)[5] = ans.wRevision & 0xFF;
  236. // ((BYTE*)blobVersion.m_pData)[6] = (ans.wBuild >> 8) & 0xFF;
  237. // ((BYTE*)blobVersion.m_pData)[7] = ans.wBuild & 0xFF;
  238. // }
  239. // pClient->GetFunction()->CloseSession();
  240. // }
  241. // pClient->SafeDelete();
  242. // return rc;
  243. //}
  244. ErrorCodeEnum SpGetAllDevices(CEntityBase *pEntity, CAutoArray<CSimpleStringA> &devs)
  245. {
  246. CSmartPointer<IConfigInfo> pConfig;
  247. ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  248. if (rc == Error_Succeed)
  249. {
  250. int nCount(0);
  251. rc = pConfig->ReadConfigValueInt("Device", "Number", nCount);
  252. if (rc == Error_Succeed && nCount>0)
  253. {
  254. devs.Init(nCount);
  255. for(int i=0; i<nCount; i++)
  256. {
  257. CSimpleStringA str = CSimpleStringA::Format("%d", i+1);
  258. rc = pConfig->ReadConfigValue("Device", (const char*)str, devs[i]);
  259. }
  260. }
  261. }
  262. return rc;
  263. }
  264. ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName,
  265. CSimpleStringA &strModel, CSimpleStringA &strVendor, CSimpleStringA &strVersion)
  266. {
  267. CSmartPointer<IConfigInfo> pConfig;
  268. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  269. if (rc == Error_Succeed)
  270. {
  271. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  272. pConfig->ReadConfigValue(strSection, "Vendor", strVendor);
  273. pConfig->ReadConfigValue(strSection, "Version", strVersion);
  274. strModel = devDeviceName;
  275. if (!strVendor.IsNullOrEmpty())
  276. {
  277. strModel += ".";
  278. strModel += strVendor;
  279. }
  280. if (!strVersion.IsNullOrEmpty())
  281. {
  282. strModel += ".";
  283. strModel += strVersion;
  284. }
  285. }
  286. return rc;
  287. }
  288. ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase *pCallerEntity,
  289. const CSimpleStringA &devDeviceName,
  290. CSimpleStringA &strDevAdaptorPath)
  291. {
  292. CSmartPointer<IConfigInfo> pConfig;
  293. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  294. if (rc == Error_Succeed)
  295. {
  296. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  297. strDevAdaptorPath = devDeviceName;
  298. CSimpleStringA str;
  299. pConfig->ReadConfigValue(strSection, "Vendor", str);
  300. if (!str.IsNullOrEmpty())
  301. {
  302. strDevAdaptorPath += ".";
  303. strDevAdaptorPath += str;
  304. }
  305. str.Clear();
  306. pConfig->ReadConfigValue(strSection, "Version", str);
  307. if (!str.IsNullOrEmpty())
  308. {
  309. strDevAdaptorPath += ".";
  310. strDevAdaptorPath += str;
  311. }
  312. str.Clear();
  313. pConfig->ReadConfigValue(strSection, "Batch", str);
  314. if (!str.IsNullOrEmpty())
  315. {
  316. strDevAdaptorPath += ".";
  317. strDevAdaptorPath += str;
  318. }
  319. CSimpleStringA strDepPath;
  320. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  321. #ifdef RVC_OS_WIN
  322. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  323. (const char*)strDepPath,
  324. (const char*)strDevAdaptorPath);
  325. #else
  326. strDevAdaptorPath = CSimpleStringA::Format("%s/%s.so",
  327. (const char*)strDepPath,
  328. (const char*)strDevAdaptorPath);
  329. #endif
  330. }
  331. return rc;
  332. }
  333. // add by ly
  334. ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex,
  335. CEntityBase *pCallerEntity,
  336. const CSimpleStringA &devDeviceName,
  337. CSimpleStringA &strDevAdaptorPath)
  338. {
  339. CSmartPointer<IConfigInfo> pConfig;
  340. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  341. if (rc == Error_Succeed)
  342. {
  343. char tmp[64] = {0};
  344. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  345. strDevAdaptorPath = devDeviceName;
  346. CSimpleStringA str;
  347. sprintf(tmp, "Vendor_%d", nIndex);
  348. pConfig->ReadConfigValue(strSection, tmp, str);
  349. if (!str.IsNullOrEmpty())
  350. {
  351. strDevAdaptorPath += ".";
  352. strDevAdaptorPath += str;
  353. }
  354. str.Clear();
  355. sprintf(tmp, "Version_%d", nIndex);
  356. pConfig->ReadConfigValue(strSection, tmp, str);
  357. if (!str.IsNullOrEmpty())
  358. {
  359. strDevAdaptorPath += ".";
  360. strDevAdaptorPath += str;
  361. }
  362. str.Clear();
  363. sprintf(tmp, "Batch_%d", nIndex);
  364. pConfig->ReadConfigValue(strSection, tmp, str);
  365. if (!str.IsNullOrEmpty())
  366. {
  367. strDevAdaptorPath += ".";
  368. strDevAdaptorPath += str;
  369. }
  370. CSimpleStringA strDepPath;
  371. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  372. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  373. (const char*)strDepPath,
  374. (const char*)strDevAdaptorPath);
  375. }
  376. return rc;
  377. }
  378. // BranchDevice [Josephus in 16:32:09 2016/6/22]
  379. ErrorCodeEnum SpGetBrDevAdaptorPath(CEntityBase *pCallerEntity,
  380. const CSimpleStringA &devDeviceName,
  381. CSimpleStringA &strDevAdaptorPath)
  382. {
  383. CSmartPointer<IConfigInfo> pConfig;
  384. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  385. if (rc == Error_Succeed)
  386. {
  387. CSimpleStringA strSection = CSimpleStringA("BranchDevice.") + devDeviceName;
  388. strDevAdaptorPath = devDeviceName;
  389. CSimpleStringA str;
  390. pConfig->ReadConfigValue(strSection, "Branch", str);
  391. if (!str.IsNullOrEmpty())
  392. {
  393. strDevAdaptorPath += ".";
  394. strDevAdaptorPath += str;
  395. }
  396. str.Clear();
  397. pConfig->ReadConfigValue(strSection, "Version", str);
  398. if (!str.IsNullOrEmpty())
  399. {
  400. strDevAdaptorPath += ".";
  401. strDevAdaptorPath += str;
  402. }
  403. str.Clear();
  404. pConfig->ReadConfigValue(strSection, "Batch", str);
  405. if (!str.IsNullOrEmpty())
  406. {
  407. strDevAdaptorPath += ".";
  408. strDevAdaptorPath += str;
  409. }
  410. CSimpleStringA strDepPath;
  411. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  412. //strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  413. // (const char*)strDepPath,
  414. // (const char*)strDevAdaptorPath);
  415. strDevAdaptorPath = CSimpleStringA::Format("%s.dll", (const char*)strDevAdaptorPath);
  416. }
  417. return rc;
  418. }
  419. ErrorCodeEnum IsNeedOpenUsb(CEntityBase *pCallerEntity, bool& bNeedOpenUsb)
  420. {
  421. ErrorCodeEnum errCode = Error_Unexpect;
  422. CSystemStaticInfo sysDevInfo;
  423. errCode = pCallerEntity->GetFunction()->GetSystemStaticInfo(sysDevInfo);
  424. if(errCode != Error_Succeed){
  425. Dbg("get device info failed while judge open usb or not");
  426. }else{
  427. CSimpleStringA strMachineType;
  428. strMachineType = sysDevInfo.strMachineType;
  429. WORD majorVersion = sysDevInfo.MachineVersion.GetMajor();
  430. WORD minorVersion = sysDevInfo.MachineVersion.GetMinor();
  431. CSimpleStringA machineVersion = CSimpleStringA::Format("%d.%d", majorVersion, minorVersion);
  432. Dbg("MachineType:%s, machineVersion:%s", strMachineType.GetData(), machineVersion.GetData());
  433. if(!strMachineType.Compare("RVC.PAD", true)
  434. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("1.0")))
  435. {
  436. bNeedOpenUsb = false;
  437. }
  438. else if(!strMachineType.Compare("RVC.Stand2S", true) || !strMachineType.Compare("RVC.CardStore", true)
  439. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.0"))
  440. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.1"))
  441. || (!strMachineType.Compare("RVC.Desk1S", true) && !machineVersion.Compare("1.0")))
  442. {
  443. bNeedOpenUsb = true;
  444. }
  445. else
  446. {
  447. //TODO:: if add new machine type
  448. bNeedOpenUsb = true;
  449. }
  450. }
  451. return errCode;
  452. }