UPS_iTrust_Adapt.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #include "StdAfx.h"
  2. #include ".\ups_itrust_adapt.h"
  3. UPS_iTrust_Adapt::UPS_iTrust_Adapt(char *szPath,char *szIniName,int nCommPort, int nAddr,int nRate, int nDataBit,int nStopBit, int nParity,int nInterval)
  4. {
  5. #if IS_USE_READMSG_CS
  6. InitializeCriticalSection(&m_csReadMsg);
  7. #endif
  8. MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
  9. // 读设备;
  10. memset(m_sz42Msg, 0, sizeof(m_sz42Msg));
  11. memset(m_sz43Msg, 0, sizeof(m_sz43Msg));
  12. memset(m_sz44Msg, 0, sizeof(m_sz44Msg));
  13. memset(m_sz47Msg, 0, sizeof(m_sz47Msg));
  14. // 写设备;
  15. memset(m_sz45Msg, 0, sizeof(m_sz45Msg));
  16. memset(m_sz49Msg, 0, sizeof(m_sz49Msg));
  17. m_dwOnlineTick = 0;
  18. m_devOnline = TRUE;
  19. }
  20. UPS_iTrust_Adapt::~UPS_iTrust_Adapt(void)
  21. {
  22. #if IS_USE_READMSG_CS
  23. DeleteCriticalSection(& m_csReadMsg);
  24. #endif
  25. MTVERIFY(CloseHandle(m_hSemComm));
  26. CloseComm();
  27. }
  28. BOOL UPS_iTrust_Adapt::OpenUPSComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  29. {
  30. BOOL bResult = FALSE;
  31. LOG4C((LOG_NOTICE,"->OpenUPSComm"));
  32. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  33. return bResult;
  34. }
  35. int UPS_iTrust_Adapt::GetIniInfo(char *szPath,char *szIniName,char *szCmd,char *IniSendCMD, int &IniSendlen, char *nType,int &nIndex,int &nLen)
  36. {
  37. CHAR szFile[MAX_PATH + 1] = "";
  38. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  39. TRACE("szFile =%s\n",szFile);
  40. IniSendlen = GetPrivateProfileString(szCmd, "SendCmd", "", IniSendCMD, 10, szFile); // 返回的字符串是以\0结束的;
  41. GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
  42. nType[strlen(nType)] = '\0';
  43. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  44. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  45. return 0;
  46. }
  47. int UPS_iTrust_Adapt::SendReadRequest(
  48. char *szPath,
  49. char *szIniName,
  50. int nCommPort,
  51. int nAddr,
  52. char *szCmd,
  53. char *szMsg,
  54. int nReversed1,
  55. int nReversed2,
  56. int nReversed3,
  57. int nReversed4,
  58. int nReversed5,
  59. float fReversed1,
  60. float fReversed2,
  61. float fReversed3,
  62. char *szReversed1,
  63. char *szReversed2,
  64. char *szReversed3,
  65. char *szReversed4,
  66. char *szReversed5 )
  67. {
  68. LOG4C((LOG_NOTICE,"->SendReadRequest"));
  69. CCommProcess *pComm = FindComm(nCommPort);
  70. if( pComm == NULL ) return -1;
  71. int nRet(-1);
  72. int nIndex(0), nLen(0), IniSendlen(0);
  73. char IniSendCMD[MAX_CMD] = {0}, szDataType[CMD_TYPE] = {0};
  74. GetIniInfo(szPath,szIniName,szCmd,IniSendCMD,IniSendlen,szDataType,nIndex,nLen);
  75. if (
  76. (strlen(m_sz42Msg) == 0 &&
  77. (strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  78. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  79. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 ||
  80. strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
  81. strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  82. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 ||
  83. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0
  84. )||
  85. ( strlen(m_sz43Msg) == 0 &&
  86. ( strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ||
  87. strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 ||
  88. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0
  89. ) )||
  90. ( strlen(m_sz44Msg) == 0 &&
  91. ( strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 ||
  92. strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  93. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ||
  94. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 ||
  95. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 ||
  96. strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  97. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 ||
  98. strcmp(szCmd, "cmd-51") == 0
  99. )) ||
  100. ( strlen(m_sz47Msg) == 0 &&
  101. (strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  102. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 ||
  103. strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  104. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 ||
  105. strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  106. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 ||
  107. strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  108. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 ||
  109. strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  110. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
  111. strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  112. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0
  113. ) ) ||
  114. strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-21") == 0 ||
  115. strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-52") == 0
  116. )
  117. )
  118. {
  119. nRet = GetDeviceParam(nAddr ,pComm, IniSendCMD,IniSendlen, szCmd );
  120. if( nRet != 0 )
  121. return nRet;
  122. }
  123. if( GetTickCount() - m_dwOnlineTick > 60 * 1000 && m_dwOnlineTick > 0 ) {
  124. m_devOnline = FALSE;
  125. }
  126. else if( GetTickCount() - m_dwOnlineTick < 60 * 1000 && m_dwOnlineTick > 0 ) {
  127. m_devOnline = TRUE;
  128. }
  129. if( m_devOnline == FALSE ) {
  130. return -1;
  131. }
  132. LOG4C((LOG_NOTICE,"->GetUPS_42Msg"));
  133. nRet = GetUPS_42Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  134. nRet = GetUPS_43Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  135. nRet = GetUPS_44Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  136. nRet = GetUPS_47Msg(nAddr, szCmd, szMsg, nIndex, nLen, szDataType);
  137. return nRet;
  138. }
  139. // 发送写设置;
  140. int UPS_iTrust_Adapt::SendSetReuest(
  141. char *szPath,
  142. char *szIniName,
  143. int nCommPort,
  144. int nAddr,
  145. char *szCmd,
  146. char *szMsg,
  147. int nReversed1,
  148. int nReversed2,
  149. int nReversed3,
  150. int nReversed4,
  151. int nReversed5,
  152. float fReversed1,
  153. float fReversed2,
  154. float fReversed3,
  155. char *szReversed1,
  156. char *szReversed2,
  157. char *szReversed3,
  158. char *szReversed4,
  159. char *szReversed5
  160. )
  161. {
  162. return 0;
  163. }
  164. int UPS_iTrust_Adapt::GetDeviceParam(int naddr, CCommProcess *pComm,char *IniSendCMD,const int &IniSendlen ,char *szCmd)
  165. {
  166. LOG4C((LOG_NOTICE,"->GetDeviceParam"));
  167. int nRet(-1);
  168. nRet = Send_ReadDeviceData(naddr, pComm, IniSendCMD, IniSendlen);
  169. if( nRet != 0 ) {
  170. return nRet;
  171. }
  172. nRet = Recv_ReadDeviceData(naddr, pComm, szCmd);
  173. return nRet;
  174. }
  175. int UPS_iTrust_Adapt::Send_ReadDeviceData(int nAddr,CCommProcess *pComm,const char *IniSendCMD,const int &IniSendlen)
  176. {
  177. #if DEBUG_ITRUSTADAPT
  178. LOG4C((LOG_NOTICE,"->Send_ReadDeviceData"));
  179. int nSLen = sizeof(SEND_DEVICEDATA);
  180. SEND_DEVICEDATA SendDeviceData;
  181. memset(&SendDeviceData, 0, sizeof(SEND_DEVICEDATA));
  182. SendDeviceData.Start = 0x7E;
  183. SendDeviceData.Version[0] = 0x31;
  184. SendDeviceData.Version[1] = 0x30;
  185. SendDeviceData.Address[0] = ByteToAscii( (nAddr >> 4) & 0x0F);
  186. SendDeviceData.Address[1] = ByteToAscii( nAddr & 0x0F);
  187. SendDeviceData.Cid1[0] = 0x32;
  188. SendDeviceData.Cid1[1] = 0x41;
  189. memcpy(SendDeviceData.Cid2, IniSendCMD, IniSendlen);
  190. memcpy(SendDeviceData.Length,"0000",4);
  191. //GetEmersonLength( 0,(char *)SendDeviceData.Length);
  192. GetEmersonCheck((char *)&SendDeviceData, (char*)SendDeviceData.chkSum);
  193. // 结束符;
  194. SendDeviceData.End = 0x0D;
  195. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) {
  196. ResetEvent(m_hSemComm);
  197. int nResult = pComm->Write((BYTE *)&SendDeviceData, nSLen);
  198. if (nResult != nSLen){
  199. SetEvent(m_hSemComm);
  200. return EER_CODE_COM_REGNUM;
  201. }
  202. }
  203. else{
  204. return ERR_CODE_COM_BUSY;
  205. }
  206. #endif
  207. return 0;
  208. }
  209. int UPS_iTrust_Adapt::Recv_ReadDeviceData(int nAddr,CCommProcess *pComm,char *szCmd)
  210. {
  211. #if DEBUG_ITRUSTADAPT
  212. LOG4C((LOG_NOTICE,"->Recv_ReadDeviceData"));
  213. int nProcessLen(0),nReadLen(0);
  214. char *pBuff = new char[MAX_RECE_MSG];
  215. memset(pBuff, 0 , MAX_RECE_MSG);
  216. nReadLen = pComm->Read((BYTE *)pBuff,MAX_RECE_MSG);
  217. if (nReadLen <= 0){
  218. SetEvent(m_hSemComm);
  219. if (pBuff != NULL) {
  220. delete [] pBuff;
  221. pBuff = NULL;
  222. }
  223. return ERR_CODE_COM_READ_NO_DATA;
  224. } //长度校验出错 ;
  225. CopyUPS_42_Msg(nAddr, szCmd, pBuff);
  226. CopyUPS_43_Msg(nAddr, szCmd, pBuff);
  227. CopyUPS_44_Msg(nAddr, szCmd, pBuff);
  228. CopyUPS_47_Msg(nAddr, szCmd, pBuff);
  229. m_dwOnlineTick = GetTickCount();
  230. SetEvent( m_hSemComm );
  231. if( pBuff != NULL) {
  232. delete[] pBuff;
  233. pBuff = NULL;
  234. }
  235. #else
  236. SimulationCommData();
  237. #endif
  238. return 0;
  239. }
  240. void UPS_iTrust_Adapt::CopyUPS_42_Msg( int naddr, char *szCmd, char *pBuffer)
  241. {
  242. if ( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  243. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  244. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 ||
  245. strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
  246. strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  247. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 ||
  248. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0)
  249. {
  250. #if IS_USE_READMSG_CS
  251. EnterCriticalSection(&m_csReadMsg);
  252. #endif
  253. memcpy(m_sz42Msg, pBuffer, sizeof(m_sz42Msg));
  254. #if IS_USE_READMSG_CS
  255. LeaveCriticalSection(&m_csReadMsg);
  256. #endif
  257. }
  258. }
  259. void UPS_iTrust_Adapt::CopyUPS_43_Msg( int naddr, char *szCmd, char *pBuffer)
  260. {
  261. if (strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ||
  262. strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 ||
  263. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 )
  264. {
  265. #if IS_USE_READMSG_CS
  266. EnterCriticalSection(&m_csReadMsg);
  267. #endif
  268. memcpy(m_sz43Msg, pBuffer, sizeof(m_sz43Msg));
  269. #if IS_USE_READMSG_CS
  270. LeaveCriticalSection(&m_csReadMsg);
  271. #endif
  272. }
  273. }
  274. void UPS_iTrust_Adapt::CopyUPS_44_Msg( int naddr, char *szCmd, char *pBuffer)
  275. {
  276. if ( strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 ||
  277. strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  278. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ||
  279. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 ||
  280. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 ||
  281. strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  282. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 ||
  283. strcmp(szCmd, "cmd-51") == 0)
  284. {
  285. #if IS_USE_READMSG_CS
  286. EnterCriticalSection(&m_csReadMsg);
  287. #endif
  288. memcpy(m_sz44Msg, pBuffer, sizeof(m_sz44Msg));
  289. #if IS_USE_READMSG_CS
  290. LeaveCriticalSection(&m_csReadMsg);
  291. #endif
  292. }
  293. }
  294. void UPS_iTrust_Adapt::CopyUPS_47_Msg( int naddr, char *szCmd, char *pBuffer)
  295. {
  296. if ( strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  297. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 ||
  298. strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  299. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 ||
  300. strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  301. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 ||
  302. strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  303. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 ||
  304. strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  305. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
  306. strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  307. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0)
  308. {
  309. #if IS_USE_READMSG_CS
  310. EnterCriticalSection(&m_csReadMsg);
  311. #endif
  312. memcpy(m_sz47Msg, pBuffer, sizeof(m_sz47Msg));
  313. #if IS_USE_READMSG_CS
  314. LeaveCriticalSection(&m_csReadMsg);
  315. #endif
  316. }
  317. }
  318. void UPS_iTrust_Adapt::CopyUPS_45_Msg( int naddr, char *szCmd, char *pBuffer)
  319. {
  320. if ( 0)
  321. {
  322. #if IS_USE_READMSG_CS
  323. EnterCriticalSection(&m_csReadMsg);
  324. #endif
  325. memcpy(m_sz45Msg, pBuffer, sizeof(m_sz45Msg));
  326. #if IS_USE_READMSG_CS
  327. LeaveCriticalSection(&m_csReadMsg);
  328. #endif
  329. }
  330. }
  331. void UPS_iTrust_Adapt::CopyUPS_49_Msg( int naddr, char *szCmd, char *pBuffer)
  332. {
  333. if ( 0)
  334. {
  335. #if IS_USE_READMSG_CS
  336. EnterCriticalSection(&m_csReadMsg);
  337. #endif
  338. memcpy(m_sz49Msg, pBuffer, sizeof(m_sz49Msg));
  339. #if IS_USE_READMSG_CS
  340. LeaveCriticalSection(&m_csReadMsg);
  341. #endif
  342. }
  343. }
  344. int UPS_iTrust_Adapt::GetUPS_42Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  345. {
  346. int nRet(0);
  347. if (strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  348. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  349. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 ||
  350. strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
  351. strcmp(szCmd, "cmd-13") == 0 || strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  352. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 || strcmp(szCmd, "cmd-18") == 0 ||
  353. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0)
  354. {
  355. #if IS_USE_READMSG_CS
  356. EnterCriticalSection(&m_csReadMsg);
  357. #endif
  358. DataConversion(szType, m_sz42Msg + nIndex, szMsg, nLen);
  359. #if IS_USE_READMSG_CS
  360. LeaveCriticalSection(&m_csReadMsg);
  361. #endif
  362. nRet = 0;
  363. }
  364. return nRet;
  365. }
  366. int UPS_iTrust_Adapt::GetUPS_43Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  367. {
  368. int nRet(0);
  369. if (strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 || strcmp(szCmd, "cmd-23") == 0 ||
  370. strcmp(szCmd, "cmd-24") == 0 || strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 ||
  371. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 )
  372. {
  373. #if IS_USE_READMSG_CS
  374. EnterCriticalSection(&m_csReadMsg);
  375. #endif
  376. DataConversion(szType, m_sz43Msg + nIndex, szMsg, nLen);
  377. #if IS_USE_READMSG_CS
  378. LeaveCriticalSection(&m_csReadMsg);
  379. #endif
  380. nRet = 0;
  381. }
  382. return nRet;
  383. }
  384. int UPS_iTrust_Adapt::GetUPS_44Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  385. {
  386. int nRet(0);
  387. if (strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 || strcmp(szCmd, "cmd-32") == 0 ||
  388. strcmp(szCmd, "cmd-33") == 0 || strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  389. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 || strcmp(szCmd, "cmd-38") == 0 ||
  390. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 ||
  391. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 || strcmp(szCmd, "cmd-44") == 0 ||
  392. strcmp(szCmd, "cmd-45") == 0 || strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  393. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 || strcmp(szCmd, "cmd-50") == 0 ||
  394. strcmp(szCmd, "cmd-51") == 0 )
  395. {
  396. #if IS_USE_READMSG_CS
  397. EnterCriticalSection(&m_csReadMsg);
  398. #endif
  399. DataConversion(szType, m_sz44Msg + nIndex, szMsg, nLen);
  400. #if IS_USE_READMSG_CS
  401. LeaveCriticalSection(&m_csReadMsg);
  402. #endif
  403. nRet = 0;
  404. }
  405. return nRet;
  406. }
  407. int UPS_iTrust_Adapt::GetUPS_47Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  408. {
  409. int nRet(0);
  410. if (strcmp(szCmd, "cmd-52") == 0 || strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  411. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 || strcmp(szCmd, "cmd-57") == 0 ||
  412. strcmp(szCmd, "cmd-58") == 0 || strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  413. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 || strcmp(szCmd, "cmd-63") == 0 ||
  414. strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  415. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 || strcmp(szCmd, "cmd-69") == 0 ||
  416. strcmp(szCmd, "cmd-60") == 0 || strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  417. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 || strcmp(szCmd, "cmd-65") == 0 ||
  418. strcmp(szCmd, "cmd-66") == 0 || strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  419. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 || strcmp(szCmd, "cmd-71") == 0 ||
  420. strcmp(szCmd, "cmd-72") == 0 || strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  421. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0 )
  422. {
  423. #if IS_USE_READMSG_CS
  424. EnterCriticalSection(&m_csReadMsg);
  425. #endif
  426. DataConversion(szType, m_sz47Msg + nIndex, szMsg, nLen);
  427. #if IS_USE_READMSG_CS
  428. LeaveCriticalSection(&m_csReadMsg);
  429. #endif
  430. nRet = 0;
  431. }
  432. return nRet;
  433. }
  434. int UPS_iTrust_Adapt::GetUPS_45Msg(int nAddr, char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  435. {
  436. int nRet(0);
  437. if (0)
  438. {
  439. #if IS_USE_READMSG_CS
  440. EnterCriticalSection(&m_csReadMsg);
  441. #endif
  442. DataConversion(szType, m_sz45Msg + nIndex, szMsg, nLen);
  443. #if IS_USE_READMSG_CS
  444. LeaveCriticalSection(&m_csReadMsg);
  445. #endif
  446. nRet = 0;
  447. }
  448. return nRet;
  449. }
  450. int UPS_iTrust_Adapt::GetUPS_49Msg(int nAddr,char *szCmd, char *szMsg, int &nIndex, int &nLen, char *szType )
  451. {
  452. int nRet(0);
  453. if (0)
  454. {
  455. #if IS_USE_READMSG_CS
  456. EnterCriticalSection(&m_csReadMsg);
  457. #endif
  458. DataConversion(szType, m_sz49Msg + nIndex, szMsg, nLen);
  459. #if IS_USE_READMSG_CS
  460. LeaveCriticalSection(&m_csReadMsg);
  461. #endif
  462. nRet = 0;
  463. }
  464. return nRet;
  465. }
  466. void UPS_iTrust_Adapt::lowcase2uppcase(BYTE &btSrc)
  467. {
  468. if( btSrc >= 'a' && btSrc <= 'z' )
  469. {
  470. btSrc = btSrc - 'a' + 'A';
  471. }
  472. }
  473. void UPS_iTrust_Adapt::GetEmersonLength(const int &iLenID, char *szLegth)
  474. {
  475. int ilengthchecksum(0);
  476. int it = iLenID;
  477. ilengthchecksum = it & 0x00F ; it = iLenID;
  478. ilengthchecksum += (it &0x0F0) >> 4; it = iLenID;
  479. ilengthchecksum += (it &0xF00 ) >> 8;
  480. ilengthchecksum = ilengthchecksum%16;
  481. ilengthchecksum = ~ilengthchecksum +17;
  482. int ilength = (ilengthchecksum & 0x000F) << 12 ;
  483. ilength = ilength | iLenID;
  484. itoa(ilength,szLegth,16 );
  485. for (int i(0) ; i < 5 ; i++)
  486. {
  487. lowercase2uppercase((BYTE &)szLegth[i]);
  488. }
  489. }
  490. void UPS_iTrust_Adapt::GetEmersonCheck(char *szData, char *szCheck ,int nlen /* = 12 */)
  491. {
  492. DWORD dwSum(0);
  493. for (int i(0); i < nlen; i++)
  494. {
  495. dwSum += szData[i+1] ;
  496. }
  497. WORD iCompliment = dwSum;
  498. iCompliment = ~iCompliment;//取反
  499. iCompliment++;
  500. itoa(iCompliment, szCheck, 16);
  501. for (int i(0); i < 5 ; i++)
  502. {
  503. lowcase2uppcase((BYTE &)szCheck[i]);
  504. }
  505. }
  506. void UPS_iTrust_Adapt::SimulationCommData(void)
  507. {
  508. }