UpsKeHua.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. // UpsKeHua.cpp: implementation of the CUpsKeHua class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "UpsKeHua.h"
  6. #include "CommProcess.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CUpsKeHua::CUpsKeHua(
  16. char szPath[MAX_PATH], // 程序所在路径
  17. char szIniName[MAX_PATH], // 配置文件名称
  18. int nCommPort, // 串行端口
  19. int nAddr, // 设备地址
  20. int nRate, // 波特率
  21. int nDataBit, // 数据位
  22. int nStopBit, // 停止位
  23. 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 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
  31. memset(m_szKeHua_Q1Msg, 0, sizeof(m_szKeHua_Q1Msg));
  32. memset(m_szKeHua_G1Msg, 0, sizeof(m_szKeHua_G1Msg));
  33. memset(m_szKeHua_G2Msg, 0, sizeof(m_szKeHua_G2Msg));
  34. memset(m_szKeHua_G3Msg, 0, sizeof(m_szKeHua_G3Msg));
  35. memset(m_szKeHua_GFMsg, 0, sizeof(m_szKeHua_GFMsg));
  36. m_devOnline = TRUE;
  37. m_dwOnlineTick = 0;
  38. }
  39. CUpsKeHua::~CUpsKeHua()
  40. {
  41. #if IS_USE_READMSG_CS
  42. DeleteCriticalSection( &m_csReadMsg );
  43. #endif
  44. MTVERIFY( CloseHandle( m_hSemComm ) );
  45. CloseComm();
  46. }
  47. BOOL CUpsKeHua::UpsKeHuaOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  48. {
  49. BOOL bResult = FALSE;
  50. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  51. return bResult;
  52. }
  53. // 发送读取设备参数请求
  54. int CUpsKeHua::SendReadRequest(
  55. char szPath[MAX_PATH], // 程序所在路径
  56. char szIniName[MAX_PATH], // 配置文件名称
  57. int nCommPort, // 串行端口
  58. int nAddr, // 设备地址
  59. char szCmd[MAX_CMD], // 请求命令
  60. char szMsg[VAR_MSG], // 响应的值
  61. int nReversed1, // 预留整形参数1接口
  62. int nReversed2, // 预留整形参数2接口
  63. int nReversed3, // 预留整形参数3接口
  64. int nReversed4, // 预留整形参数4接口
  65. int nReversed5, // 预留整形参数5接口
  66. float fReversed1, // 预留float参数1接口
  67. float fReversed2, // 预留float参数2接口
  68. float fReversed3, // 预留float参数3接口
  69. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  70. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  71. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  72. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  73. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  74. )
  75. {
  76. int nIndex = 0, nLen = 0;
  77. char szSendMsg[UPS_KEHUA_SEND_MSG] = {0};
  78. char szType[TYPE_LENGTH] = {0};
  79. GetFromIni(szPath, szIniName, szCmd, szSendMsg, nIndex, nLen, szType);
  80. CCommProcess *pComm = FindComm(nCommPort);
  81. if( pComm == NULL ) return -1;
  82. int nRet = -1;
  83. if( strlen(m_szKeHua_Q1Msg) == 0 ||
  84. strlen(m_szKeHua_G1Msg) == 0 ||
  85. strlen(m_szKeHua_G3Msg) == 0 ||
  86. strlen(m_szKeHua_GFMsg) == 0 ||
  87. strlen(m_szKeHua_G2Msg) == 0 ||
  88. strcmp(szCmd, "cmd-1") == 0 ||
  89. strcmp(szCmd, "cmd-14") == 0 ||
  90. strcmp(szCmd, "cmd-20") == 0 ||
  91. strcmp(szCmd, "cmd-32") == 0 ||
  92. strcmp(szCmd, "cmd-34") == 0
  93. )
  94. {
  95. int nRet = GetDeviceParam( pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  96. if( nRet != 0 )
  97. {
  98. return nRet;
  99. }
  100. }
  101. if( GetTickCount() - m_dwOnlineTick > 60 *1000 && m_dwOnlineTick > 0 )
  102. {
  103. m_devOnline = FALSE;
  104. }
  105. else if( GetTickCount() - m_dwOnlineTick < 60 *1000 && m_dwOnlineTick > 0 )
  106. {
  107. m_devOnline = TRUE;
  108. }
  109. if( m_devOnline == FALSE )
  110. {
  111. return -1;
  112. }
  113. nRet = GetKeHuaQ1VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  114. nRet = GetKeHuaG1VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  115. nRet = GetKeHuaG3VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  116. nRet = GetKeHuaGFVarMsg(szCmd, szMsg, nIndex, nLen, szType);
  117. nRet = GetKeHuaG2VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  118. return nRet;
  119. }
  120. int CUpsKeHua::RequestStatus(
  121. CCommProcess *pComm, //串口对象指针
  122. char chSendMsg[UPS_KEHUA_SEND_MSG] //发送Buffer
  123. )
  124. {
  125. #if DEBUG_UPS_KEHUA_U
  126. if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
  127. {
  128. int nDataLen = (int)strlen(chSendMsg);
  129. ResetEvent( m_hSemComm );
  130. int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen);
  131. if( nResult == nDataLen )
  132. {
  133. }
  134. else
  135. {
  136. SetEvent( m_hSemComm );
  137. return ERR_CODE_KEHUA_COM_WRITE_DATA;
  138. }
  139. }
  140. else
  141. {
  142. return ERR_CODE_KEHUA_COM_BUSY;
  143. }
  144. #endif
  145. return 0;
  146. }
  147. int CUpsKeHua::ResponseStatus(
  148. CCommProcess *pComm, //串口对象指针
  149. char szCmd[MAX_CMD], // 命令
  150. char szMsg[VAR_MSG], // 接收Buffer
  151. int &nIndex, // 变量索引,针对接收Buffer而言
  152. int &nLen, // 变量长度
  153. char szType[TYPE_LENGTH] // 变量数据类型
  154. )
  155. {
  156. #if DEBUG_UPS_KEHUA_U
  157. int nReceiveLen = 0;
  158. int nProcessLen = 0;
  159. int nReadLen = 0;
  160. RESPONSE_STRUCT structResponse;
  161. memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  162. nReceiveLen = sizeof(RESPONSE_STRUCT);
  163. char *pBuffer = new char[ nReceiveLen ];
  164. memset(pBuffer, 0, nLen);
  165. nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
  166. if( nReadLen <= 0)
  167. {
  168. // 串口没有读到数据
  169. TRACE("串口没有读到数据!\r\n");
  170. SetEvent( m_hSemComm );
  171. if( pBuffer != NULL)
  172. {
  173. delete[] pBuffer;
  174. pBuffer = NULL;
  175. }
  176. return ERR_CODE_COM_READ_NO_DATA;
  177. }
  178. SetKeHuaG1VarMsg(szCmd, pBuffer);
  179. SetKeHuaG2VarMsg(szCmd, pBuffer);
  180. SetKeHuaG3VarMsg(szCmd, pBuffer);
  181. SetKeHuaQ1VarMsg(szCmd, pBuffer);
  182. SetKeHuaGFVarMsg(szCmd, pBuffer);
  183. m_dwOnlineTick = GetTickCount();
  184. // 设置串口等待事件为有信号
  185. SetEvent( m_hSemComm );
  186. if( pBuffer != NULL)
  187. {
  188. delete[] pBuffer;
  189. pBuffer = NULL;
  190. }
  191. #else
  192. SimulationCommData();
  193. #endif
  194. return 0;
  195. }
  196. int CUpsKeHua::GetDeviceParam(
  197. CCommProcess *pComm, //串口对象指针
  198. char szSendMsg[UPS_KEHUA_SEND_MSG], //发送Buffer
  199. char szCmd[MAX_CMD], // 命令
  200. char szMsg[VAR_MSG], // 接收Buffer
  201. int &nIndex, // 变量索引,针对接收Buffer而言
  202. int &nLen, // 变量长度
  203. char szType[TYPE_LENGTH]) // 变量数据类型
  204. {
  205. int nRet = -1;
  206. nRet = RequestStatus(pComm, szSendMsg);
  207. if( nRet != 0 )
  208. {
  209. return nRet; // 串口忙
  210. }
  211. nRet = ResponseStatus(pComm, szCmd, szMsg, nIndex, nLen, szType);
  212. return nRet;
  213. }
  214. //读取配置文件
  215. int CUpsKeHua::GetFromIni(
  216. char szPath[MAX_PATH], //服务器程序所在目录
  217. char szIniName[MAX_PATH], //配置文件名
  218. char szCmd[MAX_CMD], //命令
  219. char szUpsKeHuaSendMsg[UPS_KEHUA_SEND_MSG], //发送Buffer
  220. int &nIndex,
  221. int &nLen,
  222. char szType[TYPE_LENGTH]
  223. )
  224. {
  225. CHAR szFile[MAX_PATH + 1] = "";
  226. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  227. GetPrivateProfileString(szCmd, "SendCmd", "", szUpsKeHuaSendMsg, sizeof(szUpsKeHuaSendMsg), szFile);
  228. szUpsKeHuaSendMsg[strlen(szUpsKeHuaSendMsg)] = 0x0D;
  229. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  230. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  231. return 0;
  232. }
  233. int CUpsKeHua::GetKeHuaQ1VarMsg(
  234. char szCmd[MAX_CMD], // 命令
  235. char szMsg[VAR_MSG], // 接收Buffer
  236. int &nIndex, // 变量索引,针对接收Buffer而言
  237. int &nLen, // 变量长度
  238. char szType[TYPE_LENGTH] // 变量数据类型
  239. )
  240. {
  241. int nRet = -1;
  242. if( strcmp(szCmd, "cmd-1") == 0 ||
  243. strcmp(szCmd, "cmd-2") == 0 ||
  244. strcmp(szCmd, "cmd-3") == 0 ||
  245. strcmp(szCmd, "cmd-4") == 0 ||
  246. strcmp(szCmd, "cmd-5") == 0 ||
  247. strcmp(szCmd, "cmd-6") == 0 ||
  248. strcmp(szCmd, "cmd-7") == 0 ||
  249. strcmp(szCmd, "cmd-8") == 0 ||
  250. strcmp(szCmd, "cmd-9") == 0 ||
  251. strcmp(szCmd, "cmd-10") == 0 ||
  252. strcmp(szCmd, "cmd-11") == 0 ||
  253. strcmp(szCmd, "cmd-12") == 0 ||
  254. strcmp(szCmd, "cmd-13") == 0
  255. )
  256. {
  257. #if IS_USE_READMSG_CS
  258. EnterCriticalSection( &m_csReadMsg );
  259. #endif
  260. memcpy(szMsg, m_szKeHua_Q1Msg + nIndex, nLen);
  261. #if IS_USE_READMSG_CS
  262. LeaveCriticalSection(&m_csReadMsg);
  263. #endif
  264. nRet = 0;
  265. }
  266. return nRet;
  267. }
  268. int CUpsKeHua::GetKeHuaG1VarMsg(
  269. char szCmd[MAX_CMD], // 命令
  270. char szMsg[VAR_MSG], // 接收Buffer
  271. int &nIndex, // 变量索引,针对接收Buffer而言
  272. int &nLen, // 变量长度
  273. char szType[TYPE_LENGTH] // 变量数据类型
  274. )
  275. {
  276. int nRet = 0;
  277. if( strcmp(szCmd, "cmd-1") == 0 ||
  278. strcmp(szCmd, "cmd-2") == 0 ||
  279. strcmp(szCmd, "cmd-3") == 0 ||
  280. strcmp(szCmd, "cmd-4") == 0 ||
  281. strcmp(szCmd, "cmd-5") == 0 ||
  282. strcmp(szCmd, "cmd-6") == 0 ||
  283. strcmp(szCmd, "cmd-7") == 0 ||
  284. strcmp(szCmd, "cmd-8") == 0 ||
  285. strcmp(szCmd, "cmd-9") == 0 ||
  286. strcmp(szCmd, "cmd-10") == 0 ||
  287. strcmp(szCmd, "cmd-11") == 0 ||
  288. strcmp(szCmd, "cmd-12") == 0 ||
  289. strcmp(szCmd, "cmd-13") == 0
  290. )
  291. {
  292. #if IS_USE_READMSG_CS
  293. EnterCriticalSection( &m_csReadMsg );
  294. #endif
  295. memcpy(szMsg, m_szKeHua_Q1Msg + nIndex, nLen);
  296. #if IS_USE_READMSG_CS
  297. LeaveCriticalSection(&m_csReadMsg);
  298. #endif
  299. nRet = 0;
  300. }
  301. return nRet;
  302. }
  303. int CUpsKeHua::GetKeHuaG2VarMsg(
  304. char szCmd[MAX_CMD], // 命令
  305. char szMsg[VAR_MSG], // 接收Buffer
  306. int &nIndex, // 变量索引,针对接收Buffer而言
  307. int &nLen, // 变量长度
  308. char szType[TYPE_LENGTH] // 变量数据类型
  309. )
  310. {
  311. int nRet = -1;
  312. if( strcmp(szCmd, "cmd-1") == 0 ||
  313. strcmp(szCmd, "cmd-2") == 0 ||
  314. strcmp(szCmd, "cmd-3") == 0 ||
  315. strcmp(szCmd, "cmd-4") == 0 ||
  316. strcmp(szCmd, "cmd-5") == 0 ||
  317. strcmp(szCmd, "cmd-6") == 0 ||
  318. strcmp(szCmd, "cmd-7") == 0 ||
  319. strcmp(szCmd, "cmd-8") == 0 ||
  320. strcmp(szCmd, "cmd-9") == 0 ||
  321. strcmp(szCmd, "cmd-10") == 0 ||
  322. strcmp(szCmd, "cmd-11") == 0 ||
  323. strcmp(szCmd, "cmd-12") == 0 ||
  324. strcmp(szCmd, "cmd-13") == 0
  325. )
  326. {
  327. #if IS_USE_READMSG_CS
  328. EnterCriticalSection( &m_csReadMsg );
  329. #endif
  330. memcpy(szMsg, m_szKeHua_Q1Msg + nIndex, nLen);
  331. #if IS_USE_READMSG_CS
  332. LeaveCriticalSection(&m_csReadMsg);
  333. #endif
  334. nRet = 0;
  335. }
  336. return nRet;
  337. }
  338. int CUpsKeHua::GetKeHuaG3VarMsg(
  339. char szCmd[MAX_CMD], // 命令
  340. char szMsg[VAR_MSG], // 接收Buffer
  341. int &nIndex, // 变量索引,针对接收Buffer而言
  342. int &nLen, // 变量长度
  343. char szType[TYPE_LENGTH] // 变量数据类型
  344. )
  345. {
  346. int nRet = -1;
  347. if( strcmp(szCmd, "cmd-1") == 0 ||
  348. strcmp(szCmd, "cmd-2") == 0 ||
  349. strcmp(szCmd, "cmd-3") == 0 ||
  350. strcmp(szCmd, "cmd-4") == 0 ||
  351. strcmp(szCmd, "cmd-5") == 0 ||
  352. strcmp(szCmd, "cmd-6") == 0 ||
  353. strcmp(szCmd, "cmd-7") == 0 ||
  354. strcmp(szCmd, "cmd-8") == 0 ||
  355. strcmp(szCmd, "cmd-9") == 0 ||
  356. strcmp(szCmd, "cmd-10") == 0 ||
  357. strcmp(szCmd, "cmd-11") == 0 ||
  358. strcmp(szCmd, "cmd-12") == 0 ||
  359. strcmp(szCmd, "cmd-13") == 0
  360. )
  361. {
  362. #if IS_USE_READMSG_CS
  363. EnterCriticalSection( &m_csReadMsg );
  364. #endif
  365. memcpy(szMsg, m_szKeHua_Q1Msg + nIndex, nLen);
  366. #if IS_USE_READMSG_CS
  367. LeaveCriticalSection(&m_csReadMsg);
  368. #endif
  369. nRet = 0;
  370. }
  371. return nRet;
  372. }
  373. int CUpsKeHua::GetKeHuaGFVarMsg(
  374. char szCmd[MAX_CMD], // 命令
  375. char szMsg[VAR_MSG], // 接收Buffer
  376. int &nIndex, // 变量索引,针对接收Buffer而言
  377. int &nLen, // 变量长度
  378. char szType[TYPE_LENGTH] // 变量数据类型
  379. )
  380. {
  381. int nRet = -1;
  382. if( strcmp(szCmd, "cmd-1") == 0 ||
  383. strcmp(szCmd, "cmd-2") == 0 ||
  384. strcmp(szCmd, "cmd-3") == 0 ||
  385. strcmp(szCmd, "cmd-4") == 0 ||
  386. strcmp(szCmd, "cmd-5") == 0 ||
  387. strcmp(szCmd, "cmd-6") == 0 ||
  388. strcmp(szCmd, "cmd-7") == 0 ||
  389. strcmp(szCmd, "cmd-8") == 0 ||
  390. strcmp(szCmd, "cmd-9") == 0 ||
  391. strcmp(szCmd, "cmd-10") == 0 ||
  392. strcmp(szCmd, "cmd-11") == 0 ||
  393. strcmp(szCmd, "cmd-12") == 0 ||
  394. strcmp(szCmd, "cmd-13") == 0
  395. )
  396. {
  397. #if IS_USE_READMSG_CS
  398. EnterCriticalSection( &m_csReadMsg );
  399. #endif
  400. memcpy(szMsg, m_szKeHua_Q1Msg + nIndex, nLen);
  401. #if IS_USE_READMSG_CS
  402. LeaveCriticalSection(&m_csReadMsg);
  403. #endif
  404. nRet = 0;
  405. }
  406. return nRet;
  407. }
  408. void CUpsKeHua::SetKeHuaQ1VarMsg( char szCmd[MAX_CMD], char *pBuffer)
  409. {
  410. if( strcmp(szCmd, "cmd-1") == 0 ||
  411. strcmp(szCmd, "cmd-2") == 0 ||
  412. strcmp(szCmd, "cmd-3") == 0 ||
  413. strcmp(szCmd, "cmd-4") == 0 ||
  414. strcmp(szCmd, "cmd-5") == 0 ||
  415. strcmp(szCmd, "cmd-6") == 0 ||
  416. strcmp(szCmd, "cmd-7") == 0 ||
  417. strcmp(szCmd, "cmd-8") == 0 ||
  418. strcmp(szCmd, "cmd-9") == 0 ||
  419. strcmp(szCmd, "cmd-10") == 0 ||
  420. strcmp(szCmd, "cmd-11") == 0 ||
  421. strcmp(szCmd, "cmd-12") == 0 ||
  422. strcmp(szCmd, "cmd-13") == 0
  423. )
  424. {
  425. #if IS_USE_READMSG_CS
  426. EnterCriticalSection( &m_csReadMsg );
  427. #endif
  428. memcpy(m_szKeHua_Q1Msg, pBuffer, sizeof(m_szKeHua_Q1Msg));
  429. #if IS_USE_READMSG_CS
  430. LeaveCriticalSection(&m_csReadMsg);
  431. #endif
  432. }
  433. }
  434. void CUpsKeHua::SetKeHuaG1VarMsg( char szCmd[MAX_CMD], char *pBuffer)
  435. {
  436. if( strcmp(szCmd, "cmd-14") == 0 ||
  437. strcmp(szCmd, "cmd-15") == 0 ||
  438. strcmp(szCmd, "cmd-16") == 0 ||
  439. strcmp(szCmd, "cmd-17") == 0 ||
  440. strcmp(szCmd, "cmd-18") == 0 ||
  441. strcmp(szCmd, "cmd-19") == 0
  442. )
  443. {
  444. #if IS_USE_READMSG_CS
  445. EnterCriticalSection( &m_csReadMsg );
  446. #endif
  447. memcpy(m_szKeHua_G1Msg, pBuffer, sizeof(m_szKeHua_G1Msg));
  448. #if IS_USE_READMSG_CS
  449. LeaveCriticalSection(&m_csReadMsg);
  450. #endif
  451. }
  452. }
  453. void CUpsKeHua::SetKeHuaG2VarMsg( char szCmd[MAX_CMD], char *pBuffer)
  454. {
  455. if( strcmp(szCmd, "cmd-34") == 0 ||
  456. strcmp(szCmd, "cmd-35") == 0 ||
  457. strcmp(szCmd, "cmd-36") == 0 ||
  458. strcmp(szCmd, "cmd-37") == 0 ||
  459. strcmp(szCmd, "cmd-38") == 0 ||
  460. strcmp(szCmd, "cmd-39") == 0 ||
  461. strcmp(szCmd, "cmd-40") == 0 ||
  462. strcmp(szCmd, "cmd-41") == 0 ||
  463. strcmp(szCmd, "cmd-42") == 0
  464. )
  465. {
  466. #if IS_USE_READMSG_CS
  467. EnterCriticalSection( &m_csReadMsg );
  468. #endif
  469. memcpy(m_szKeHua_G2Msg, pBuffer, sizeof(m_szKeHua_G2Msg));
  470. #if IS_USE_READMSG_CS
  471. LeaveCriticalSection(&m_csReadMsg);
  472. #endif
  473. }
  474. }
  475. void CUpsKeHua::SetKeHuaG3VarMsg( char szCmd[MAX_CMD], char *pBuffer)
  476. {
  477. if( strcmp(szCmd, "cmd-20") == 0 ||
  478. strcmp(szCmd, "cmd-21") == 0 ||
  479. strcmp(szCmd, "cmd-22") == 0 ||
  480. strcmp(szCmd, "cmd-23") == 0 ||
  481. strcmp(szCmd, "cmd-24") == 0 ||
  482. strcmp(szCmd, "cmd-25") == 0 ||
  483. strcmp(szCmd, "cmd-26") == 0 ||
  484. strcmp(szCmd, "cmd-27") == 0 ||
  485. strcmp(szCmd, "cmd-28") == 0 ||
  486. strcmp(szCmd, "cmd-29") == 0 ||
  487. strcmp(szCmd, "cmd-30") == 0 ||
  488. strcmp(szCmd, "cmd-31") == 0
  489. )
  490. {
  491. #if IS_USE_READMSG_CS
  492. EnterCriticalSection( &m_csReadMsg );
  493. #endif
  494. memcpy(m_szKeHua_G3Msg, pBuffer, sizeof(m_szKeHua_G3Msg));
  495. #if IS_USE_READMSG_CS
  496. LeaveCriticalSection(&m_csReadMsg);
  497. #endif
  498. }
  499. }
  500. void CUpsKeHua::SetKeHuaGFVarMsg( char szCmd[MAX_CMD], char *pBuffer)
  501. {
  502. if( strcmp(szCmd, "cmd-32") == 0 ||
  503. strcmp(szCmd, "cmd-33") == 0
  504. )
  505. {
  506. #if IS_USE_READMSG_CS
  507. EnterCriticalSection( &m_csReadMsg );
  508. #endif
  509. memcpy(m_szKeHua_GFMsg, pBuffer, sizeof(m_szKeHua_GFMsg));
  510. #if IS_USE_READMSG_CS
  511. LeaveCriticalSection(&m_csReadMsg);
  512. #endif
  513. }
  514. }
  515. void CUpsKeHua::SimulationCommData(void)
  516. {
  517. //28 30 30 30 2E 30 20 30 30 30 2E 30 20 32 32 30 (000.0 000.0 220
  518. //2E 30 20 30 30 30 20 30 30 2E 30 20 32 2E 31 33 .0 000 00.0 2.13
  519. //20 32 32 2E 30 20 31 30 30 31 30 30 30 30 0D 22.0 10010000.
  520. m_szKeHua_Q1Msg[0] = 0x28;
  521. m_szKeHua_Q1Msg[1] = 0x30;
  522. m_szKeHua_Q1Msg[2] = 0x30;
  523. m_szKeHua_Q1Msg[3] = 0x30;
  524. m_szKeHua_Q1Msg[4] = 0x2E;
  525. m_szKeHua_Q1Msg[5] = 0x30;
  526. m_szKeHua_Q1Msg[6] = 0x20;
  527. m_szKeHua_Q1Msg[7] = 0x30;
  528. m_szKeHua_Q1Msg[8] = 0x30;
  529. m_szKeHua_Q1Msg[9] = 0x30;
  530. m_szKeHua_Q1Msg[10] = 0x2E;
  531. m_szKeHua_Q1Msg[11] = 0x30;
  532. m_szKeHua_Q1Msg[12] = 0x20;
  533. m_szKeHua_Q1Msg[13] = 0x32;
  534. m_szKeHua_Q1Msg[14] = 0x32;
  535. m_szKeHua_Q1Msg[15] = 0x30;
  536. m_szKeHua_Q1Msg[16] = 0x2E;
  537. m_szKeHua_Q1Msg[17] = 0x30;
  538. m_szKeHua_Q1Msg[18] = 0x20;
  539. m_szKeHua_Q1Msg[19] = 0x30;
  540. m_szKeHua_Q1Msg[20] = 0x30;
  541. m_szKeHua_Q1Msg[21] = 0x30;
  542. m_szKeHua_Q1Msg[22] = 0x20;
  543. m_szKeHua_Q1Msg[23] = 0x30;
  544. m_szKeHua_Q1Msg[24] = 0x30;
  545. m_szKeHua_Q1Msg[25] = 0x2E;
  546. m_szKeHua_Q1Msg[26] = 0x30;
  547. m_szKeHua_Q1Msg[27] = 0x20;
  548. m_szKeHua_Q1Msg[28] = 0x32;
  549. m_szKeHua_Q1Msg[29] = 0x2E;
  550. m_szKeHua_Q1Msg[30] = 0x31;
  551. m_szKeHua_Q1Msg[31] = 0x33;
  552. m_szKeHua_Q1Msg[32] = 0x20;
  553. m_szKeHua_Q1Msg[33] = 0x32;
  554. m_szKeHua_Q1Msg[34] = 0x32;
  555. m_szKeHua_Q1Msg[35] = 0x2E;
  556. m_szKeHua_Q1Msg[36] = 0x30;
  557. m_szKeHua_Q1Msg[37] = 0x20;
  558. m_szKeHua_Q1Msg[38] = 0x31;
  559. m_szKeHua_Q1Msg[39] = 0x30;
  560. m_szKeHua_Q1Msg[40] = 0x30;
  561. m_szKeHua_Q1Msg[41] = 0x31;
  562. m_szKeHua_Q1Msg[42] = 0x30;
  563. m_szKeHua_Q1Msg[43] = 0x30;
  564. m_szKeHua_Q1Msg[44] = 0x30;
  565. m_szKeHua_Q1Msg[45] = 0x30;
  566. m_szKeHua_Q1Msg[46] = 0x0D;
  567. //21 33 37 31 20 30 36 38 20 34 33 33 31 20 30 30 !371 068 4331 00
  568. //32 2E 35 20 2B 30 30 2E 30 20 30 30 2E 30 20 30 2.5 +00.0 00.0 0
  569. //30 2E 30 20 34 39 2E 39 0D 0.0 49.9.
  570. m_szKeHua_G1Msg[0] = 0x21;
  571. m_szKeHua_G1Msg[1] = 0x33;
  572. m_szKeHua_G1Msg[2] = 0x37;
  573. m_szKeHua_G1Msg[3] = 0x31;
  574. m_szKeHua_G1Msg[4] = 0x20;
  575. m_szKeHua_G1Msg[5] = 0x20;
  576. m_szKeHua_G1Msg[6] = 0x36;
  577. m_szKeHua_G1Msg[7] = 0x38;
  578. m_szKeHua_G1Msg[8] = 0x20;
  579. m_szKeHua_G1Msg[9] = 0x34;
  580. m_szKeHua_G1Msg[10] = 0x33;
  581. m_szKeHua_G1Msg[11] = 0x33;
  582. m_szKeHua_G1Msg[12] = 0x31;
  583. m_szKeHua_G1Msg[13] = 0x20;
  584. m_szKeHua_G1Msg[14] = 0x30;
  585. m_szKeHua_G1Msg[15] = 0x30;
  586. m_szKeHua_G1Msg[16] = 0x32;
  587. m_szKeHua_G1Msg[17] = 0x2E;
  588. m_szKeHua_G1Msg[18] = 0x35;
  589. m_szKeHua_G1Msg[19] = 0x20;
  590. m_szKeHua_G1Msg[20] = 0x2B;
  591. m_szKeHua_G1Msg[21] = 0x30;
  592. m_szKeHua_G1Msg[22] = 0x30;
  593. m_szKeHua_G1Msg[23] = 0x2E;
  594. m_szKeHua_G1Msg[24] = 0x30;
  595. m_szKeHua_G1Msg[25] = 0x20;
  596. m_szKeHua_G1Msg[26] = 0x30;
  597. m_szKeHua_G1Msg[27] = 0x30;
  598. m_szKeHua_G1Msg[28] = 0x2E;
  599. m_szKeHua_G1Msg[29] = 0x30;
  600. m_szKeHua_G1Msg[30] = 0x20;
  601. m_szKeHua_G1Msg[31] = 0x30;
  602. m_szKeHua_G1Msg[32] = 0x30;
  603. m_szKeHua_G1Msg[33] = 0x2E;
  604. m_szKeHua_G1Msg[34] = 0x30;
  605. m_szKeHua_G1Msg[35] = 0x20;
  606. m_szKeHua_G1Msg[36] = 0x34;
  607. m_szKeHua_G1Msg[37] = 0x39;
  608. m_szKeHua_G1Msg[38] = 0x2E;
  609. m_szKeHua_G1Msg[39] = 0x39;
  610. m_szKeHua_G1Msg[40] = 0x0D;
  611. //21 30 31 30 30 30 31 30 30 20 30 30 30 31 31 30 !01000100 000110
  612. //31 31 20 30 30 30 30 30 30 30 30 0D 11 00000000.
  613. m_szKeHua_G2Msg[0] = 0x21;
  614. m_szKeHua_G2Msg[1] = 0x30;
  615. m_szKeHua_G2Msg[2] = 0x31;
  616. m_szKeHua_G2Msg[3] = 0x30;
  617. m_szKeHua_G2Msg[4] = 0x30;
  618. m_szKeHua_G2Msg[5] = 0x30;
  619. m_szKeHua_G2Msg[6] = 0x31;
  620. m_szKeHua_G2Msg[7] = 0x30;
  621. m_szKeHua_G2Msg[8] = 0x30;
  622. m_szKeHua_G2Msg[9] = 0x20;
  623. m_szKeHua_G2Msg[10] = 0x30;
  624. m_szKeHua_G2Msg[11] = 0x30;
  625. m_szKeHua_G2Msg[12] = 0x30;
  626. m_szKeHua_G2Msg[13] = 0x31;
  627. m_szKeHua_G2Msg[14] = 0x31;
  628. m_szKeHua_G2Msg[15] = 0x30;
  629. m_szKeHua_G2Msg[16] = 0x31;
  630. m_szKeHua_G2Msg[17] = 0x31;
  631. m_szKeHua_G2Msg[18] = 0x20;
  632. m_szKeHua_G2Msg[19] = 0x30;
  633. m_szKeHua_G2Msg[20] = 0x30;
  634. m_szKeHua_G2Msg[21] = 0x30;
  635. m_szKeHua_G2Msg[22] = 0x30;
  636. m_szKeHua_G2Msg[23] = 0x30;
  637. m_szKeHua_G2Msg[24] = 0x30;
  638. m_szKeHua_G2Msg[25] = 0x30;
  639. m_szKeHua_G2Msg[26] = 0x30;
  640. m_szKeHua_G2Msg[27] = 0x0D;
  641. //21 30 30 30 2E 30 2F 30 30 30 2E 30 2F 30 30 30 !000.0/000.0/000
  642. //2E 30 20 30 30 32 2E 34 2F 30 30 32 2E 37 2F 30 .0 002.4/002.7/0
  643. m_szKeHua_G3Msg[0] = 0x21;
  644. m_szKeHua_G3Msg[1] = 0x30;
  645. m_szKeHua_G3Msg[2] = 0x30;
  646. m_szKeHua_G3Msg[3] = 0x30;
  647. m_szKeHua_G3Msg[4] = 0x2E;
  648. m_szKeHua_G3Msg[5] = 0x30;
  649. m_szKeHua_G3Msg[6] = 0x2F;
  650. m_szKeHua_G3Msg[7] = 0x30;
  651. m_szKeHua_G3Msg[8] = 0x30;
  652. m_szKeHua_G3Msg[9] = 0x30;
  653. m_szKeHua_G3Msg[10] = 0x2E;
  654. m_szKeHua_G3Msg[11] = 0x30;
  655. m_szKeHua_G3Msg[12] = 0x2F;
  656. m_szKeHua_G3Msg[13] = 0x30;
  657. m_szKeHua_G3Msg[14] = 0x30;
  658. m_szKeHua_G3Msg[15] = 0x30;
  659. m_szKeHua_G3Msg[16] = 0x2E;
  660. m_szKeHua_G3Msg[17] = 0x30;
  661. m_szKeHua_G3Msg[18] = 0x20;
  662. m_szKeHua_G3Msg[19] = 0x30;
  663. m_szKeHua_G3Msg[20] = 0x30;
  664. m_szKeHua_G3Msg[21] = 0x32;
  665. m_szKeHua_G3Msg[22] = 0x2E;
  666. m_szKeHua_G3Msg[23] = 0x34;
  667. m_szKeHua_G3Msg[24] = 0x2F;
  668. m_szKeHua_G3Msg[25] = 0x30;
  669. m_szKeHua_G3Msg[26] = 0x30;
  670. m_szKeHua_G3Msg[27] = 0x32;
  671. m_szKeHua_G3Msg[28] = 0x2E;
  672. m_szKeHua_G3Msg[29] = 0x37;
  673. m_szKeHua_G3Msg[30] = 0x2F;
  674. m_szKeHua_G3Msg[31] = 0x30;
  675. //30 32 2E 37 20 32 32 30 2E 30 2F 32 32 30 2E 30 02.7 220.0/220.0
  676. //2F 32 32 30 2E 30 20 30 30 30 2E 30 2F 30 30 30 /220.0 000.0/000
  677. //2E 30 2F 30 30 30 2E 30 0D .0/000.0.
  678. m_szKeHua_G3Msg[32] = 0x30;
  679. m_szKeHua_G3Msg[33] = 0x32;
  680. m_szKeHua_G3Msg[34] = 0x2E;
  681. m_szKeHua_G3Msg[35] = 0x37;
  682. m_szKeHua_G3Msg[36] = 0x20;
  683. m_szKeHua_G3Msg[37] = 0x32;
  684. m_szKeHua_G3Msg[38] = 0x32;
  685. m_szKeHua_G3Msg[39] = 0x30;
  686. m_szKeHua_G3Msg[40] = 0x2E;
  687. m_szKeHua_G3Msg[41] = 0x30;
  688. m_szKeHua_G3Msg[42] = 0x2F;
  689. m_szKeHua_G3Msg[43] = 0x32;
  690. m_szKeHua_G3Msg[44] = 0x32;
  691. m_szKeHua_G3Msg[45] = 0x30;
  692. m_szKeHua_G3Msg[46] = 0x2E;
  693. m_szKeHua_G3Msg[47] = 0x30;
  694. m_szKeHua_G3Msg[48] = 0x2F;
  695. m_szKeHua_G3Msg[49] = 0x32;
  696. m_szKeHua_G3Msg[50] = 0x32;
  697. m_szKeHua_G3Msg[51] = 0x30;
  698. m_szKeHua_G3Msg[52] = 0x2E;
  699. m_szKeHua_G3Msg[53] = 0x30;
  700. m_szKeHua_G3Msg[54] = 0x20;
  701. m_szKeHua_G3Msg[55] = 0x30;
  702. m_szKeHua_G3Msg[56] = 0x30;
  703. m_szKeHua_G3Msg[57] = 0x30;
  704. m_szKeHua_G3Msg[58] = 0x2E;
  705. m_szKeHua_G3Msg[59] = 0x30;
  706. m_szKeHua_G3Msg[60] = 0x2F;
  707. m_szKeHua_G3Msg[61] = 0x30;
  708. m_szKeHua_G3Msg[62] = 0x30;
  709. m_szKeHua_G3Msg[63] = 0x30;
  710. m_szKeHua_G3Msg[64] = 0x2E;
  711. m_szKeHua_G3Msg[65] = 0x30;
  712. m_szKeHua_G3Msg[66] = 0x2F;
  713. m_szKeHua_G3Msg[67] = 0x30;
  714. m_szKeHua_G3Msg[68] = 0x30;
  715. m_szKeHua_G3Msg[69] = 0x30;
  716. m_szKeHua_G3Msg[70] = 0x2E;
  717. m_szKeHua_G3Msg[71] = 0x30;
  718. m_szKeHua_G3Msg[72] = 0x0D;
  719. }