DeviceBaseHelper.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef __DEVICEBASE_HELPER_H
  2. #define __DEVICEBASE_HELPER_H
  3. #pragma once
  4. #include "DeviceBaseClass.h"
  5. enum DeviceType
  6. {
  7. PinPadClassType
  8. };
  9. class DeviceBaseHelper
  10. {
  11. public:
  12. static DeviceBaseClass* QueryDevComponent(const char *lpszRVCRunPath, DeviceType eDevType)
  13. {
  14. char root_path[MAX_PATH];
  15. sprintf(root_path, "%s\\hardwarecfg\\root.ini", lpszRVCRunPath);
  16. }
  17. static ErrorCodeEnum GetAndSplitDevErrInfo(
  18. DeviceBaseClass* inst,
  19. CSimpleStringA& csErrMsg,
  20. WORD& wdDevErrCode,
  21. LPCTSTR lpszFuncNameForDisplay = ""
  22. )
  23. {
  24. csErrMsg = "";
  25. wdDevErrCode = 0;
  26. BOOL bDisplayFunName = TRUE;
  27. if( lpszFuncNameForDisplay == NULL || strlen(lpszFuncNameForDisplay) == 0 )
  28. bDisplayFunName = FALSE;
  29. if(inst == NULL)
  30. {
  31. Dbg("inst occurs nullptr !!!");
  32. return Error_Param;
  33. }
  34. DevErrorInfo devErrInfo;
  35. ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
  36. ErrorCodeEnum erroCode = inst->GetLastErr(devErrInfo);
  37. if(erroCode == Error_Succeed)
  38. {
  39. if(strlen(devErrInfo.szErrMsg) > 0)
  40. {
  41. csErrMsg = devErrInfo.szErrMsg;
  42. }
  43. if(devErrInfo.dwErrMsgLen > MAX_DEV_ERROR_MSG_LEN)
  44. {
  45. //oiltmp@20200520 comment the following line
  46. //wdDevErrCode = (WORD)((devErrInfo.dwErrMsgLen >> 16) & 0x0000FFFF);
  47. }
  48. if(bDisplayFunName)
  49. {
  50. Dbg("Invoke <%s> failed, Dev_GLE: DevErrCode[%d], ErrMsg[%s]",
  51. lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
  52. }
  53. else
  54. {
  55. Dbg("Dev_GLE: DevErrCode[%d], ErrMsg[%s]", wdDevErrCode, (LPCTSTR)csErrMsg);
  56. }
  57. }
  58. else
  59. {
  60. if(bDisplayFunName)
  61. {
  62. Dbg("Invoke <%s> failed, and unfortunately Dev_GLE failed returned EC: %d(0x%X)",
  63. lpszFuncNameForDisplay, erroCode, erroCode);
  64. csErrMsg = CSimpleStringA::Format("Invoke <%s> failed", lpszFuncNameForDisplay);
  65. }
  66. else
  67. {
  68. Dbg("Dev_GLE failed returned EC: %d(0x%X)",
  69. erroCode, erroCode);
  70. }
  71. }
  72. return erroCode;
  73. }
  74. static ErrorCodeEnum LogDevErrInfo(DeviceBaseClass* inst, LPCTSTR lpszFuncName = "")
  75. {
  76. CSimpleStringA csMsg;
  77. WORD wdErrorCode = 0;
  78. return GetAndSplitDevErrInfo(inst, csMsg, wdErrorCode, lpszFuncName);
  79. }
  80. static BOOL GetDevErrorCode(DeviceBaseClass* inst, WORD& wdErrorCode)
  81. {
  82. CSimpleStringA csMsg;
  83. ErrorCodeEnum eRet = GetAndSplitDevErrInfo(inst, csMsg, wdErrorCode);
  84. return ((eRet == Error_Succeed) ? (TRUE) : (FALSE));
  85. }
  86. #ifndef _WIN32
  87. static VendorNameType GetCurVendorType(LPCTSTR vendorName)
  88. {
  89. if(vendorName == NULL || strlen(vendorName) == 0) {
  90. return Vendor_Invalide;
  91. }
  92. int idx = -1;
  93. for(int i=0; i<sizeof(VendorNameStr)/sizeof(VendorNameStr[0]); ++i)
  94. {
  95. if(strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0) {
  96. idx = i;
  97. break;
  98. }
  99. }
  100. if(idx == -1) {
  101. /*历史遗留原因,怡化厂商有两个适配器名字*/
  102. if(strnicmp(vendorName, "yihua", strlen("yihua")) == 0) {
  103. idx = Vendor_YiHua;
  104. } else {
  105. idx = Vendor_Invalide;
  106. }
  107. }
  108. return (VendorNameType)idx;
  109. }
  110. //1:报错累计到上限,需要返回错误码给业务
  111. //0:报错累计未到上限,或者不需要计数
  112. //-1:出现错误
  113. static int CountDevError(CSmartPointer<IEntityFunction> spEntityFunction, int& iCurErrNum)
  114. {
  115. CSmartPointer<IConfigInfo> spCenterConfig;
  116. ErrorCodeEnum eErrDev = spEntityFunction->OpenConfig(Config_CenterSetting, spCenterConfig);
  117. int iErrNumLimit;
  118. if (eErrDev != Error_Succeed) {
  119. Dbg("open centersetting file failed!");
  120. return -1;
  121. }
  122. else {
  123. spCenterConfig->ReadConfigValueInt("Common", "ErrUpperLimit", iErrNumLimit);
  124. if (0 == iErrNumLimit) {
  125. iErrNumLimit = 5;
  126. Dbg("iErrNumLimit=%d", iErrNumLimit);
  127. }
  128. else if (iErrNumLimit < 0)
  129. return 0;
  130. }
  131. iCurErrNum++;
  132. if (iCurErrNum >= iErrNumLimit) {
  133. return 1;
  134. }
  135. else {
  136. return 0;
  137. }
  138. }
  139. #endif //NOT _WIN32
  140. };
  141. #ifndef _WIN32
  142. struct HardwareEntityCode {
  143. DWORD dwEntityId;
  144. DWORD dwVendorId;
  145. DWORD dwVendorErroCode;
  146. DWORD dwReserved;
  147. };
  148. #endif //NOT _WIN32
  149. #endif // __DEVICEBASE_HELPER_H