GetDevInfoHelper.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. ErrorCodeEnum SpGetAllDevices(CEntityBase* pEntity, CAutoArray<CSimpleStringA>& devs)
  124. {
  125. CSmartPointer<IConfigInfo> pConfig;
  126. ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  127. if (rc == Error_Succeed)
  128. {
  129. int nCount(0);
  130. rc = pConfig->ReadConfigValueInt("Device", "Number", nCount);
  131. if (rc == Error_Succeed && nCount > 0)
  132. {
  133. devs.Init(nCount);
  134. for (int i = 0; i < nCount; i++)
  135. {
  136. CSimpleStringA str = CSimpleStringA::Format("%d", i + 1);
  137. rc = pConfig->ReadConfigValue("Device", (const char*)str, devs[i]);
  138. }
  139. }
  140. }
  141. return rc;
  142. }
  143. ErrorCodeEnum SpGetDeviceInfo(CEntityBase* pCallerEntity, const CSimpleStringA& devDeviceName,
  144. CSimpleStringA& strModel, CSimpleStringA& strVendor, CSimpleStringA& strVersion)
  145. {
  146. CSmartPointer<IConfigInfo> pConfig;
  147. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  148. if (rc == Error_Succeed)
  149. {
  150. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  151. pConfig->ReadConfigValue(strSection, "Vendor", strVendor);
  152. pConfig->ReadConfigValue(strSection, "Version", strVersion);
  153. strModel = devDeviceName;
  154. if (!strVendor.IsNullOrEmpty())
  155. {
  156. strModel += ".";
  157. strModel += strVendor;
  158. }
  159. if (!strVersion.IsNullOrEmpty())
  160. {
  161. strModel += ".";
  162. strModel += strVersion;
  163. }
  164. }
  165. return rc;
  166. }
  167. ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase* pCallerEntity,
  168. const CSimpleStringA& devDeviceName,
  169. CSimpleStringA& strDevAdaptorPath)
  170. {
  171. CSmartPointer<IConfigInfo> pConfig;
  172. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  173. if (rc == Error_Succeed)
  174. {
  175. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  176. strDevAdaptorPath = devDeviceName;
  177. CSimpleStringA str;
  178. pConfig->ReadConfigValue(strSection, "Vendor", str);
  179. if (!str.IsNullOrEmpty())
  180. {
  181. strDevAdaptorPath += ".";
  182. strDevAdaptorPath += str;
  183. }
  184. str.Clear();
  185. pConfig->ReadConfigValue(strSection, "Version", str);
  186. if (!str.IsNullOrEmpty())
  187. {
  188. strDevAdaptorPath += ".";
  189. strDevAdaptorPath += str;
  190. }
  191. str.Clear();
  192. pConfig->ReadConfigValue(strSection, "Batch", str);
  193. if (!str.IsNullOrEmpty())
  194. {
  195. strDevAdaptorPath += ".";
  196. strDevAdaptorPath += str;
  197. }
  198. CSimpleStringA strDepPath;
  199. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  200. #ifdef RVC_OS_WIN
  201. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  202. (const char*)strDepPath,
  203. (const char*)strDevAdaptorPath);
  204. #else
  205. strDevAdaptorPath = CSimpleStringA::Format("%s/lib%s.so",
  206. (const char*)strDepPath,
  207. (const char*)strDevAdaptorPath);
  208. #endif
  209. }
  210. return rc;
  211. }
  212. // add by ly
  213. ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex,
  214. CEntityBase* pCallerEntity,
  215. const CSimpleStringA& devDeviceName,
  216. CSimpleStringA& strDevAdaptorPath)
  217. {
  218. CSmartPointer<IConfigInfo> pConfig;
  219. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  220. if (rc == Error_Succeed)
  221. {
  222. char tmp[64] = { 0 };
  223. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  224. strDevAdaptorPath = devDeviceName;
  225. CSimpleStringA str;
  226. sprintf(tmp, "Vendor_%d", nIndex);
  227. pConfig->ReadConfigValue(strSection, tmp, str);
  228. if (!str.IsNullOrEmpty())
  229. {
  230. strDevAdaptorPath += ".";
  231. strDevAdaptorPath += str;
  232. }
  233. str.Clear();
  234. sprintf(tmp, "Version_%d", nIndex);
  235. pConfig->ReadConfigValue(strSection, tmp, str);
  236. if (!str.IsNullOrEmpty())
  237. {
  238. strDevAdaptorPath += ".";
  239. strDevAdaptorPath += str;
  240. }
  241. str.Clear();
  242. sprintf(tmp, "Batch_%d", nIndex);
  243. pConfig->ReadConfigValue(strSection, tmp, str);
  244. if (!str.IsNullOrEmpty())
  245. {
  246. strDevAdaptorPath += ".";
  247. strDevAdaptorPath += str;
  248. }
  249. CSimpleStringA strDepPath;
  250. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  251. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  252. (const char*)strDepPath,
  253. (const char*)strDevAdaptorPath);
  254. }
  255. return rc;
  256. }
  257. // BranchDevice [Josephus in 16:32:09 2016/6/22]
  258. ErrorCodeEnum SpGetBrDevAdaptorPath(CEntityBase* pCallerEntity,
  259. const CSimpleStringA& devDeviceName,
  260. CSimpleStringA& strDevAdaptorPath)
  261. {
  262. CSmartPointer<IConfigInfo> pConfig;
  263. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  264. if (rc == Error_Succeed)
  265. {
  266. CSimpleStringA strSection = CSimpleStringA("BranchDevice.") + devDeviceName;
  267. strDevAdaptorPath = devDeviceName;
  268. CSimpleStringA str;
  269. pConfig->ReadConfigValue(strSection, "Branch", str);
  270. if (!str.IsNullOrEmpty())
  271. {
  272. strDevAdaptorPath += ".";
  273. strDevAdaptorPath += str;
  274. }
  275. str.Clear();
  276. pConfig->ReadConfigValue(strSection, "Version", str);
  277. if (!str.IsNullOrEmpty())
  278. {
  279. strDevAdaptorPath += ".";
  280. strDevAdaptorPath += str;
  281. }
  282. str.Clear();
  283. pConfig->ReadConfigValue(strSection, "Batch", str);
  284. if (!str.IsNullOrEmpty())
  285. {
  286. strDevAdaptorPath += ".";
  287. strDevAdaptorPath += str;
  288. }
  289. CSimpleStringA strDepPath;
  290. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  291. //strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  292. // (const char*)strDepPath,
  293. // (const char*)strDevAdaptorPath);
  294. strDevAdaptorPath = CSimpleStringA::Format("%s.dll", (const char*)strDevAdaptorPath);
  295. }
  296. return rc;
  297. }
  298. ErrorCodeEnum IsNeedOpenUsb(CEntityBase* pCallerEntity, bool& bNeedOpenUsb)
  299. {
  300. ErrorCodeEnum errCode = Error_Unexpect;
  301. CSystemStaticInfo sysDevInfo;
  302. errCode = pCallerEntity->GetFunction()->GetSystemStaticInfo(sysDevInfo);
  303. if (errCode != Error_Succeed) {
  304. Dbg("get device info failed while judge open usb or not");
  305. }
  306. else {
  307. CSimpleStringA strMachineType;
  308. strMachineType = sysDevInfo.strMachineType;
  309. WORD majorVersion = sysDevInfo.MachineVersion.GetMajor();
  310. WORD minorVersion = sysDevInfo.MachineVersion.GetMinor();
  311. CSimpleStringA machineVersion = CSimpleStringA::Format("%d.%d", majorVersion, minorVersion);
  312. Dbg("MachineType:%s, machineVersion:%s", strMachineType.GetData(), machineVersion.GetData());
  313. if (!strMachineType.Compare("RVC.PAD", true)
  314. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("1.0")))
  315. {
  316. bNeedOpenUsb = false;
  317. }
  318. else if (!strMachineType.Compare("RVC.Stand2S", true) || !strMachineType.Compare("RVC.CardStore", true)
  319. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.0"))
  320. || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.1"))
  321. || (!strMachineType.Compare("RVC.Desk1S", true) && !machineVersion.Compare("1.0")))
  322. {
  323. bNeedOpenUsb = true;
  324. }
  325. else
  326. {
  327. //TODO:: if add new machine type
  328. bNeedOpenUsb = true;
  329. }
  330. }
  331. return errCode;
  332. }