ups_newave.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*************************************************
  2. /* Copyright (C), 2010-2011,StoneU. Co., Ltd.
  3. /* File name: ups_newave.cpp
  4. /* Author: Zero.t
  5. /* Version: Ver1.0.0.1
  6. /* Date: 2011-8-30
  7. /* Description: Conceptpower系列UPS,具体型号未知;本类首次使用在项目::K客户现场文件\b北京\M美思装饰\大众汽车金融;
  8. /* Others: UPS协议类,不做控制设备操作;
  9. /* Function List: ###
  10. /* History:
  11. 1.Date: ###
  12. Author: ###
  13. Modification: ###
  14. *************************************************/
  15. #include "StdAfx.h"
  16. #include "CommProcess.h"
  17. #include ".\ups_newave.h"
  18. Cups_newave::Cups_newave(
  19. char szPath[MAX_PATH],
  20. char szIniName[MAX_PATH],
  21. int nCommPort, int nAddr,
  22. int nRate, int nDataBit,
  23. int nStopBit, int nParity,
  24. int nInterval
  25. )
  26. {
  27. #if IS_USE_READMSG_CS
  28. InitializeCriticalSection(&m_csReadMsg);
  29. #endif
  30. MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
  31. memset(m_szAlarmMsg, 0, sizeof(m_szAlarmMsg));
  32. memset(m_szStatuMsg, 0, sizeof(m_szStatuMsg));
  33. memset(m_szValueMsg, 0, sizeof(m_szValueMsg));
  34. m_dwOnlineTick = 0;
  35. m_devOnline = TRUE;
  36. }
  37. Cups_newave::~Cups_newave(void)
  38. {
  39. #if IS_USE_READMSG_CS
  40. DeleteCriticalSection(& m_csReadMsg);
  41. #endif
  42. MTVERIFY(CloseHandle(m_hSemComm));
  43. CloseComm();
  44. }
  45. BOOL Cups_newave::upsAveOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  46. {
  47. BOOL bResult = FALSE;
  48. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  49. return bResult;
  50. }
  51. int Cups_newave::GetParamFromIni( char szPath[MAX_PATH], char szIniName[MAX_PATH],char szCmd[MAX_CMD],char szSanTakSendMsg[MAX_CMD],
  52. char nType[MAX_CMD], int &nIndex, int &nLen ,int &StaBit, int &EndBit)
  53. {
  54. CHAR szFile[MAX_PATH + 1] = "";
  55. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  56. TRACE("szFile =%s\n",szFile);
  57. GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, 10, szFile);
  58. szSanTakSendMsg[strlen(szSanTakSendMsg)] = 0x0D;
  59. GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
  60. nType[strlen(nType)] = '\0';
  61. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  62. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  63. StaBit = GetPrivateProfileInt(szCmd,"StaBit",0,szFile);
  64. EndBit = GetPrivateProfileInt(szCmd,"EndBit",0,szFile);
  65. return 0;
  66. }
  67. int Cups_newave::SendQueryMsg( CCommProcess *pComm,int nAddr)
  68. {
  69. #if NEWAVE_DEBUG //开关量,用于测试模拟数据
  70. __QueryMsg str_Query;
  71. int nLen = sizeof(__QueryMsg);
  72. memset(&str_Query,0,nLen);
  73. str_Query.msg_head = 0x3E;
  74. str_Query.msg_addr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  75. str_Query.msg_addr[1] = ByteToAscii(nAddr & 0x0f);
  76. str_Query.msg_type = 0x51;
  77. str_Query.msg_length[0] = 0x30;
  78. str_Query.msg_length[1] = 0x30;
  79. str_Query.msg_length[3] = 0x34;
  80. memcpy(str_Query.msg_check,"0186",4);
  81. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
  82. {
  83. int nDatalen = (int)sizeof(str_Query);
  84. ResetEvent(m_hSemComm);
  85. int nResult = pComm->Write((BYTE *)&str_Query, nDatalen);
  86. //LOG4C_HEX_DUMP((LOG_NOTICE, chSendMsg, 3));
  87. //LOG4C((LOG_NOTICE, "CSanTak::RequestStatus chSendMsg = %s, nResult = %d, nDatalen = %d", chSendMsg,nResult, nDatalen));
  88. if (nResult == nDatalen)
  89. {
  90. }
  91. else
  92. {
  93. SetEvent(m_hSemComm);
  94. return EER_CODE_NEWAVE_COM_REGNUM;
  95. }
  96. }
  97. else
  98. {
  99. return ERR_CODE_NEWAVE_COM_BUSY; //串口忙
  100. }
  101. #endif
  102. return 0;
  103. }
  104. int Cups_newave::QueryResponeMsg(CCommProcess *pComm,int nAddr)
  105. {
  106. #if NEWAVE_DEBUG //开关量,用于测试模拟数据
  107. int ireallen = 0;
  108. __ResponeQuery str_record;
  109. int ireadlen = sizeof(str_record);
  110. char *pBuffer = new char[ireadlen];
  111. memset(pBuffer,0,ireadlen);
  112. ireallen = pComm->Read((BYTE *)pBuffer,ireadlen);
  113. if (ireallen <= 0)
  114. {
  115. SetEvent(m_hSemComm);
  116. if (pBuffer != NULL)
  117. {
  118. delete[] pBuffer;
  119. pBuffer = NULL;
  120. }
  121. return ERR_CODE_NEWAVE_COM_READ_NO_DATA;
  122. }
  123. char ch_record = 0;
  124. ch_record = pBuffer[4];
  125. m_dwOnlineTick = GetTickCount();
  126. // 设置串口等待事件为有信号
  127. SetEvent( m_hSemComm );
  128. if( pBuffer != NULL)
  129. {
  130. delete[] pBuffer;
  131. pBuffer = NULL;
  132. }
  133. #endif
  134. return 0;
  135. }
  136. int Cups_newave::SendReadRequest(
  137. char szPath[MAX_PATH],
  138. char szIniName[MAX_PATH],
  139. int nCommPort,
  140. int nAddr,
  141. char szCmd[MAX_CMD],
  142. char szRecMsg[VAR_MSG],
  143. int nReversed1,
  144. int nReversed2,
  145. int nReversed3,
  146. int nReversed4,
  147. int nReversed5,
  148. float fReversed1,
  149. float fReversed2,
  150. float fReversed3,
  151. char szReversed1[MAX_RESERVED1],
  152. char szReversed2[MAX_RESERVED2],
  153. char szReversed3[MAX_RESERVED3],
  154. char szReversed4[MAX_RESERVED4],
  155. char szReversed5[MAX_RESERVED5]
  156. )
  157. {
  158. int nIndex = 0, nLen = 0;
  159. int StaBit = 0, EndBit = 0;
  160. char szSendCmd[MAX_SENDCMD] = {0};
  161. char szType[CMD_TYPE] = {0};
  162. m_address = nAddr;
  163. GetParamFromIni(szPath, szIniName, szCmd, szSendCmd, szType, nIndex, nLen ,StaBit, EndBit);
  164. CCommProcess *pComm = FindComm(nCommPort);
  165. if( pComm == NULL ) return -1;
  166. int nRet = -1;
  167. if(
  168. ( strlen(m_szValueMsg) == 0 && (
  169. strcmp(szCmd,"cmd-1") == 0 || strcmp(szCmd,"cmd-2") == 0 || strcmp(szCmd,"cmd-3") == 0 ||
  170. strcmp(szCmd,"cmd-4") == 0 || strcmp(szCmd,"cmd-6") == 0 || strcmp(szCmd,"cmd-5") == 0 ||
  171. strcmp(szCmd,"cmd-7") == 0 || strcmp(szCmd,"cmd-8") == 0 || strcmp(szCmd,"cmd-9") == 0 ||
  172. strcmp(szCmd,"cmd-10") == 0 || strcmp(szCmd,"cmd-11") == 0 || strcmp(szCmd,"cmd-12") == 0||
  173. strcmp(szCmd,"cmd-13") == 0 || strcmp(szCmd,"cmd-14") == 0
  174. ))||
  175. (strlen(m_szStatuMsg) == 0 &&(
  176. strcmp(szCmd,"cmd-15") == 0 || strcmp(szCmd,"cmd-16") == 0 || strcmp(szCmd,"cmd-17") == 0 ||
  177. strcmp(szCmd,"cmd-18") == 0 || strcmp(szCmd,"cmd-19") == 0 || strcmp(szCmd,"cmd-20") == 0 ||
  178. strcmp(szCmd,"cmd-21") == 0 || strcmp(szCmd,"cmd-22") == 0 || strcmp(szCmd,"cmd-23") == 0 ||
  179. strcmp(szCmd,"cmd-24") == 0 || strcmp(szCmd,"cmd-25") == 0 || strcmp(szCmd,"cmd-26") == 0 ||
  180. strcmp(szCmd,"cmd-27") == 0 || strcmp(szCmd,"cmd-28") == 0 || strcmp(szCmd,"cmd-29") == 0 ||
  181. strcmp(szCmd,"cmd-30") == 0 || strcmp(szCmd,"cmd-31") == 0 || strcmp(szCmd,"cmd-32") == 0 ||
  182. strcmp(szCmd,"cmd-33") == 0 || strcmp(szCmd,"cmd-34") == 0 || strcmp(szCmd,"cmd-35") == 0 ||
  183. strcmp(szCmd,"cmd-36") == 0
  184. ))||
  185. (strlen(m_szAlarmMsg) == 0 && (
  186. strcmp(szCmd,"cmd-37") == 0 || strcmp(szCmd,"cmd-38") == 0 ||
  187. strcmp(szCmd,"cmd-39") == 0 || strcmp(szCmd,"cmd-40") == 0 || strcmp(szCmd,"cmd-41") == 0 ||
  188. strcmp(szCmd,"cmd-42") == 0 || strcmp(szCmd,"cmd-43") == 0 || strcmp(szCmd,"cmd-44") == 0 ||
  189. strcmp(szCmd,"cmd-45") == 0 || strcmp(szCmd,"cmd-46") == 0 || strcmp(szCmd,"cmd-47") == 0 ||
  190. strcmp(szCmd,"cmd-48") == 0 || strcmp(szCmd,"cmd-49") == 0 || strcmp(szCmd,"cmd-50") == 0 ||
  191. strcmp(szCmd,"cmd-51") == 0 || strcmp(szCmd,"cmd-52") == 0 || strcmp(szCmd,"cmd-53") == 0 ||
  192. strcmp(szCmd,"cmd-54") == 0 || strcmp(szCmd,"cmd-55") == 0 || strcmp(szCmd,"cmd-56") == 0 ||
  193. strcmp(szCmd,"cmd-57") == 0 || strcmp(szCmd,"cmd-58") == 0 || strcmp(szCmd,"cmd-59") == 0 ||
  194. strcmp(szCmd,"cmd-60") == 0 || strcmp(szCmd,"cmd-61") == 0 || strcmp(szCmd,"cmd-62") == 0 ||
  195. strcmp(szCmd,"cmd-63") == 0 || strcmp(szCmd,"cmd-64") == 0 || strcmp(szCmd,"cmd-65") == 0 ||
  196. strcmp(szCmd,"cmd-66") == 0
  197. ))||
  198. strcmp(szCmd,"cmd-1") == 0 || strcmp(szCmd,"cmd-15") == 0 || strcmp(szCmd,"cmd-39") == 0
  199. )
  200. {
  201. nRet = GetDeviceParam(nAddr, pComm, szSendCmd, szCmd, szRecMsg, nIndex, nLen,szType );
  202. if( nRet != 0 )
  203. return nRet;
  204. }
  205. if( GetTickCount() - m_dwOnlineTick > 60 * 1000 && m_dwOnlineTick > 0 )
  206. {
  207. m_devOnline = FALSE;
  208. }
  209. else if( GetTickCount() - m_dwOnlineTick < 60 * 1000 && m_dwOnlineTick > 0 )
  210. {
  211. m_devOnline = TRUE;
  212. }
  213. if( m_devOnline == FALSE )
  214. {
  215. return -1;
  216. }
  217. nRet = GetValueMsg(szCmd, szRecMsg, nIndex, nLen, szType);
  218. nRet = GetStatuMsg(szCmd, szRecMsg, nIndex, nLen, StaBit, EndBit, szType);
  219. nRet = GetAlarmMsg(szCmd, szRecMsg, nIndex, nLen, StaBit, EndBit, szType);
  220. //LOG4C_HEX_DUMP((LOG_NOTICE, szMsg, sizeof(szMsg)));
  221. LOG4C((LOG_NOTICE, "%s=%d", szCmd, atoi(szRecMsg)));
  222. return nRet;
  223. }
  224. int Cups_newave::GetDeviceParam(
  225. int nAddr,
  226. CCommProcess *pComm, // 串口对象指针
  227. char szSendCmd[MAX_SEND_MSG], // 发送Buffer
  228. char szCmd[MAX_CMD], // 命令
  229. char szMsg[VAR_MSG], // 接收Buffer
  230. int &nIndex, // 变量索引,针对接收Buffer而言
  231. int &nLen, // 变量长度
  232. char szType[CMD_TYPE] // 变量数据类型
  233. )
  234. {
  235. int nRet = -1;
  236. nRet = RequestStatus(nAddr, pComm, szSendCmd);
  237. if( nRet != 0 )
  238. {
  239. return nRet;
  240. }
  241. nRet = ResponseStatus(nAddr, pComm, szCmd, szMsg, nIndex, nLen, szType);
  242. return nRet;
  243. }
  244. int Cups_newave::RequestStatus(int nAddr, CCommProcess *pComm,const char szSendCmd[MAX_SEND_MSG] )
  245. {
  246. #if NEWAVE_DEBUG //开关量,用于测试模拟数据
  247. int sum = 0;
  248. __GetMsg str_GetMsg;
  249. int nLen = sizeof(str_GetMsg);
  250. memset(&str_GetMsg,0,nLen);
  251. str_GetMsg.msg_head = 0x3E;
  252. str_GetMsg.msg_addr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  253. str_GetMsg.msg_addr[1] = ByteToAscii(nAddr & 0x0f);
  254. str_GetMsg.msg_type = 0x47;
  255. str_GetMsg.msg_length[0] = 0x30;
  256. str_GetMsg.msg_length[1] = 0x30;
  257. str_GetMsg.msg_length[2] = 0x38;
  258. memcpy(str_GetMsg.msg_record,szSendCmd,4);
  259. {
  260. sum += str_GetMsg.msg_head;
  261. sum += str_GetMsg.msg_addr[0];
  262. sum += str_GetMsg.msg_addr[1];
  263. sum += str_GetMsg.msg_type;
  264. sum += str_GetMsg.msg_length[0];
  265. sum += str_GetMsg.msg_length[1];
  266. sum += str_GetMsg.msg_length[2];
  267. sum += str_GetMsg.msg_record[0];
  268. sum += str_GetMsg.msg_record[1];
  269. sum += str_GetMsg.msg_record[2];
  270. sum += str_GetMsg.msg_record[3];
  271. }
  272. CString strSum;
  273. strSum.Format("%00004X",sum);
  274. int nstrlen = strSum.GetLength();
  275. if (nstrlen > 4)
  276. {
  277. return -1;
  278. }
  279. for (int i = 0 ; i < nstrlen; i++)
  280. {
  281. str_GetMsg.msg_check[i] = strSum.GetAt(i);
  282. }
  283. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
  284. {
  285. int nDatalen = (int)sizeof(str_GetMsg);
  286. ResetEvent(m_hSemComm);
  287. int nResult = pComm->Write((BYTE *)&str_GetMsg, nDatalen);
  288. //LOG4C_HEX_DUMP((LOG_NOTICE, chSendMsg, 3));
  289. //LOG4C((LOG_NOTICE, "CSanTak::RequestStatus chSendMsg = %s, nResult = %d, nDatalen = %d", chSendMsg,nResult, nDatalen));
  290. if (nResult == nDatalen)
  291. {
  292. }
  293. else
  294. {
  295. SetEvent(m_hSemComm);
  296. return EER_CODE_NEWAVE_COM_REGNUM;
  297. }
  298. }
  299. else
  300. {
  301. return ERR_CODE_NEWAVE_COM_BUSY; //串口忙
  302. }
  303. #endif
  304. return 0;
  305. }
  306. int Cups_newave::ResponseStatus(int nAddr,CCommProcess *pComm, char szCmd[MAX_CMD],
  307. char szMsg[VAR_MSG],int &nIndex, int &nLen, char szType[CMD_TYPE])
  308. {
  309. #if NEWAVE_DEBUG
  310. int nReceiveLen = 650;
  311. int nProcessLen = 0;
  312. int nReadLen = 0;
  313. char *pBuff = new char[nReceiveLen];
  314. memset(pBuff, 0 , nReceiveLen);
  315. nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen);
  316. //LOG4C((LOG_NOTICE, "CSanTak::ResponseStatus pBuff = %s, nReadLen = %d, nReceiveLen = %d", pBuff, nReadLen, nReceiveLen));
  317. if (nReadLen <= 0)
  318. {
  319. SetEvent(m_hSemComm);
  320. if (pBuff != NULL)
  321. {
  322. delete [] pBuff;
  323. pBuff = NULL;
  324. }
  325. return ERR_CODE_NEWAVE_COM_READ_NO_DATA;
  326. }
  327. //长度校验出错
  328. SetValueMsg(szCmd, pBuff);
  329. SetStatuMsg(szCmd, pBuff);
  330. SetAlarmMsg(szCmd, pBuff);
  331. m_dwOnlineTick = GetTickCount();
  332. // 设置串口等待事件为有信号
  333. SetEvent( m_hSemComm );
  334. if( pBuff != NULL)
  335. {
  336. delete[] pBuff;
  337. pBuff = NULL;
  338. }
  339. #else
  340. SimulationCommData();
  341. #endif
  342. return 0;
  343. }
  344. // 长度为2;
  345. void Cups_newave::DataProcess(const char *szSour, char *szDest,int &StaBit, int &EndBit)
  346. {
  347. char tmp_Sour[3] = {0};
  348. memcpy(tmp_Sour,szSour,2);
  349. int sum = (AsciiToBYTE(tmp_Sour[0]))*16 + AsciiToBYTE(tmp_Sour[1]);
  350. int ByteBit = 0;
  351. switch(StaBit)
  352. {
  353. #if 1
  354. case 7:
  355. ByteBit = sum & 0x01;
  356. break;
  357. case 6:
  358. ByteBit = (sum & 0x02) / 0x02 ;
  359. break;
  360. case 5:
  361. ByteBit = (sum & 0x04) / 0x04 ;
  362. break;
  363. case 4:
  364. ByteBit = (sum & 0x08) / 0x08 ;
  365. break;
  366. case 3:
  367. ByteBit = (sum & 0x10) / 0x10 ;
  368. break;
  369. case 2:
  370. ByteBit = (sum & 0x20) / 0x20 ;
  371. break;
  372. case 1:
  373. ByteBit = (sum & 0x40) / 0x40 ;
  374. break;
  375. case 0:
  376. ByteBit = (sum & 0x80) / 0x80;
  377. break;
  378. #else
  379. case 0:
  380. ByteBit = sum & 0x01;
  381. break;
  382. case 1:
  383. ByteBit = (sum & 0x02) / 0x02 ;
  384. break;
  385. case 2:
  386. ByteBit = (sum & 0x04) / 0x04 ;
  387. break;
  388. case 3:
  389. ByteBit = (sum & 0x08) / 0x08 ;
  390. break;
  391. case 4:
  392. ByteBit = (sum & 0x10) / 0x10 ;
  393. break;
  394. case 5:
  395. ByteBit = (sum & 0x20) / 0x20 ;
  396. break;
  397. case 6:
  398. ByteBit = (sum & 0x40) / 0x40 ;
  399. break;
  400. case 7:
  401. ByteBit = (sum & 0x80) / 0x80;
  402. break;
  403. #endif
  404. }
  405. szDest[0] = ByteBit + 48;
  406. }
  407. void Cups_newave::BitDataProcess(const char *szSour, char *szRecv, int &iSourLen,int &StaBit)
  408. {
  409. CString strBit = ""; // 存放位串字符;
  410. int ByteBit = 0;
  411. char *tmp_Sour = new char[iSourLen+1];
  412. memcpy(tmp_Sour,szSour,iSourLen);
  413. for (int i = 0; i < iSourLen; i+=2)
  414. {
  415. char szDest[9] = {0}; // 目标数据;
  416. int sum = (AsciiToBYTE(tmp_Sour[i]))*16 + AsciiToBYTE(tmp_Sour[i+1]);
  417. for(int j = 0; j < 8; j ++)
  418. {
  419. switch(j)
  420. {
  421. case 7:
  422. ByteBit = sum & 0x01;
  423. break;
  424. case 6:
  425. ByteBit = (sum & 0x02) / 0x02 ;
  426. break;
  427. case 5:
  428. ByteBit = (sum & 0x04) / 0x04 ;
  429. break;
  430. case 4:
  431. ByteBit = (sum & 0x08) / 0x08 ;
  432. break;
  433. case 3:
  434. ByteBit = (sum & 0x10) / 0x10 ;
  435. break;
  436. case 2:
  437. ByteBit = (sum & 0x20) / 0x20 ;
  438. break;
  439. case 1:
  440. ByteBit = (sum & 0x40) / 0x40 ;
  441. break;
  442. case 0:
  443. ByteBit = (sum & 0x80) / 0x80;
  444. break;
  445. }
  446. szDest[j] = ByteBit + 48;
  447. }
  448. strBit += szDest;
  449. }
  450. strBit = strBit.MakeReverse();
  451. szRecv[0] = strBit.GetAt(StaBit);
  452. if (tmp_Sour != NULL)
  453. {
  454. delete[] tmp_Sour;
  455. tmp_Sour = NULL;
  456. }
  457. }
  458. int Cups_newave::GetValueMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, char szTp[CMD_TYPE])
  459. {
  460. int nRet = 0;
  461. if (
  462. strcmp(szCmd,"cmd-1") == 0 || strcmp(szCmd,"cmd-2") == 0 || strcmp(szCmd,"cmd-3") == 0 ||
  463. strcmp(szCmd,"cmd-4") == 0 || strcmp(szCmd,"cmd-6") == 0 || strcmp(szCmd,"cmd-5") == 0 ||
  464. strcmp(szCmd,"cmd-7") == 0 || strcmp(szCmd,"cmd-8") == 0 || strcmp(szCmd,"cmd-9") == 0 ||
  465. strcmp(szCmd,"cmd-10") == 0 || strcmp(szCmd,"cmd-11") == 0 || strcmp(szCmd,"cmd-12") == 0||
  466. strcmp(szCmd,"cmd-13") == 0 || strcmp(szCmd,"cmd-14") == 0
  467. )
  468. {
  469. #if IS_USE_READMSG_CS
  470. EnterCriticalSection(&m_csReadMsg);
  471. #endif
  472. DataConversion(szTp, m_szValueMsg + nIndex, szRecMsg, nLen);
  473. #if IS_USE_READMSG_CS
  474. LeaveCriticalSection(&m_csReadMsg);
  475. #endif
  476. nRet = 0;
  477. }
  478. return nRet;
  479. }
  480. int Cups_newave::GetStatuMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, int &StaBit, int &EndBit, char szTp[CMD_TYPE])
  481. {
  482. int nRet = 0;
  483. if (
  484. strcmp(szCmd,"cmd-15") == 0 || strcmp(szCmd,"cmd-16") == 0 || strcmp(szCmd,"cmd-17") == 0 ||
  485. strcmp(szCmd,"cmd-18") == 0 || strcmp(szCmd,"cmd-19") == 0 || strcmp(szCmd,"cmd-20") == 0 ||
  486. strcmp(szCmd,"cmd-21") == 0 || strcmp(szCmd,"cmd-22") == 0 || strcmp(szCmd,"cmd-23") == 0 ||
  487. strcmp(szCmd,"cmd-24") == 0 || strcmp(szCmd,"cmd-25") == 0 || strcmp(szCmd,"cmd-26") == 0 ||
  488. strcmp(szCmd,"cmd-27") == 0 || strcmp(szCmd,"cmd-28") == 0 || strcmp(szCmd,"cmd-29") == 0 ||
  489. strcmp(szCmd,"cmd-30") == 0 || strcmp(szCmd,"cmd-31") == 0 || strcmp(szCmd,"cmd-32") == 0 ||
  490. strcmp(szCmd,"cmd-33") == 0 || strcmp(szCmd,"cmd-34") == 0 || strcmp(szCmd,"cmd-35") == 0 ||
  491. strcmp(szCmd,"cmd-36") == 0
  492. )
  493. {
  494. #if IS_USE_READMSG_CS
  495. EnterCriticalSection(&m_csReadMsg);
  496. #endif
  497. //DataProcess(m_szStatuMsg + nIndex, szRecMsg ,StaBit, EndBit);
  498. BitDataProcess(m_szStatuMsg + nIndex,szRecMsg,nLen,StaBit);
  499. LOG4C((LOG_NOTICE, "%s Bit[%d] = %s", szCmd,StaBit ,szRecMsg));
  500. #if IS_USE_READMSG_CS
  501. LeaveCriticalSection(&m_csReadMsg);
  502. #endif
  503. nRet = 0;
  504. }
  505. return nRet;
  506. }
  507. int Cups_newave::GetAlarmMsg(char szCmd[MAX_CMD],char szRecMsg[VAR_MSG],int &nIndex, int &nLen, int &StaBit, int &EndBit, char szTp[CMD_TYPE])
  508. {
  509. int nRet = 0;
  510. if (
  511. strcmp(szCmd,"cmd-37") == 0 || strcmp(szCmd,"cmd-38") == 0 ||
  512. strcmp(szCmd,"cmd-39") == 0 || strcmp(szCmd,"cmd-40") == 0 || strcmp(szCmd,"cmd-41") == 0 ||
  513. strcmp(szCmd,"cmd-42") == 0 || strcmp(szCmd,"cmd-43") == 0 || strcmp(szCmd,"cmd-44") == 0 ||
  514. strcmp(szCmd,"cmd-45") == 0 || strcmp(szCmd,"cmd-46") == 0 || strcmp(szCmd,"cmd-47") == 0 ||
  515. strcmp(szCmd,"cmd-48") == 0 || strcmp(szCmd,"cmd-49") == 0 || strcmp(szCmd,"cmd-50") == 0 ||
  516. strcmp(szCmd,"cmd-51") == 0 || strcmp(szCmd,"cmd-52") == 0 || strcmp(szCmd,"cmd-53") == 0 ||
  517. strcmp(szCmd,"cmd-54") == 0 || strcmp(szCmd,"cmd-55") == 0 || strcmp(szCmd,"cmd-56") == 0 ||
  518. strcmp(szCmd,"cmd-57") == 0 || strcmp(szCmd,"cmd-58") == 0 || strcmp(szCmd,"cmd-59") == 0 ||
  519. strcmp(szCmd,"cmd-60") == 0 || strcmp(szCmd,"cmd-61") == 0 || strcmp(szCmd,"cmd-62") == 0 ||
  520. strcmp(szCmd,"cmd-63") == 0 || strcmp(szCmd,"cmd-64") == 0 || strcmp(szCmd,"cmd-65") == 0 ||
  521. strcmp(szCmd,"cmd-66") == 0
  522. )
  523. {
  524. #if IS_USE_READMSG_CS
  525. EnterCriticalSection(&m_csReadMsg);
  526. #endif
  527. //DataProcess(m_szAlarmMsg + nIndex, szRecMsg ,StaBit, EndBit);
  528. BitDataProcess(m_szAlarmMsg + nIndex,szRecMsg,nLen,StaBit);
  529. LOG4C((LOG_NOTICE, "%s Bit[%d] = %s", szCmd,StaBit ,szRecMsg));
  530. #if IS_USE_READMSG_CS
  531. LeaveCriticalSection(&m_csReadMsg);
  532. #endif
  533. nRet = 0;
  534. }
  535. return nRet;
  536. }
  537. void Cups_newave::SetValueMsg(char szCmd[MAX_CMD], char *pBuffer)
  538. {
  539. if (
  540. strcmp(szCmd,"cmd-1") == 0 || strcmp(szCmd,"cmd-2") == 0 || strcmp(szCmd,"cmd-3") == 0 ||
  541. strcmp(szCmd,"cmd-4") == 0 || strcmp(szCmd,"cmd-6") == 0 || strcmp(szCmd,"cmd-5") == 0 ||
  542. strcmp(szCmd,"cmd-7") == 0 || strcmp(szCmd,"cmd-8") == 0 || strcmp(szCmd,"cmd-9") == 0 ||
  543. strcmp(szCmd,"cmd-10") == 0 || strcmp(szCmd,"cmd-11") == 0 || strcmp(szCmd,"cmd-12") == 0||
  544. strcmp(szCmd,"cmd-13") == 0 || strcmp(szCmd,"cmd-14") == 0
  545. )
  546. {
  547. #if IS_USE_READMSG_CS
  548. EnterCriticalSection(&m_csReadMsg);
  549. #endif
  550. memcpy(m_szValueMsg, pBuffer, sizeof(m_szValueMsg));
  551. #if IS_USE_READMSG_CS
  552. LeaveCriticalSection(&m_csReadMsg);
  553. #endif
  554. }
  555. }
  556. void Cups_newave::SetStatuMsg(char szCmd[MAX_CMD], char *pBuffer)
  557. {
  558. if (
  559. strcmp(szCmd,"cmd-15") == 0 || strcmp(szCmd,"cmd-16") == 0 || strcmp(szCmd,"cmd-17") == 0 ||
  560. strcmp(szCmd,"cmd-18") == 0 || strcmp(szCmd,"cmd-19") == 0 || strcmp(szCmd,"cmd-20") == 0 ||
  561. strcmp(szCmd,"cmd-21") == 0 || strcmp(szCmd,"cmd-22") == 0 || strcmp(szCmd,"cmd-23") == 0 ||
  562. strcmp(szCmd,"cmd-24") == 0 || strcmp(szCmd,"cmd-25") == 0 || strcmp(szCmd,"cmd-26") == 0 ||
  563. strcmp(szCmd,"cmd-27") == 0 || strcmp(szCmd,"cmd-28") == 0 || strcmp(szCmd,"cmd-29") == 0 ||
  564. strcmp(szCmd,"cmd-30") == 0 || strcmp(szCmd,"cmd-31") == 0 || strcmp(szCmd,"cmd-32") == 0 ||
  565. strcmp(szCmd,"cmd-33") == 0 || strcmp(szCmd,"cmd-34") == 0 || strcmp(szCmd,"cmd-35") == 0 ||
  566. strcmp(szCmd,"cmd-36") == 0
  567. )
  568. {
  569. #if IS_USE_READMSG_CS
  570. EnterCriticalSection(&m_csReadMsg);
  571. #endif
  572. memcpy(m_szStatuMsg, pBuffer, sizeof(m_szStatuMsg));
  573. #if IS_USE_READMSG_CS
  574. LeaveCriticalSection(&m_csReadMsg);
  575. #endif
  576. }
  577. }
  578. void Cups_newave::SetAlarmMsg(char szCmd[MAX_CMD], char *pBuffer)
  579. {
  580. if (
  581. strcmp(szCmd,"cmd-37") == 0 || strcmp(szCmd,"cmd-38") == 0 ||
  582. strcmp(szCmd,"cmd-39") == 0 || strcmp(szCmd,"cmd-40") == 0 || strcmp(szCmd,"cmd-41") == 0 ||
  583. strcmp(szCmd,"cmd-42") == 0 || strcmp(szCmd,"cmd-43") == 0 || strcmp(szCmd,"cmd-44") == 0 ||
  584. strcmp(szCmd,"cmd-45") == 0 || strcmp(szCmd,"cmd-46") == 0 || strcmp(szCmd,"cmd-47") == 0 ||
  585. strcmp(szCmd,"cmd-48") == 0 || strcmp(szCmd,"cmd-49") == 0 || strcmp(szCmd,"cmd-50") == 0 ||
  586. strcmp(szCmd,"cmd-51") == 0 || strcmp(szCmd,"cmd-52") == 0 || strcmp(szCmd,"cmd-53") == 0 ||
  587. strcmp(szCmd,"cmd-54") == 0 || strcmp(szCmd,"cmd-55") == 0 || strcmp(szCmd,"cmd-56") == 0 ||
  588. strcmp(szCmd,"cmd-57") == 0 || strcmp(szCmd,"cmd-58") == 0 || strcmp(szCmd,"cmd-59") == 0 ||
  589. strcmp(szCmd,"cmd-60") == 0 || strcmp(szCmd,"cmd-61") == 0 || strcmp(szCmd,"cmd-62") == 0 ||
  590. strcmp(szCmd,"cmd-63") == 0 || strcmp(szCmd,"cmd-64") == 0 || strcmp(szCmd,"cmd-65") == 0 ||
  591. strcmp(szCmd,"cmd-66") == 0
  592. )
  593. {
  594. #if IS_USE_READMSG_CS
  595. EnterCriticalSection(&m_csReadMsg);
  596. #endif
  597. memcpy(m_szAlarmMsg, pBuffer, sizeof(m_szAlarmMsg));
  598. #if IS_USE_READMSG_CS
  599. LeaveCriticalSection(&m_csReadMsg);
  600. #endif
  601. }
  602. }
  603. void Cups_newave::SimulationCommData()
  604. {
  605. memcpy(m_szValueMsg, ">01A0575999,100,2277,2278,2289,2204,2197,2199,3,7,4,12,23,150BDF", sizeof(">01A0575999,100,2277,2278,2289,2204,2197,2199,3,7,4,12,23,150BDF"));
  606. memcpy(m_szStatuMsg, ">01A012C0C291B3033A", sizeof(">01A012C0C291B3033A"));
  607. memcpy(m_szAlarmMsg, ">01A018808080808080800451", sizeof(">01A018808080808080800451"));
  608. }