UpsUH31.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. //////////////////////////////////////////////////////////////////////////////
  2. ////// //////
  3. ////// 文 件: UpsUH31.cpp //////
  4. ////// 作 者: Suguobing //////
  5. ////// 创建时间: //////
  6. ////// 说 明: UH31协议 //////
  7. ////// //////
  8. ////// 修改时间:2010-05-10 //////
  9. ////// 修改说明:数据转换 //////
  10. ////// //////
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include "stdafx.h"
  13. #include "CommProcess.h"
  14. #include "UpsUH31.h"
  15. //UINT CUpsUhk31::ConfirmChar(char *pSource,char *pDes, char *pType,int len)//ASCII转换为字符串
  16. //{
  17. // char *nbuf = new char[len];
  18. // memset(nbuf, 0, len);
  19. // char nbuf1[30] = {0};
  20. // char nchar;
  21. // char nchar1;
  22. // char nchar2;
  23. // char nchar3;
  24. //
  25. // for (int i = 0; i< len; i++)
  26. // {
  27. // nbuf[i] = (char)AsciiToBYTE(pSource[i]);
  28. // }
  29. //
  30. // if (strcmp(pType, "DDWORD") == 0)
  31. // {
  32. // int j = 0;
  33. // for (int i = 0; i < len; i++)
  34. // {
  35. // nbuf1[j] = nbuf[i]<<4 | nbuf[i+1];
  36. // j++;
  37. // i+=2;
  38. // }
  39. // strcpy(pDes, nbuf1);
  40. //
  41. // }
  42. //
  43. // if (strcmp(pType, "UNIT") == 0)
  44. // {
  45. // nchar = nbuf[0]<<4 | nbuf[1];
  46. // nchar1 = nbuf[2]<<4 | nbuf[3];
  47. // nchar2 = nbuf[4]<<4 | nbuf[5];
  48. // nchar3 = nbuf[6]<<4 | nbuf[6];
  49. //
  50. // if ((nchar == 0) && (nchar1 == 0) && (nchar2 == 0) && (nchar3 == 0))
  51. // {
  52. // sprintf(pDes, "0");
  53. // }
  54. // else
  55. // {
  56. // sprintf(pDes, "%c%c%c%c",nchar, nchar1, nchar2, nchar3);
  57. // }
  58. // }
  59. //
  60. // if (strcmp(pType,"BYTE") == 0)
  61. // {
  62. // nchar = (nbuf[0]<<4) | nbuf[1];
  63. // if (nchar == 0)
  64. // {
  65. // sprintf(pDes,"0");
  66. // }
  67. // else
  68. // {
  69. // sprintf(pDes,"%c",nchar);
  70. // }
  71. // }
  72. // if (strcmp(pType, "WORD") == 0)
  73. // {
  74. // nchar = nbuf[0]<<4 | nbuf[1];
  75. // nchar1 = nbuf[2]<<4 | nbuf[3];
  76. // if ((nchar == 0) && (nchar1 == 0))
  77. // {
  78. // sprintf(pDes,"0");
  79. // }
  80. // else
  81. // {
  82. // sprintf(pDes,"%c%c",nchar,nchar1);
  83. //
  84. // }
  85. //
  86. // }
  87. // if (strcmp(pType,"FLOAT") == 0)
  88. // {
  89. // for (int i = 0; i < len; i++)
  90. // {
  91. // nbuf[i] = (char)AsciiToBYTE(pSource[i]);
  92. // }
  93. //
  94. // Test data;
  95. //
  96. // data.ch[0] = (nbuf[0]<<4) | nbuf[1];
  97. // data.ch[1] = (nbuf[2]<<4) | nbuf[3];
  98. // data.ch[2] = (nbuf[4]<<4) | nbuf[5];
  99. // data.ch[3] = (nbuf[6]<<4) | nbuf[7];
  100. //
  101. // sprintf(pDes,"%f",data.ff);
  102. // }
  103. //
  104. // delete [] nbuf;
  105. // return 0;
  106. //}
  107. CUpsUhk31::CUpsUhk31( char szPath[MAX_PATH],
  108. char szIniName[MAX_PATH],
  109. int nCommPort, int nAddr,
  110. int nRate, int nDataBit,
  111. int nStopBit, int nParity,
  112. int nInterval )
  113. {
  114. #if IS_USE_READMSG_CS
  115. InitializeCriticalSection(&m_csReadMsg);
  116. //InitializeCriticalSection(&m_csReadMsg);
  117. #endif
  118. MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
  119. memset(m_szUhk_Q41Msg, 0, sizeof(m_szUhk_Q41Msg));
  120. memset(m_szUhk_Q43Msg, 0, sizeof(m_szUhk_Q43Msg));
  121. memset(m_szUhk_Q44Msg, 0, sizeof(m_szUhk_Q44Msg));
  122. memset(m_szUhk_Q45Msg, 0, sizeof(m_szUhk_Q45Msg));
  123. memset(m_szUhk_Q46Msg, 0, sizeof(m_szUhk_Q46Msg));
  124. memset(m_szUhk_Q48Msg, 0, sizeof(m_szUhk_Q48Msg));//设定系统参数
  125. memset(m_szUhk_Q4FMsg, 0, sizeof(m_szUhk_Q4FMsg));
  126. memset(m_szUhk_Q50Msg, 0, sizeof(m_szUhk_Q50Msg));
  127. m_dwOnlineTick = 0;
  128. m_devOnline = TRUE;
  129. //OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  130. }
  131. CUpsUhk31::~CUpsUhk31()
  132. {
  133. #if IS_USE_READMSG_CS
  134. DeleteCriticalSection(& m_csReadMsg);
  135. #endif
  136. MTVERIFY(CloseHandle(m_hSemComm));
  137. CloseComm();
  138. }
  139. BOOL CUpsUhk31::UpsUhkOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  140. {
  141. BOOL bResult = FALSE;
  142. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  143. return bResult;
  144. }
  145. int CUpsUhk31::SendReadRequest(
  146. char szPath[MAX_PATH],
  147. char szIniName[MAX_PATH],
  148. int nCommPort,
  149. int nAddr,
  150. char szCmd[MAX_CMD],
  151. char szMsg[VAR_MSG],
  152. int nReversed1,
  153. int nReversed2,
  154. int nReversed3,
  155. int nReversed4,
  156. int nReversed5,
  157. float fReversed1,
  158. float fReversed2,
  159. float fReversed3,
  160. char szReversed1[MAX_RESERVED1],
  161. char szReversed2[MAX_RESERVED2],
  162. char szReversed3[MAX_RESERVED3],
  163. char szReversed4[MAX_RESERVED4],
  164. char szReversed5[MAX_RESERVED5]
  165. )
  166. {
  167. int nIndex = 0, nLen = 0;
  168. char szSendMsg[UPS_UHK_SEND_MSG] = {0};
  169. char szType[UPS_TYPE_LENGTH] = {0};
  170. int startBit = 0;
  171. int endBit = 0;
  172. m_address = nAddr;
  173. GetUhkFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen, startBit, endBit);
  174. CCommProcess *pComm = FindComm(nCommPort);
  175. if( pComm == NULL ) return -1;
  176. int nRet = -1;
  177. if( ( strlen(m_szUhk_Q41Msg) == 0 &&
  178. (strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
  179. strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ||
  180. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  181. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 ||
  182. strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 ||
  183. strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0 ||
  184. strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  185. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  186. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 ||
  187. strcmp(szCmd, "cmd-18") == 0 || strcmp(szCmd, "cmd-19") == 0 ||
  188. strcmp(szCmd, "cmd-20") == 0) ) || //获取系统模拟量量化数据(浮点数)
  189. ( strlen(m_szUhk_Q43Msg) == 0 &&
  190. (strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  191. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
  192. strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0 ||
  193. strcmp(szCmd, "cmd-27") == 0 ) )||//UPS工作状态及传送顺序
  194. ( strlen(m_szUhk_Q44Msg) == 0 &&
  195. (strcmp(szCmd, "cmd-28") == 0 || strcmp(szCmd, "cmd-29") == 0 ||
  196. strcmp(szCmd, "cmd-30") == 0 || strcmp(szCmd, "cmd-31") == 0 ||
  197. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 ||
  198. strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  199. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  200. strcmp(szCmd, "cmd-38") == 0 || strcmp(szCmd, "cmd-39") == 0 ||
  201. strcmp(szCmd, "cmd-40") == 0 || strcmp(szCmd, "cmd-41") == 0 ||
  202. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 ||
  203. strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 ) ) ||//UPS告警内容及传送
  204. ( strlen(m_szUhk_Q45Msg) == 0 &&
  205. (strcmp(szCmd, "cmd-73") == 0 ) ) ||//获取系统参数(浮点数)
  206. ( strlen(m_szUhk_Q46Msg) == 0 &&
  207. ( strcmp(szCmd, "cmd-46") == 0 ||
  208. strcmp(szCmd, "cmd-47") == 0 ||
  209. strcmp(szCmd, "cmd-48") == 0 ||
  210. strcmp(szCmd, "cmd-49") == 0 ||
  211. strcmp(szCmd, "cmd-50") == 0 ||
  212. strcmp(szCmd, "cmd-51") == 0 ||
  213. strcmp(szCmd, "cmd-52") == 0 ||
  214. strcmp(szCmd, "cmd-53") == 0 ||
  215. strcmp(szCmd, "cmd-54") == 0 ||
  216. strcmp(szCmd, "cmd-55") == 0 ||
  217. strcmp(szCmd, "cmd-56") == 0 ||
  218. strcmp(szCmd, "cmd-57") == 0 ||
  219. strcmp(szCmd, "cmd-58") == 0 ||
  220. strcmp(szCmd, "cmd-59") == 0 ) ) ||//获取监测模块
  221. ( strlen(m_szUhk_Q4FMsg) == 0 &&
  222. (strcmp(szCmd, "cmd-74") == 0 ) ) ||//获取通信协议版本号
  223. ( strlen(m_szUhk_Q50Msg) == 0 &&
  224. (strcmp(szCmd, "cmd-75") == 0 ) ) || //获取设备地址
  225. strcmp(szCmd, "cmd-1") == 0 ||
  226. strcmp(szCmd, "cmd-21") == 0 ||
  227. strcmp(szCmd, "cmd-28") == 0 ||
  228. strcmp(szCmd, "cmd-46") == 0 ||
  229. strcmp(szCmd, "cmd-73") == 0 ||
  230. strcmp(szCmd, "cmd-74") == 0 ||
  231. strcmp(szCmd, "cmd-75") == 0 )
  232. {
  233. nRet = GetDeviceParam( pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  234. if( nRet != 0 ) return nRet;
  235. }
  236. if( GetTickCount() - m_dwOnlineTick > 60 * 1000 && m_dwOnlineTick > 0 )
  237. {
  238. m_devOnline = FALSE;
  239. }
  240. else if( GetTickCount() - m_dwOnlineTick < 60 * 1000 && m_dwOnlineTick > 0 )
  241. {
  242. m_devOnline = TRUE;
  243. }
  244. if( m_devOnline == FALSE )
  245. {
  246. return -1;
  247. }
  248. nRet = GetUhkQ41VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  249. nRet = GetUhkQ43VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  250. nRet = GetUhkQ44VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  251. nRet = GetUhkQ45VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  252. nRet = GetUhkQ46VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  253. nRet = GetUhkQ4FVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  254. nRet = GetUhkQ50VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  255. return nRet;
  256. }
  257. int CUpsUhk31::GetUhkQ41VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit)
  258. {
  259. int nRet = 0;
  260. if (strcmp(szCmd, "cmd-1") == 0 ||
  261. strcmp(szCmd, "cmd-2") == 0 ||
  262. strcmp(szCmd, "cmd-3") == 0 ||
  263. strcmp(szCmd, "cmd-4") == 0 ||
  264. strcmp(szCmd, "cmd-6") == 0 ||
  265. strcmp(szCmd, "cmd-5") == 0 ||
  266. strcmp(szCmd, "cmd-6") == 0 ||
  267. strcmp(szCmd, "cmd-7") == 0 ||
  268. strcmp(szCmd, "cmd-8") == 0 ||
  269. strcmp(szCmd, "cmd-9") == 0 ||
  270. strcmp(szCmd, "cmd-10") == 0 ||
  271. strcmp(szCmd, "cmd-11") == 0 ||
  272. strcmp(szCmd, "cmd-12") == 0 ||
  273. strcmp(szCmd, "cmd-13") == 0 ||
  274. strcmp(szCmd, "cmd-14") == 0 ||
  275. strcmp(szCmd, "cmd-15") == 0 ||
  276. strcmp(szCmd, "cmd-16") == 0 ||
  277. strcmp(szCmd, "cmd-17") == 0 ||
  278. strcmp(szCmd, "cmd-18") == 0 ||
  279. strcmp(szCmd, "cmd-19") == 0 ||
  280. strcmp(szCmd, "cmd-20") == 0)
  281. {
  282. #if IS_USE_READMSG_CS
  283. EnterCriticalSection(&m_csReadMsg);
  284. #endif
  285. DataConversion(szType, m_szUhk_Q41Msg + nIndex, szMsg, nLen, startBit, endBit);
  286. #if IS_USE_READMSG_CS
  287. LeaveCriticalSection(&m_csReadMsg);
  288. #endif
  289. nRet = 0;
  290. }
  291. return nRet;
  292. }
  293. int CUpsUhk31::GetUhkQ43VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  294. {
  295. int nRet = 0;
  296. if (strcmp(szCmd, "cmd-21") == 0 ||
  297. strcmp(szCmd, "cmd-22") == 0 ||
  298. strcmp(szCmd, "cmd-23") == 0 ||
  299. strcmp(szCmd, "cmd-24") == 0 ||
  300. strcmp(szCmd, "cmd-25") == 0 ||
  301. strcmp(szCmd, "cmd-26") == 0 ||
  302. strcmp(szCmd, "cmd-27") == 0
  303. )
  304. {
  305. #if IS_USE_READMSG_CS
  306. EnterCriticalSection(&m_csReadMsg);
  307. #endif
  308. DataConversion(szType, m_szUhk_Q43Msg + nIndex, szMsg, nLen, startBit, endBit);
  309. #if IS_USE_READMSG_CS
  310. LeaveCriticalSection(&m_csReadMsg);
  311. #endif
  312. nRet = 0;
  313. }
  314. return nRet;
  315. }
  316. int CUpsUhk31::GetUhkQ44VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  317. {
  318. int nRet = 0;
  319. if (strcmp(szCmd, "cmd-28") == 0 ||
  320. strcmp(szCmd, "cmd-29") == 0 ||
  321. strcmp(szCmd, "cmd-30") == 0 ||
  322. strcmp(szCmd, "cmd-31") == 0 ||
  323. strcmp(szCmd, "cmd-32") == 0 ||
  324. strcmp(szCmd, "cmd-33") == 0 ||
  325. strcmp(szCmd, "cmd-34") == 0 ||
  326. strcmp(szCmd, "cmd-35") == 0 ||
  327. strcmp(szCmd, "cmd-36") == 0 ||
  328. strcmp(szCmd, "cmd-37") == 0 ||
  329. strcmp(szCmd, "cmd-38") == 0 ||
  330. strcmp(szCmd, "cmd-39") == 0 ||
  331. strcmp(szCmd, "cmd-40") == 0 ||
  332. strcmp(szCmd, "cmd-41") == 0 ||
  333. strcmp(szCmd, "cmd-42") == 0 ||
  334. strcmp(szCmd, "cmd-43") == 0 ||
  335. strcmp(szCmd, "cmd-44") == 0 ||
  336. strcmp(szCmd, "cmd-45") == 0
  337. )
  338. {
  339. #if IS_USE_READMSG_CS
  340. EnterCriticalSection(&m_csReadMsg);
  341. #endif
  342. DataConversion(szType, m_szUhk_Q44Msg + nIndex, szMsg, nLen, startBit, endBit);
  343. #if IS_USE_READMSG_CS
  344. LeaveCriticalSection(&m_csReadMsg);
  345. #endif
  346. nRet = 0;
  347. }
  348. return nRet;
  349. }
  350. int CUpsUhk31::GetUhkQ45VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  351. {
  352. int nRet = 0;
  353. if (strcmp(szCmd, "cmd-73") == 0 )
  354. {
  355. #if IS_USE_READMSG_CS
  356. EnterCriticalSection(&m_csReadMsg);
  357. #endif
  358. DataConversion(szType, m_szUhk_Q45Msg + nIndex, szMsg, nLen, startBit, endBit);
  359. #if IS_USE_READMSG_CS
  360. LeaveCriticalSection(&m_csReadMsg);
  361. #endif
  362. nRet = 0;
  363. }
  364. return nRet;
  365. }
  366. int CUpsUhk31::GetUhkQ46VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  367. {
  368. int nRet = 0;
  369. if ( strcmp(szCmd, "cmd-46") == 0 ||
  370. strcmp(szCmd, "cmd-47") == 0 ||
  371. strcmp(szCmd, "cmd-48") == 0 ||
  372. strcmp(szCmd, "cmd-49") == 0 ||
  373. strcmp(szCmd, "cmd-50") == 0 ||
  374. strcmp(szCmd, "cmd-51") == 0 ||
  375. strcmp(szCmd, "cmd-52") == 0 ||
  376. strcmp(szCmd, "cmd-53") == 0 ||
  377. strcmp(szCmd, "cmd-54") == 0 ||
  378. strcmp(szCmd, "cmd-55") == 0 ||
  379. strcmp(szCmd, "cmd-56") == 0 ||
  380. strcmp(szCmd, "cmd-57") == 0 ||
  381. strcmp(szCmd, "cmd-58") == 0 ||
  382. strcmp(szCmd, "cmd-59") == 0 )
  383. {
  384. #if IS_USE_READMSG_CS
  385. EnterCriticalSection(&m_csReadMsg);
  386. #endif
  387. DataConversion(szType, m_szUhk_Q45Msg + nIndex, szMsg, nLen, startBit, endBit);
  388. #if IS_USE_READMSG_CS
  389. LeaveCriticalSection(&m_csReadMsg);
  390. #endif
  391. nRet = 0;
  392. }
  393. return nRet;
  394. }
  395. int CUpsUhk31::GetUhkQ4FVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  396. {
  397. int nRet = 0;
  398. if (strcmp(szCmd, "cmd-74") == 0 )
  399. {
  400. #if IS_USE_READMSG_CS
  401. EnterCriticalSection(&m_csReadMsg);
  402. #endif
  403. DataConversion(szType, m_szUhk_Q4FMsg + nIndex, szMsg, nLen, startBit, endBit);
  404. #if IS_USE_READMSG_CS
  405. LeaveCriticalSection(&m_csReadMsg);
  406. #endif
  407. nRet = 0;
  408. }
  409. return nRet;
  410. }
  411. int CUpsUhk31::GetUhkQ50VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int startBit, int endBit )
  412. {
  413. int nRet = 0;
  414. if (strcmp(szCmd, "cmd-75") == 0 )
  415. {
  416. #if IS_USE_READMSG_CS
  417. EnterCriticalSection(&m_csReadMsg);
  418. #endif
  419. DataConversion(szType, m_szUhk_Q50Msg + nIndex, szMsg, nLen, startBit, endBit);
  420. #if IS_USE_READMSG_CS
  421. LeaveCriticalSection(&m_csReadMsg);
  422. #endif
  423. nRet = 0;
  424. }
  425. return nRet;
  426. }
  427. int CUpsUhk31::GetDeviceParam(
  428. CCommProcess *pComm, //串口对象指针
  429. char szSendMsg[UPS_UHK_SEND_MSG], //发送Buffer
  430. char szCmd[MAX_CMD], // 命令
  431. char szMsg[VAR_MSG], // 接收Buffer
  432. int &nIndex, // 变量索引,针对接收Buffer而言
  433. int &nLen, // 变量长度
  434. char szType[TYPE_LENGTH]) // 变量数据类型
  435. {
  436. int nRet = -1;
  437. nRet = RequestStatus(pComm, szSendMsg);
  438. if( nRet != 0 )
  439. {
  440. return nRet; // 串口忙
  441. }
  442. nRet = ResponseStatus(pComm, szCmd, szMsg, nIndex, nLen, szType);
  443. return nRet;
  444. }
  445. int CUpsUhk31::GetUhkFromIni(char szPath[MAX_PATH], //服务器程序所在目录
  446. char szIniName[MAX_PATH], //配置文件名
  447. char szCmd[MAX_CMD], //命令
  448. char szSanTakSendMsg[MAX_CMD], //发送Buffer
  449. char nType[MAX_CMD],
  450. int &nIndex,
  451. int &nLen,
  452. int &startBit,
  453. int &endBit)
  454. {
  455. CHAR szFile[MAX_PATH + 1] = "";
  456. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  457. TRACE("szFile =%s\n",szFile);
  458. GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, 10, szFile);
  459. szSanTakSendMsg[strlen(szSanTakSendMsg)] = '\0';
  460. GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
  461. nType[strlen(nType)] = '\0';
  462. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  463. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  464. TRACE("GetUhkFromIniszPath=%s\nszIniName=%s\nszCmd=%s\nzSanTakSendMsg=%s\nsType=%s\nnIndex=%d\nnLen = %d\n",
  465. szPath,szIniName,szCmd,szSanTakSendMsg,nType,nIndex,nLen);
  466. return 0;
  467. }
  468. int CUpsUhk31::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_UHK_SEND_MSG] )
  469. {
  470. #if DEBUG_UHK //开关量,用于测试模拟数据
  471. REQUEST_STRUCT structResuest;
  472. int nLen = sizeof(REQUEST_STRUCT);
  473. char chkSumBuf[5] ={0};
  474. char addBuf[UPS_TYPE_LENGTH] = {0};
  475. memset(&structResuest,0,nLen);
  476. //
  477. structResuest.headMes.Start = 0x7E;
  478. //
  479. structResuest.headMes.Version[0] = 0x32;
  480. structResuest.headMes.Version[1] = 0x31;
  481. //
  482. sprintf(addBuf, "%x",m_address);
  483. structResuest.headMes.Address[0] = ByteToAscii((m_address >> 4) & 0x0f);
  484. structResuest.headMes.Address[1] = ByteToAscii(m_address & 0x0f);
  485. //
  486. structResuest.headMes.Cid1[0] = 0x32;
  487. structResuest.headMes.Cid1[1] = 0x41;
  488. structResuest.headMes.Cid2[0] = ByteToAscii(chSendMsg[0] & 0x0f);
  489. structResuest.headMes.Cid2[1] = ByteToAscii(chSendMsg[1] & 0x0f);
  490. structResuest.headMes.Lenth[0] = 0x30;
  491. structResuest.headMes.Lenth[1] = 0x30;
  492. structResuest.headMes.Lenth[2] = 0x30;
  493. structResuest.headMes.Lenth[3] = 0x30;
  494. BYTE *pDatabuf = new BYTE[nLen - sizeof(structResuest.chkSum) - 1];
  495. memset(pDatabuf,0,nLen - sizeof(structResuest.chkSum) - 1);
  496. memcpy(pDatabuf,&structResuest,nLen - sizeof(structResuest.chkSum) - 1);
  497. GetCheckSum((char *)pDatabuf + 1, chkSumBuf, nLen - sizeof(structResuest.chkSum) - 2);
  498. structResuest.chkSum[0] = chkSumBuf[0];
  499. structResuest.chkSum[1] = chkSumBuf[1];
  500. structResuest.chkSum[2] = chkSumBuf[2];
  501. structResuest.chkSum[3] = chkSumBuf[3];
  502. structResuest.End = 0x0D;
  503. TRACE("headMes.Start= %c\nversion=%s\ncid1=%s\ncid2=%s\nlength=%s\nchksum=%s\n\n",
  504. structResuest.headMes.Start,structResuest.headMes.Version,
  505. structResuest.headMes.Address,structResuest.headMes.Cid1,
  506. structResuest.headMes.Cid2,structResuest.headMes.Lenth,structResuest.chkSum,structResuest.End);
  507. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
  508. {
  509. int nDatalen = (int)sizeof(structResuest);
  510. ResetEvent(m_hSemComm);
  511. int nResult = pComm->Write((BYTE *)&structResuest, nDatalen);
  512. if (nResult == nDatalen)
  513. {
  514. }
  515. else
  516. {
  517. delete [] pDatabuf;
  518. SetEvent(m_hSemComm);
  519. return EER_CODE_UPSKEHUA_COM_REGNUM;
  520. }
  521. }
  522. else
  523. {
  524. delete [] pDatabuf;
  525. return ERR_CODE_UPSKEHUA_COM_BUSY; //串口忙
  526. }
  527. delete [] pDatabuf;
  528. #endif
  529. TRACE("resquest return 0");
  530. return 0;
  531. }
  532. int CUpsUhk31::ResponseStatus(
  533. CCommProcess *pComm,
  534. char szCmd[MAX_CMD],
  535. char szMsg[VAR_MSG],
  536. int &nIndex,
  537. int &nLen,
  538. char szType[TYPE_LENGTH]
  539. )
  540. {
  541. #if DEBUG_UHK
  542. int nReceiveLen = 0;
  543. int nProcessLen = 0;
  544. int nReadLen = 0;
  545. RESPONSE_STRUCT strcutResponse;
  546. memset(&strcutResponse, 0, sizeof(RESPONSE_STRUCT));
  547. nReceiveLen = sizeof(RESPONSE_STRUCT);
  548. char *pBuff = new char[nReceiveLen];
  549. memset(pBuff, 0 , nLen);
  550. nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen);
  551. if (nReadLen <= 0)
  552. {
  553. SetEvent(m_hSemComm);
  554. if (pBuff != NULL)
  555. {
  556. delete [] pBuff;
  557. pBuff = NULL;
  558. }
  559. return ERR_CODE_UPSKEHUA_COM_READ_NO_DATA;
  560. }
  561. //长度校验出错
  562. if (LengthCheck(pBuff) != 0)
  563. {
  564. SetEvent(m_hSemComm);
  565. TRACE("长度校验出错");
  566. if (pBuff != NULL)
  567. {
  568. delete [] pBuff;
  569. pBuff = NULL;
  570. }
  571. return ERR_CODE_RTN_LCHKSUM_ERROR;
  572. }
  573. //int TempLen = strlen(pBuff);
  574. if (!ChkSumCheck(pBuff, nReadLen))
  575. {
  576. TRACE("校验码校验出错");
  577. SetEvent(m_hSemComm);
  578. if (pBuff != NULL)
  579. {
  580. delete [] pBuff;
  581. pBuff = NULL;
  582. }
  583. return ERR_CODE_RTN_CHKSUM_ERROR; //校验码校验出错
  584. }
  585. if (CheckRtn(pBuff, nReadLen) != 0)
  586. {
  587. TRACE("RTN校验出错");
  588. if (pBuff != NULL)
  589. {
  590. delete [] pBuff;
  591. pBuff = NULL;
  592. }
  593. return ERR_CODE_RTN_CHKSUM_RTN_ERROR; //RTN校验出错
  594. }
  595. SetUhkQ41VarMsg(szCmd, pBuff);
  596. SetUhkQ43VarMsg(szCmd, pBuff);
  597. SetUhkQ44VarMsg(szCmd, pBuff);
  598. SetUhkQ45VarMsg(szCmd, pBuff);
  599. SetUhkQ46VarMsg(szCmd, pBuff);
  600. SetUhkQ4FVarMsg(szCmd, pBuff);
  601. SetUhkQ50VarMsg(szCmd, pBuff);
  602. m_dwOnlineTick = GetTickCount();
  603. // 设置串口等待事件为有信号
  604. SetEvent( m_hSemComm );
  605. if( pBuff != NULL)
  606. {
  607. delete[] pBuff;
  608. pBuff = NULL;
  609. }
  610. #else
  611. SimulationCommData();
  612. #endif
  613. return 0;
  614. }
  615. void CUpsUhk31::SetUhkQ41VarMsg(char szCmd[MAX_CMD], char *pBuff)
  616. {
  617. if (strcmp(szCmd, "cmd-1") == 0 ||
  618. strcmp(szCmd, "cmd-2") == 0 ||
  619. strcmp(szCmd, "cmd-3") == 0 ||
  620. strcmp(szCmd, "cmd-4") == 0 ||
  621. strcmp(szCmd, "cmd-6") == 0 ||
  622. strcmp(szCmd, "cmd-5") == 0 ||
  623. strcmp(szCmd, "cmd-6") == 0 ||
  624. strcmp(szCmd, "cmd-7") == 0 ||
  625. strcmp(szCmd, "cmd-8") == 0 ||
  626. strcmp(szCmd, "cmd-9") == 0 ||
  627. strcmp(szCmd, "cmd-10") == 0 ||
  628. strcmp(szCmd, "cmd-11") == 0 ||
  629. strcmp(szCmd, "cmd-12") == 0 ||
  630. strcmp(szCmd, "cmd-13") == 0 ||
  631. strcmp(szCmd, "cmd-14") == 0 ||
  632. strcmp(szCmd, "cmd-15") == 0 ||
  633. strcmp(szCmd, "cmd-16") == 0 ||
  634. strcmp(szCmd, "cmd-17") == 0 ||
  635. strcmp(szCmd, "cmd-18") == 0 ||
  636. strcmp(szCmd, "cmd-19") == 0 ||
  637. strcmp(szCmd, "cmd-20") == 0)
  638. {
  639. #if IS_USE_READMSG_CS
  640. EnterCriticalSection(&m_csReadMsg);
  641. #endif
  642. memcpy(m_szUhk_Q41Msg, pBuff, sizeof(m_szUhk_Q41Msg));
  643. #if IS_USE_READMSG_CS
  644. LeaveCriticalSection(&m_csReadMsg);
  645. #endif
  646. }
  647. }
  648. void CUpsUhk31::SetUhkQ43VarMsg(char szCmd[MAX_CMD], char *pBuff)
  649. {
  650. if ( strcmp(szCmd, "cmd-21") == 0 ||
  651. strcmp(szCmd, "cmd-22") == 0 ||
  652. strcmp(szCmd, "cmd-23") == 0 ||
  653. strcmp(szCmd, "cmd-24") == 0 ||
  654. strcmp(szCmd, "cmd-25") == 0 ||
  655. strcmp(szCmd, "cmd-26") == 0 ||
  656. strcmp(szCmd, "cmd-27") == 0
  657. )
  658. {
  659. #if IS_USE_READMSG_CS
  660. EnterCriticalSection(&m_csReadMsg);
  661. #endif
  662. memcpy(m_szUhk_Q43Msg,pBuff,sizeof(m_szUhk_Q43Msg));
  663. #if IS_USE_READMSG_CS
  664. LeaveCriticalSection(&m_csReadMsg);
  665. #endif
  666. }
  667. }
  668. void CUpsUhk31::SetUhkQ44VarMsg(char szCmd[MAX_CMD], char *pBuff)
  669. {
  670. if ( strcmp(szCmd, "cmd-28") == 0 ||
  671. strcmp(szCmd, "cmd-29") == 0 ||
  672. strcmp(szCmd, "cmd-30") == 0 ||
  673. strcmp(szCmd, "cmd-31") == 0 ||
  674. strcmp(szCmd, "cmd-32") == 0 ||
  675. strcmp(szCmd, "cmd-33") == 0 ||
  676. strcmp(szCmd, "cmd-34") == 0 ||
  677. strcmp(szCmd, "cmd-35") == 0 ||
  678. strcmp(szCmd, "cmd-36") == 0 ||
  679. strcmp(szCmd, "cmd-37") == 0 ||
  680. strcmp(szCmd, "cmd-38") == 0 ||
  681. strcmp(szCmd, "cmd-39") == 0 ||
  682. strcmp(szCmd, "cmd-40") == 0 ||
  683. strcmp(szCmd, "cmd-41") == 0 ||
  684. strcmp(szCmd, "cmd-42") == 0 ||
  685. strcmp(szCmd, "cmd-43") == 0 ||
  686. strcmp(szCmd, "cmd-44") == 0 ||
  687. strcmp(szCmd, "cmd-45") == 0 )
  688. {
  689. #if IS_USE_READMSG_CS
  690. EnterCriticalSection(&m_csReadMsg);
  691. #endif
  692. memcpy(m_szUhk_Q44Msg,pBuff,sizeof(m_szUhk_Q44Msg));
  693. #if IS_USE_READMSG_CS
  694. LeaveCriticalSection(&m_csReadMsg);
  695. #endif
  696. }
  697. }
  698. void CUpsUhk31::SetUhkQ45VarMsg(char szCmd[MAX_CMD], char *pBuff)
  699. {
  700. if ( strcmp(szCmd, "cmd-73") == 0 ||
  701. strcmp(szCmd, "cmd-73") == 0)
  702. {
  703. #if IS_USE_READMSG_CS
  704. EnterCriticalSection(&m_csReadMsg);
  705. #endif
  706. memcpy(m_szUhk_Q45Msg,pBuff,sizeof(m_szUhk_Q45Msg));
  707. #if IS_USE_READMSG_CS
  708. LeaveCriticalSection(&m_csReadMsg);
  709. #endif
  710. }
  711. }
  712. void CUpsUhk31::SetUhkQ46VarMsg(char szCmd[MAX_CMD], char *pBuff)
  713. {
  714. if ( strcmp(szCmd, "cmd-46") == 0 ||
  715. strcmp(szCmd, "cmd-47") == 0 ||
  716. strcmp(szCmd, "cmd-48") == 0 ||
  717. strcmp(szCmd, "cmd-49") == 0 ||
  718. strcmp(szCmd, "cmd-50") == 0 ||
  719. strcmp(szCmd, "cmd-51") == 0 ||
  720. strcmp(szCmd, "cmd-52") == 0 ||
  721. strcmp(szCmd, "cmd-53") == 0 ||
  722. strcmp(szCmd, "cmd-54") == 0 ||
  723. strcmp(szCmd, "cmd-55") == 0 ||
  724. strcmp(szCmd, "cmd-56") == 0 ||
  725. strcmp(szCmd, "cmd-57") == 0 ||
  726. strcmp(szCmd, "cmd-58") == 0 ||
  727. strcmp(szCmd, "cmd-59") == 0 )
  728. {
  729. #if IS_USE_READMSG_CS
  730. EnterCriticalSection(&m_csReadMsg);
  731. #endif
  732. memcpy(m_szUhk_Q46Msg,pBuff,sizeof(m_szUhk_Q46Msg));
  733. #if IS_USE_READMSG_CS
  734. LeaveCriticalSection(&m_csReadMsg);
  735. #endif
  736. }
  737. }
  738. void CUpsUhk31::SetUhkQ4FVarMsg(char szCmd[MAX_CMD], char *pBuff)
  739. {
  740. if (strcmp(szCmd, "cmd-74") == 0 )
  741. {
  742. #if IS_USE_READMSG_CS
  743. EnterCriticalSection(&m_csReadMsg);
  744. #endif
  745. memcpy(m_szUhk_Q4FMsg,pBuff,sizeof(m_szUhk_Q4FMsg));
  746. #if IS_USE_READMSG_CS
  747. LeaveCriticalSection(&m_csReadMsg);
  748. #endif
  749. }
  750. }
  751. void CUpsUhk31::SetUhkQ50VarMsg(char szCmd[MAX_CMD], char *pBuff)
  752. {
  753. if (strcmp(szCmd, "cmd-75") == 0)
  754. {
  755. #if IS_USE_READMSG_CS
  756. EnterCriticalSection(&m_csReadMsg);
  757. #endif
  758. memcpy(m_szUhk_Q50Msg,pBuff,sizeof(m_szUhk_Q50Msg));
  759. #if IS_USE_READMSG_CS
  760. LeaveCriticalSection(&m_csReadMsg);
  761. #endif
  762. }
  763. }
  764. void CUpsUhk31::SimulationCommData(void)
  765. {
  766. /*获取模拟量量化数据浮点数*/
  767. TRACE("UhkResponseStatus赋值\n");
  768. // 7E 32 31 30 30 32 41 30 30 37
  769. // 30 39 30 30 30 36 36 36 36 36
  770. // 44 34 33 36 36 36 36 36 44 34
  771. // 33 36 36 36 36 37 30 34 33 36
  772. // 36 36 36 35 43 34 33 20 20 20
  773. // 20 20 20 20 20 20 20 20 20 20
  774. // 20 20 20 43 44 43 43 34 43 34
  775. // 30 20 20 20 20 20 20 20 20 20
  776. // 20 20 20 20 20 20 20 39 41 31
  777. // 39 38 36 34 33 37 42 31 34 34
  778. // 38 34 32 30 30 30 30 30 36 37
  779. // 42 31 34 34 38 34 32 30 30 30
  780. // 30 30 30 34 31 30 30 30 30 43
  781. // 38 34 32 34 38 45 31 44 41 34
  782. // 31 36 36 45 36 36 41 34 33 30
  783. // 30 38 30 38 36 34 33 45 31 46
  784. // 30 0D
  785. m_szUhk_Q41Msg[0] = 0x7E;
  786. m_szUhk_Q41Msg[1] = 0x32;
  787. m_szUhk_Q41Msg[2] = 0x31;
  788. m_szUhk_Q41Msg[3] = 0x30;
  789. m_szUhk_Q41Msg[4] = 0x30;
  790. m_szUhk_Q41Msg[5] = 0x32;
  791. m_szUhk_Q41Msg[6] = 0x41;
  792. m_szUhk_Q41Msg[7] = 0x30;
  793. m_szUhk_Q41Msg[8] = 0x30;
  794. m_szUhk_Q41Msg[9] = 0x37;
  795. m_szUhk_Q41Msg[10] = 0x30;
  796. m_szUhk_Q41Msg[11] = 0x39;
  797. m_szUhk_Q41Msg[12] = 0x30;
  798. m_szUhk_Q41Msg[13] = 0x30;
  799. m_szUhk_Q41Msg[14] = 0x30;
  800. m_szUhk_Q41Msg[15] = 0x36;
  801. m_szUhk_Q41Msg[16] = 0x36;
  802. m_szUhk_Q41Msg[17] = 0x36;
  803. m_szUhk_Q41Msg[18] = 0x36;
  804. m_szUhk_Q41Msg[19] = 0x36;
  805. //44 34 33 36 36 36 36 36 44 34
  806. m_szUhk_Q41Msg[20] = 0x44;
  807. m_szUhk_Q41Msg[21] = 0x34;
  808. m_szUhk_Q41Msg[22] = 0x33;
  809. m_szUhk_Q41Msg[23] = 0x36;
  810. m_szUhk_Q41Msg[24] = 0x36;
  811. m_szUhk_Q41Msg[25] = 0x36;
  812. m_szUhk_Q41Msg[26] = 0x36;
  813. m_szUhk_Q41Msg[27] = 0x36;
  814. m_szUhk_Q41Msg[28] = 0x44;
  815. m_szUhk_Q41Msg[29] = 0x34;
  816. //33 36 36 36 36 37 30 34 33 36
  817. m_szUhk_Q41Msg[30] = 0x33;
  818. m_szUhk_Q41Msg[31] = 0x36;
  819. m_szUhk_Q41Msg[32] = 0x36;
  820. m_szUhk_Q41Msg[33] = 0x36;
  821. m_szUhk_Q41Msg[34] = 0x36;
  822. m_szUhk_Q41Msg[35] = 0x37;
  823. m_szUhk_Q41Msg[36] = 0x30;
  824. m_szUhk_Q41Msg[37] = 0x34;
  825. m_szUhk_Q41Msg[38] = 0x33;
  826. m_szUhk_Q41Msg[39] = 0x36;
  827. //36 36 36 35 43 34 33 20 20 20
  828. m_szUhk_Q41Msg[40] = 0x36;
  829. m_szUhk_Q41Msg[41] = 0x36;
  830. m_szUhk_Q41Msg[42] = 0x36;
  831. m_szUhk_Q41Msg[43] = 0x35;
  832. m_szUhk_Q41Msg[44] = 0x43;
  833. m_szUhk_Q41Msg[45] = 0x34;
  834. m_szUhk_Q41Msg[46] = 0x33;
  835. m_szUhk_Q41Msg[47] = 0x20;
  836. m_szUhk_Q41Msg[48] = 0x20;
  837. m_szUhk_Q41Msg[49] = 0x20;
  838. //20 20 20 20 20 20 20 20 20 20
  839. m_szUhk_Q41Msg[50] = 0x20;
  840. m_szUhk_Q41Msg[51] = 0x20;
  841. m_szUhk_Q41Msg[52] = 0x20;
  842. m_szUhk_Q41Msg[53] = 0x20;
  843. m_szUhk_Q41Msg[54] = 0x20;
  844. m_szUhk_Q41Msg[55] = 0x20;
  845. m_szUhk_Q41Msg[56] = 0x20;
  846. m_szUhk_Q41Msg[57] = 0x20;
  847. m_szUhk_Q41Msg[58] = 0x20;
  848. m_szUhk_Q41Msg[59] = 0x20;
  849. //20 20 20 30 30 30 30 36 30 34
  850. m_szUhk_Q41Msg[60] = 0x20;
  851. m_szUhk_Q41Msg[61] = 0x20;
  852. m_szUhk_Q41Msg[62] = 0x20;
  853. m_szUhk_Q41Msg[63] = 0x30;
  854. m_szUhk_Q41Msg[64] = 0x30;
  855. m_szUhk_Q41Msg[65] = 0x30;
  856. m_szUhk_Q41Msg[66] = 0x30;
  857. m_szUhk_Q41Msg[67] = 0x36;
  858. m_szUhk_Q41Msg[68] = 0x30;
  859. m_szUhk_Q41Msg[69] = 0x34;
  860. // 30 20 20 20 20 20 20 20 20 20
  861. m_szUhk_Q41Msg[70] = 0x30;
  862. m_szUhk_Q41Msg[71] = 0x20;
  863. m_szUhk_Q41Msg[72] = 0x20;
  864. m_szUhk_Q41Msg[73] = 0x20;
  865. m_szUhk_Q41Msg[74] = 0x20;
  866. m_szUhk_Q41Msg[75] = 0x20;
  867. m_szUhk_Q41Msg[76] = 0x20;
  868. m_szUhk_Q41Msg[77] = 0x20;
  869. m_szUhk_Q41Msg[78] = 0x20;
  870. m_szUhk_Q41Msg[79] = 0x20;
  871. //20 20 20 20 20 20 20 39 41 31
  872. m_szUhk_Q41Msg[80] = 0x20;
  873. m_szUhk_Q41Msg[81] = 0x20;
  874. m_szUhk_Q41Msg[82] = 0x20;
  875. m_szUhk_Q41Msg[83] = 0x20;
  876. m_szUhk_Q41Msg[84] = 0x20;
  877. m_szUhk_Q41Msg[85] = 0x20;
  878. m_szUhk_Q41Msg[86] = 0x20;
  879. m_szUhk_Q41Msg[87] = 0x39;
  880. m_szUhk_Q41Msg[88] = 0x41;
  881. m_szUhk_Q41Msg[89] = 0x31;
  882. //39 38 36 34 33 33 44 31 34 34
  883. m_szUhk_Q41Msg[90] = 0x39;
  884. m_szUhk_Q41Msg[91] = 0x38;
  885. m_szUhk_Q41Msg[92] = 0x36;
  886. m_szUhk_Q41Msg[93] = 0x34;
  887. m_szUhk_Q41Msg[94] = 0x33;
  888. m_szUhk_Q41Msg[95] = 0x33;
  889. m_szUhk_Q41Msg[96] = 0x44;
  890. m_szUhk_Q41Msg[97] = 0x30;
  891. m_szUhk_Q41Msg[98] = 0x41;
  892. m_szUhk_Q41Msg[99] = 0x34;
  893. //38 34 32 30 30 30 30 30 36 37
  894. m_szUhk_Q41Msg[100] = 0x38;
  895. m_szUhk_Q41Msg[101] = 0x34;
  896. m_szUhk_Q41Msg[102] = 0x32;
  897. m_szUhk_Q41Msg[103] = 0x30;
  898. m_szUhk_Q41Msg[104] = 0x30;
  899. m_szUhk_Q41Msg[105] = 0x30;
  900. m_szUhk_Q41Msg[106] = 0x30;
  901. m_szUhk_Q41Msg[107] = 0x30;
  902. m_szUhk_Q41Msg[108] = 0x36;
  903. m_szUhk_Q41Msg[109] = 0x37;
  904. // 42 31 34 34 38 34 32 30 30 30
  905. m_szUhk_Q41Msg[110] = 0x42;
  906. m_szUhk_Q41Msg[111] = 0x31;
  907. m_szUhk_Q41Msg[112] = 0x34;
  908. m_szUhk_Q41Msg[113] = 0x34;
  909. m_szUhk_Q41Msg[114] = 0x38;
  910. m_szUhk_Q41Msg[115] = 0x34;
  911. m_szUhk_Q41Msg[116] = 0x32;
  912. m_szUhk_Q41Msg[117] = 0x30;
  913. m_szUhk_Q41Msg[118] = 0x30;
  914. m_szUhk_Q41Msg[119] = 0x30;
  915. //30 30 30 34 31 30 30 30 30 43
  916. m_szUhk_Q41Msg[120] = 0X30;
  917. m_szUhk_Q41Msg[121] = 0x30;
  918. m_szUhk_Q41Msg[122] = 0x30;
  919. m_szUhk_Q41Msg[123] = 0x34;
  920. m_szUhk_Q41Msg[124] = 0x31;
  921. m_szUhk_Q41Msg[125] = 0x30;
  922. m_szUhk_Q41Msg[126] = 0x30;
  923. m_szUhk_Q41Msg[127] = 0x30;
  924. m_szUhk_Q41Msg[128] = 0x30;
  925. m_szUhk_Q41Msg[129] = 0x43;
  926. //38 34 32 34 38 45 31 44 41 34
  927. m_szUhk_Q41Msg[130] = 0x38;
  928. m_szUhk_Q41Msg[131] = 0x34;
  929. m_szUhk_Q41Msg[132] = 0x32;
  930. m_szUhk_Q41Msg[133] = 0x34;
  931. m_szUhk_Q41Msg[134] = 0x38;
  932. m_szUhk_Q41Msg[135] = 0x45;
  933. m_szUhk_Q41Msg[136] = 0x31;
  934. m_szUhk_Q41Msg[137] = 0x44;
  935. m_szUhk_Q41Msg[138] = 0x41;
  936. m_szUhk_Q41Msg[139] = 0x34;
  937. //31 36 36 45 36 36 41 34 33 30
  938. m_szUhk_Q41Msg[140] = 0x31;
  939. m_szUhk_Q41Msg[141] = 0x39;
  940. m_szUhk_Q41Msg[142] = 0x41;
  941. m_szUhk_Q41Msg[143] = 0x39;
  942. m_szUhk_Q41Msg[144] = 0x39;
  943. m_szUhk_Q41Msg[145] = 0x36;
  944. m_szUhk_Q41Msg[146] = 0x42;
  945. m_szUhk_Q41Msg[147] = 0x34;
  946. m_szUhk_Q41Msg[148] = 0x33;
  947. m_szUhk_Q41Msg[149] = 0x36;
  948. //30 38 30 38 36 34 33 45 31 46
  949. m_szUhk_Q41Msg[150] = 0x36;
  950. m_szUhk_Q41Msg[151] = 0x36;
  951. m_szUhk_Q41Msg[152] = 0x36;
  952. m_szUhk_Q41Msg[153] = 0x38;
  953. m_szUhk_Q41Msg[154] = 0x36;
  954. m_szUhk_Q41Msg[155] = 0x34;
  955. m_szUhk_Q41Msg[156] = 0x33;
  956. m_szUhk_Q41Msg[157] = 0x45;
  957. m_szUhk_Q41Msg[158] = 0x31;
  958. m_szUhk_Q41Msg[159] = 0x46;
  959. //30 0D
  960. m_szUhk_Q41Msg[160] = 0x30;
  961. m_szUhk_Q41Msg[161] = 0x0D;
  962. //7E 32 31 30 30 32 41 30 30 46
  963. //30 31 30 30 30 30 31 30 35 45
  964. //31 45 32 45 32 45 34 45 38 46
  965. //41 31 33 0D
  966. /*获取开关量输入状态*/
  967. // 7E 32 31 30 30 32 41 30 30 46
  968. m_szUhk_Q43Msg[0] = 0x7E;
  969. m_szUhk_Q43Msg[1] = 0x32;
  970. m_szUhk_Q43Msg[2] = 0x31;
  971. m_szUhk_Q43Msg[3] = 0x30;
  972. m_szUhk_Q43Msg[4] = 0x30;
  973. m_szUhk_Q43Msg[5] = 0x32;
  974. m_szUhk_Q43Msg[6] = 0x41;
  975. m_szUhk_Q43Msg[7] = 0x30;
  976. m_szUhk_Q43Msg[8] = 0x30;
  977. m_szUhk_Q43Msg[9] = 0x46;
  978. // 30 31 30 30 30 30 31 30 35 45
  979. m_szUhk_Q43Msg[10] = 0x30;
  980. m_szUhk_Q43Msg[11] = 0x31;
  981. m_szUhk_Q43Msg[12] = 0x30;
  982. m_szUhk_Q43Msg[13] = 0x30;
  983. m_szUhk_Q43Msg[14] = 0x30;
  984. m_szUhk_Q43Msg[15] = 0x30;
  985. m_szUhk_Q43Msg[16] = 0x31;
  986. m_szUhk_Q43Msg[17] = 0x30;
  987. m_szUhk_Q43Msg[18] = 0x35;
  988. m_szUhk_Q43Msg[19] = 0x45;
  989. // 31 45 32 45 32 45 34 45 38 46
  990. m_szUhk_Q43Msg[20] = 0x31;
  991. m_szUhk_Q43Msg[21] = 0x45;
  992. m_szUhk_Q43Msg[22] = 0x32;
  993. m_szUhk_Q43Msg[23] = 0x45;
  994. m_szUhk_Q43Msg[24] = 0x32;
  995. m_szUhk_Q43Msg[25] = 0x45;
  996. m_szUhk_Q43Msg[26] = 0x34;
  997. m_szUhk_Q43Msg[27] = 0x45;
  998. m_szUhk_Q43Msg[28] = 0x38;
  999. m_szUhk_Q43Msg[29] = 0x46;
  1000. // 41 31 33 0D
  1001. m_szUhk_Q43Msg[30] = 0x41;
  1002. m_szUhk_Q43Msg[31] = 0x31;
  1003. m_szUhk_Q43Msg[32] = 0x33;
  1004. m_szUhk_Q43Msg[33] = 0x0D;
  1005. /*获取告警状态*/
  1006. // 7E 32 31 30 30 32 41 30 30 38
  1007. // 30 32 36 30 30 30 30 30 30 30
  1008. // 30 30 30 30 30 30 30 30 30 30
  1009. // 41 30 30 30 30 30 30 30 30 30
  1010. // 30 30 30 30 30 30 30 30 30 30
  1011. // 30 46 36 36 39 0D
  1012. m_szUhk_Q44Msg[0] = 0x7E;
  1013. m_szUhk_Q44Msg[1] = 0x32;
  1014. m_szUhk_Q44Msg[2] = 0x31;
  1015. m_szUhk_Q44Msg[3] = 0x30;
  1016. m_szUhk_Q44Msg[4] = 0x30;
  1017. m_szUhk_Q44Msg[5] = 0x32;
  1018. m_szUhk_Q44Msg[6] = 0x41;
  1019. m_szUhk_Q44Msg[7] = 0x30;
  1020. m_szUhk_Q44Msg[8] = 0x30;
  1021. m_szUhk_Q44Msg[9] = 0x38;
  1022. // 30 32 36 30 30 30 30 30 30 30
  1023. m_szUhk_Q44Msg[10] = 0x30;
  1024. m_szUhk_Q44Msg[11] = 0x32;
  1025. m_szUhk_Q44Msg[12] = 0x36;
  1026. m_szUhk_Q44Msg[13] = 0x30;
  1027. m_szUhk_Q44Msg[14] = 0x30;
  1028. m_szUhk_Q44Msg[15] = 0x30;
  1029. m_szUhk_Q44Msg[16] = 0x30;
  1030. m_szUhk_Q44Msg[17] = 0x30;
  1031. m_szUhk_Q44Msg[18] = 0x30;
  1032. m_szUhk_Q44Msg[19] = 0x30;
  1033. // 30 30 30 30 30 30 30 30 30 30
  1034. m_szUhk_Q44Msg[20] = 0x30;
  1035. m_szUhk_Q44Msg[21] = 0x30;
  1036. m_szUhk_Q44Msg[22] = 0x30;
  1037. m_szUhk_Q44Msg[23] = 0x30;
  1038. m_szUhk_Q44Msg[24] = 0x30;
  1039. m_szUhk_Q44Msg[25] = 0x30;
  1040. m_szUhk_Q44Msg[26] = 0x30;
  1041. m_szUhk_Q44Msg[27] = 0x30;
  1042. m_szUhk_Q44Msg[28] = 0x30;
  1043. m_szUhk_Q44Msg[29] = 0x30;
  1044. // 41 30 30 30 30 30 30 30 30 30
  1045. m_szUhk_Q44Msg[30] = 0x41;
  1046. m_szUhk_Q44Msg[31] = 0x30;
  1047. m_szUhk_Q44Msg[32] = 0x30;
  1048. m_szUhk_Q44Msg[33] = 0x30;
  1049. m_szUhk_Q44Msg[34] = 0x30;
  1050. m_szUhk_Q44Msg[35] = 0x30;
  1051. m_szUhk_Q44Msg[36] = 0x30;
  1052. m_szUhk_Q44Msg[37] = 0x30;
  1053. m_szUhk_Q44Msg[38] = 0x30;
  1054. m_szUhk_Q44Msg[39] = 0x30;
  1055. // 30 30 30 30 30 30 30 30 30 30
  1056. m_szUhk_Q44Msg[40] = 0x30;
  1057. m_szUhk_Q44Msg[41] = 0x30;
  1058. m_szUhk_Q44Msg[42] = 0x30;
  1059. m_szUhk_Q44Msg[43] = 0x30;
  1060. m_szUhk_Q44Msg[44] = 0x30;
  1061. m_szUhk_Q44Msg[45] = 0x30;
  1062. m_szUhk_Q44Msg[46] = 0x30;
  1063. m_szUhk_Q44Msg[47] = 0x30;
  1064. m_szUhk_Q44Msg[48] = 0x30;
  1065. m_szUhk_Q44Msg[49] = 0x30;
  1066. // 30 46 36 36 39 0D
  1067. m_szUhk_Q44Msg[50] = 0x30;
  1068. m_szUhk_Q44Msg[51] = 0x46;
  1069. m_szUhk_Q44Msg[52] = 0x36;
  1070. m_szUhk_Q44Msg[53] = 0x36;
  1071. m_szUhk_Q44Msg[54] = 0x39;
  1072. m_szUhk_Q44Msg[55] = 0x0D;
  1073. /*获取系统参数*/
  1074. // 7E 32 31 30 30 32 41 30 30 30
  1075. m_szUhk_Q46Msg[0] = 0x7E;
  1076. m_szUhk_Q46Msg[1] = 0x32;
  1077. m_szUhk_Q46Msg[2] = 0x31;
  1078. m_szUhk_Q46Msg[3] = 0x30;
  1079. m_szUhk_Q46Msg[4] = 0x30;
  1080. m_szUhk_Q46Msg[5] = 0x32;
  1081. m_szUhk_Q46Msg[6] = 0x41;
  1082. m_szUhk_Q46Msg[7] = 0x30;
  1083. m_szUhk_Q46Msg[8] = 0x30;
  1084. m_szUhk_Q46Msg[9] = 0x30;
  1085. // 30 36 41 20 20 20 20 20 20 20
  1086. m_szUhk_Q46Msg[10] = 0x30;
  1087. m_szUhk_Q46Msg[11] = 0x36;
  1088. m_szUhk_Q46Msg[12] = 0x41;
  1089. m_szUhk_Q46Msg[13] = 0x20;
  1090. m_szUhk_Q46Msg[14] = 0X20;
  1091. m_szUhk_Q46Msg[15] = 0x20;
  1092. m_szUhk_Q46Msg[16] = 0x20;
  1093. m_szUhk_Q46Msg[17] = 0x20;
  1094. m_szUhk_Q46Msg[18] = 0x20;
  1095. m_szUhk_Q46Msg[19] = 0x20;
  1096. // 20 20 20 20 20 20 20 20 20 20
  1097. m_szUhk_Q46Msg[20] = 0x20;
  1098. m_szUhk_Q46Msg[21] = 0x20;
  1099. m_szUhk_Q46Msg[22] = 0x20;
  1100. m_szUhk_Q46Msg[23] = 0x20;
  1101. m_szUhk_Q46Msg[24] = 0x20;
  1102. m_szUhk_Q46Msg[25] = 0x20;
  1103. m_szUhk_Q46Msg[26] = 0x20;
  1104. m_szUhk_Q46Msg[27] = 0x20;
  1105. m_szUhk_Q46Msg[28] = 0x20;
  1106. m_szUhk_Q46Msg[29] = 0x20;
  1107. // 20 20 20 20 20 20 20 20 20 20
  1108. m_szUhk_Q46Msg[30] = 0x20;
  1109. m_szUhk_Q46Msg[31] = 0x20;
  1110. m_szUhk_Q46Msg[32] = 0x20;
  1111. m_szUhk_Q46Msg[33] = 0x20;
  1112. m_szUhk_Q46Msg[34] = 0x20;
  1113. m_szUhk_Q46Msg[35] = 0x20;
  1114. m_szUhk_Q46Msg[36] = 0x20;
  1115. m_szUhk_Q46Msg[37] = 0x20;
  1116. m_szUhk_Q46Msg[38] = 0x20;
  1117. m_szUhk_Q46Msg[39] = 0x20;
  1118. // 20 20 20 20 20 30 39 30 30 30
  1119. m_szUhk_Q46Msg[40] = 0x20;
  1120. m_szUhk_Q46Msg[41] = 0x20;
  1121. m_szUhk_Q46Msg[42] = 0x20;
  1122. m_szUhk_Q46Msg[43] = 0x20;
  1123. m_szUhk_Q46Msg[44] = 0x20;
  1124. m_szUhk_Q46Msg[45] = 0x30;
  1125. m_szUhk_Q46Msg[46] = 0x39;
  1126. m_szUhk_Q46Msg[47] = 0x30;
  1127. m_szUhk_Q46Msg[48] = 0x30;
  1128. m_szUhk_Q46Msg[49] = 0x30;
  1129. // 30 41 30 34 30 30 30 30 30 46
  1130. m_szUhk_Q46Msg[50] = 0x30;
  1131. m_szUhk_Q46Msg[51] = 0x41;
  1132. m_szUhk_Q46Msg[52] = 0x30;
  1133. m_szUhk_Q46Msg[53] = 0x34;
  1134. m_szUhk_Q46Msg[54] = 0x30;
  1135. m_szUhk_Q46Msg[55] = 0x30;
  1136. m_szUhk_Q46Msg[56] = 0x30;
  1137. m_szUhk_Q46Msg[57] = 0x30;
  1138. m_szUhk_Q46Msg[58] = 0x30;
  1139. m_szUhk_Q46Msg[59] = 0x46;
  1140. // 30 34 32 30 30 30 30 32 30 34
  1141. m_szUhk_Q46Msg[60] = 0x30;
  1142. m_szUhk_Q46Msg[61] = 0x34;
  1143. m_szUhk_Q46Msg[62] = 0x32;
  1144. m_szUhk_Q46Msg[63] = 0x30;
  1145. m_szUhk_Q46Msg[64] = 0x30;
  1146. m_szUhk_Q46Msg[65] = 0x30;
  1147. m_szUhk_Q46Msg[66] = 0x30;
  1148. m_szUhk_Q46Msg[67] = 0x32;
  1149. m_szUhk_Q46Msg[68] = 0x30;
  1150. m_szUhk_Q46Msg[69] = 0x34;
  1151. // 31 30 30 30 30 30 30 34 30 30
  1152. m_szUhk_Q46Msg[70] = 0x31;
  1153. m_szUhk_Q46Msg[71] = 0x30;
  1154. m_szUhk_Q46Msg[72] = 0x30;
  1155. m_szUhk_Q46Msg[73] = 0x30;
  1156. m_szUhk_Q46Msg[74] = 0x30;
  1157. m_szUhk_Q46Msg[75] = 0x30;
  1158. m_szUhk_Q46Msg[76] = 0x30;
  1159. m_szUhk_Q46Msg[77] = 0x34;
  1160. m_szUhk_Q46Msg[78] = 0x30;
  1161. m_szUhk_Q46Msg[79] = 0x30;
  1162. // 30 30 30 30 30 34 30 30 30 30
  1163. m_szUhk_Q46Msg[80] = 0x30;
  1164. m_szUhk_Q46Msg[81] = 0x30;
  1165. m_szUhk_Q46Msg[82] = 0x30;
  1166. m_szUhk_Q46Msg[83] = 0x30;
  1167. m_szUhk_Q46Msg[84] = 0x30;
  1168. m_szUhk_Q46Msg[85] = 0x34;
  1169. m_szUhk_Q46Msg[86] = 0x30;
  1170. m_szUhk_Q46Msg[87] = 0x30;
  1171. m_szUhk_Q46Msg[88] = 0x30;
  1172. m_szUhk_Q46Msg[89] = 0x30;
  1173. // 30 38 30 33 46 30 30 30 30 45
  1174. m_szUhk_Q46Msg[90] = 0x30;
  1175. m_szUhk_Q46Msg[91] = 0x38;
  1176. m_szUhk_Q46Msg[92] = 0x30;
  1177. m_szUhk_Q46Msg[93] = 0x33;
  1178. m_szUhk_Q46Msg[94] = 0x46;
  1179. m_szUhk_Q46Msg[95] = 0x30;
  1180. m_szUhk_Q46Msg[96] = 0x30;
  1181. m_szUhk_Q46Msg[97] = 0x30;
  1182. m_szUhk_Q46Msg[98] = 0x30;
  1183. m_szUhk_Q46Msg[99] = 0x45;
  1184. // 30 34 30 30 30 30 30 38 30 33
  1185. m_szUhk_Q46Msg[100] = 0x30;
  1186. m_szUhk_Q46Msg[101] = 0x34;
  1187. m_szUhk_Q46Msg[102] = 0x30;
  1188. m_szUhk_Q46Msg[103] = 0x30;
  1189. m_szUhk_Q46Msg[104] = 0x30;
  1190. m_szUhk_Q46Msg[105] = 0x30;
  1191. m_szUhk_Q46Msg[106] = 0x30;
  1192. m_szUhk_Q46Msg[107] = 0x38;
  1193. m_szUhk_Q46Msg[108] = 0x30;
  1194. m_szUhk_Q46Msg[109] = 0x33;
  1195. // 46 30 30 30 30 38 30 34 30 45
  1196. m_szUhk_Q46Msg[110] = 0x46;
  1197. m_szUhk_Q46Msg[111] = 0x30;
  1198. m_szUhk_Q46Msg[112] = 0x30;
  1199. m_szUhk_Q46Msg[113] = 0x30;
  1200. m_szUhk_Q46Msg[114] = 0x30;
  1201. m_szUhk_Q46Msg[115] = 0x38;
  1202. m_szUhk_Q46Msg[116] = 0x30;
  1203. m_szUhk_Q46Msg[117] = 0x34;
  1204. m_szUhk_Q46Msg[118] = 0x30;
  1205. m_szUhk_Q46Msg[119] = 0x45;
  1206. // 42 30 33 0D
  1207. m_szUhk_Q46Msg[120] = 0x42;
  1208. m_szUhk_Q46Msg[121] = 0x30;
  1209. m_szUhk_Q46Msg[122] = 0x33;
  1210. m_szUhk_Q46Msg[123] = 0x0D;
  1211. }
  1212. int CUpsUhk31::LengthCheck(char szSendMsg[])
  1213. {
  1214. int len = (int)strlen(szSendMsg);
  1215. char buffer[5] = {0};
  1216. int j = 0;
  1217. for (int i = 9; i< 13; i++)
  1218. {
  1219. buffer[j++] = szSendMsg[i]; //取出检验位
  1220. }
  1221. buffer[j] ='0';
  1222. if(!ValiateLength(buffer)) // 相加模十六取反加一
  1223. {
  1224. return ERR_CODE_RTN_LCHKSUM_ERROR;
  1225. }
  1226. /*转换为十六进制*/
  1227. return 0;
  1228. }
  1229. BOOL CUpsUhk31::CheckCHKSUM(char szSendMsg[])
  1230. {
  1231. int j = 0;
  1232. char buf1[5] = {0};
  1233. char buf2[5] = {0};
  1234. char szbuf[5] = {0};
  1235. char chDest[5] = {0};
  1236. unsigned short nData = 0;
  1237. int len = (int)strlen(szSendMsg);
  1238. char *buffer = new char [len-2];
  1239. memset(buffer,0,sizeof(buffer));
  1240. for (int i = 1; i < len-5; i++)
  1241. {
  1242. buffer[j++] = szSendMsg[i];
  1243. }
  1244. buffer[j] = '\0';
  1245. for (j = 0; j < buffer[j] != '\0'; j ++)
  1246. {
  1247. nData += AsciiToBYTE(buffer[j]); //十进制相加
  1248. }
  1249. nData = ~nData +1; //取反加1 (有问题)
  1250. nData %= 65536;
  1251. //转换为16进制
  1252. sprintf(buf2,"%x",nData);
  1253. StrLower(buf2,chDest);
  1254. j = 0;
  1255. for (int i = len-5; i < len -1; i++)
  1256. {
  1257. buf1[j++] = szSendMsg[i];
  1258. }
  1259. buf1[j] = '\0';
  1260. StrLower(buf1,szbuf);
  1261. if (strcmp(szbuf,chDest) == 0)
  1262. {
  1263. delete [] buffer;
  1264. return TRUE;
  1265. }
  1266. delete [] buffer;
  1267. return FALSE;
  1268. }
  1269. BOOL CUpsUhk31::CheckRtn(char szMsg[], int len)
  1270. {
  1271. //int len = (int)strlen(szMsg);
  1272. char buffer[3] = {0};
  1273. int j = 0;
  1274. for (int i = 7; i < 9; i++)
  1275. {
  1276. buffer[j++] = szMsg[i];
  1277. }
  1278. buffer[j] = '\0';
  1279. if (strcmp(buffer,"00") == 0)
  1280. {
  1281. return 0;
  1282. }
  1283. else if (strcmp(buffer,"01") == 0)
  1284. {
  1285. return ERR_CODE_RTN_VER_ERROR;
  1286. }
  1287. else if (strcmp(buffer,"02") == 0)
  1288. {
  1289. return ERR_CODE_RTN_CHKSUM_ERROR;
  1290. }
  1291. else if (strcmp(buffer,"03") == 0)
  1292. {
  1293. return ERR_CODE_RTN_LCHKSUM_ERROR;
  1294. }
  1295. else if (strcmp(buffer,"04") == 0)
  1296. {
  1297. return ERR_CODE_RTN_CID_ERROR;
  1298. }
  1299. else if (strcmp(buffer,"05") == 0)
  1300. {
  1301. return ERR_CODE_RTN_COMMAND_FORMAT;
  1302. }
  1303. else if (strcmp(buffer,"06") == 0)
  1304. {
  1305. return ERR_CODE_RTN_INVALID_LIMIT;
  1306. }
  1307. else if (strcmp(buffer,"E0") == 0)
  1308. {
  1309. return ERR_CODE_RTN_OPERATE_FAIL;
  1310. }
  1311. else if (strcmp(buffer,"E1") == 0)
  1312. {
  1313. return ERR_CODE_RTN_EQUIT_FAIL;
  1314. }
  1315. else if (strcmp(buffer,"E3")==0 ||
  1316. strcmp(buffer,"E4")==0
  1317. )
  1318. {
  1319. return ERR_CODE_RTN_KEEP;
  1320. }
  1321. else if (strcmp(buffer, "E5")==0 ||
  1322. strcmp(buffer, "E6") == 0 ||
  1323. strcmp(buffer, "E7") == 0 ||
  1324. strcmp(buffer, "E8") == 0 ||
  1325. strcmp(buffer, "E9") == 0
  1326. )
  1327. {
  1328. return ERR_CODE_RTN_WATCH;
  1329. }
  1330. else if (strcmp(buffer,"EA") == 0 ||
  1331. strcmp(buffer, "EB") == 0 ||
  1332. strcmp(buffer, "EC") == 0 ||
  1333. strcmp(buffer, "ED") == 0 ||
  1334. strcmp(buffer, "EE") == 0 ||
  1335. strcmp(buffer, "EF") == 0
  1336. )
  1337. {
  1338. return ERR_CODE_RTN_ELECTICAL_SOURCE;
  1339. }
  1340. return -1;
  1341. }
  1342. int CUpsUhk31::UhkRequestWrStatus(char szSendMsg[])
  1343. {
  1344. return 0;
  1345. }
  1346. int CUpsUhk31::UhkResponseWrStatus(char szSendMsg[])
  1347. {
  1348. return 0;
  1349. }
  1350. int CUpsUhk31::StrLower(char *pSource, char *pDest)
  1351. {
  1352. int length, i;
  1353. length = (int)strlen(pSource);
  1354. for (i = 0; i < length; i++) {
  1355. if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
  1356. pDest[i] = _tolower(pSource[i]);
  1357. }
  1358. else
  1359. pDest[i] = pSource[i];
  1360. }
  1361. return 0;
  1362. }
  1363. BOOL CUpsUhk31::ValiateLength(char szChar[])
  1364. {
  1365. unsigned int nData = 0;
  1366. unsigned int nData1 =0;
  1367. unsigned short nDataLength = 0;
  1368. unsigned short nChar1;
  1369. nChar1 =AsciiToBYTE(szChar[1]) +
  1370. AsciiToBYTE(szChar[2]) +
  1371. AsciiToBYTE(szChar[3]);
  1372. nChar1 = (~nChar1) + 1;
  1373. nChar1 %=16;
  1374. nDataLength = AsciiToBYTE(szChar[0]);
  1375. if (nDataLength != nChar1)
  1376. {
  1377. return FALSE;
  1378. }
  1379. return TRUE;
  1380. }
  1381. int CUpsUhk31::SendSetReuest(
  1382. char szPath[MAX_PATH], // 程序所在路径
  1383. char szIniName[MAX_PATH], // 配置文件名称
  1384. int nCommPort, // 串行端口
  1385. int nAddr, // 设备地址
  1386. char szCmd[MAX_CMD], // 请求命令
  1387. char szMsg[VAR_MSG], // 响应的值
  1388. int nReversed1, // 预留整形参数1接口
  1389. int nReversed2, // 预留整形参数2接口
  1390. int nReversed3, // 预留整形参数3接口
  1391. int nReversed4, // 预留整形参数4接口
  1392. int nReversed5, // 预留整形参数5接口
  1393. float fReversed1, // 预留float参数1接口
  1394. float fReversed2, // 预留float参数2接口
  1395. float fReversed3, // 预留float参数3接口
  1396. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  1397. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  1398. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  1399. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  1400. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  1401. )
  1402. {
  1403. return 0;
  1404. }
  1405. UINT CUpsUhk31::GetCheckSum(char *pBuf, char chDest[5], int len)
  1406. {
  1407. WORD iSum = 0;
  1408. //unsigned char chCompliment[2] = {0};
  1409. for(int i=0; i<len; i++)//求和
  1410. {
  1411. //TRACE("%x\r\n", pBuf[i]);
  1412. iSum += pBuf[i];
  1413. }
  1414. WORD iCompliment = iSum;
  1415. iCompliment = ~iCompliment;//取反
  1416. iCompliment++;
  1417. //DigitToBinary(iCompliment, chDest, sizeof(chDest));
  1418. itoa(iCompliment, chDest, 16);
  1419. chDest[0] = lowercase2uppercase(chDest[0]);
  1420. chDest[1] = lowercase2uppercase(chDest[1]);
  1421. chDest[2] = lowercase2uppercase(chDest[2]);
  1422. chDest[3] = lowercase2uppercase(chDest[3]);
  1423. return atoi(chDest);
  1424. }