UpsLink.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. //////////////////////////////////////////////////////////////////////////////
  2. ////// //////
  3. ////// 文 件: UpsLink.cpp //////
  4. ////// 作 者: Suguobing //////
  5. ////// 创建时间: //////
  6. ////// 说 明: UPSLink协议 //////
  7. ////// //////
  8. ////// 修改时间:2010-05-10 //////
  9. ////// 修改说明:MostDevice新版本 //////
  10. ////// //////
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include "stdafx.h"
  13. #include "UpsLink.h"
  14. #include "CommProcess.h"
  15. CUpsLink::CUpsLink(
  16. char szPath[MAX_PATH],
  17. char szIniName[MAX_PATH],
  18. int nCommPort, int nAddr,
  19. int nRate, int nDataBit,
  20. int nStopBit, int nParity,
  21. int nInterval )
  22. {
  23. InitializeCriticalSection(&m_csReadFinished);
  24. InitializeCriticalSection(&m_csWrFinished);
  25. MTVERIFY(m_hSemComm = CreateEvent(NULL, TRUE, TRUE, 0));
  26. memset(m_szLink_XMsg, 0, sizeof(m_szLink_XMsg));
  27. memset(m_szLink_X1Msg, 0, sizeof(m_szLink_X1Msg));
  28. memset(m_szLink_X2Msg, 0, sizeof(m_szLink_X2Msg));
  29. memset(m_szLink_GMsg, 0, sizeof(m_szLink_GMsg));
  30. memset(m_szLink_gMsg, 0, sizeof(m_szLink_gMsg));
  31. memset(m_szLink_fMsg, 0, sizeof(m_szLink_fMsg));
  32. memset(m_szLink_9Msg, 0, sizeof(m_szLink_9Msg));
  33. memset(m_szLink_QMsg, 0, sizeof(m_szLink_QMsg));
  34. memset(m_szLink_X3Msg, 0, sizeof(m_szLink_X3Msg));
  35. memset(m_szLink_8Msg, 0, sizeof(m_szLink_8Msg));
  36. memset(m_szLink_jMsg, 0, sizeof(m_szLink_jMsg));
  37. memset(m_szLink_X5Msg, 0, sizeof(m_szLink_X5Msg));
  38. memset(m_szLink_X6Msg, 0, sizeof(m_szLink_X6Msg));
  39. memset(m_szLink_BMsg, 0, sizeof(m_szLink_BMsg));
  40. memset(m_szLink_CMsg, 0, sizeof(m_szLink_CMsg));
  41. memset(m_szLink_LMsg, 0, sizeof(m_szLink_LMsg));
  42. memset(m_szLink_MMsg, 0, sizeof(m_szLink_MMsg));
  43. memset(m_szLink_NMsg, 0, sizeof(m_szLink_NMsg));
  44. memset(m_szLink_OMsg, 0, sizeof(m_szLink_OMsg));
  45. memset(m_szLink_PMsg, 0, sizeof(m_szLink_PMsg));
  46. memset(m_szLink_tMsg, 0, sizeof(m_szLink_tMsg));
  47. memset(m_szLink_hMsg, 0, sizeof(m_szLink_hMsg));
  48. memset(m_szLink_XJMsg, 0, sizeof(m_szLink_XJMsg));
  49. memset(m_szLink_X7Msg, 0, sizeof(m_szLink_X7Msg));
  50. memset(m_szLink_X8Msg, 0, sizeof(m_szLink_X8Msg));
  51. m_devOnline = TRUE;
  52. m_dwOnlineTick = 0;
  53. }
  54. CUpsLink::~CUpsLink()
  55. {
  56. DeleteCriticalSection(& m_csReadFinished);
  57. DeleteCriticalSection(&m_csWrFinished);
  58. MTVERIFY(CloseHandle(m_hSemComm));
  59. CloseComm();
  60. }
  61. BOOL CUpsLink::UpsUpLinkOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  62. {
  63. BOOL bResult = FALSE;
  64. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  65. return bResult;
  66. }
  67. int CUpsLink::SendReadRequest(
  68. char szPath[MAX_PATH],
  69. char szIniName[MAX_PATH],
  70. int nCommPort,
  71. int nAddr,
  72. char szCmd[MAX_CMD],
  73. char szMsg[VAR_MSG],
  74. int nReversed1,
  75. int nReversed2,
  76. int nReversed3,
  77. int nReversed4,
  78. int nReversed5,
  79. float fReversed1,
  80. float fReversed2,
  81. float fReversed3,
  82. char szReversed1[MAX_RESERVED1],
  83. char szReversed2[MAX_RESERVED2],
  84. char szReversed3[MAX_RESERVED3],
  85. char szReversed4[MAX_RESERVED4],
  86. char szReversed5[MAX_RESERVED5]
  87. )
  88. {
  89. int nIndex = 0, nLen = 0;
  90. char szSendMsg[UPS_UHK_SEND_MSG] = {0};
  91. char szType[UPS_TYPE_LENGTH] = {0};
  92. int startBit = 0;
  93. int endBit = 0;
  94. GetUpLinkFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen,startBit,endBit);
  95. CCommProcess *pComm = FindComm(nCommPort);
  96. if( pComm == NULL ) return -1;
  97. int nRet = -1;
  98. if( strlen(m_szLink_XMsg) == 0 || //获取系统模拟量量化数据(浮点数)
  99. strlen(m_szLink_X1Msg) == 0 || //UPS工作状态及传送顺序
  100. strlen(m_szLink_X2Msg) == 0 || //UPS告警内容及传送
  101. strlen(m_szLink_GMsg) == 0 || //获取系统参数(浮点数)
  102. strlen(m_szLink_gMsg) == 0 || //获取监测模块
  103. strlen(m_szLink_fMsg) == 0 || //获取监测模块
  104. strlen(m_szLink_9Msg) == 0 ||
  105. strlen(m_szLink_QMsg) == 0 ||
  106. strlen(m_szLink_X3Msg) == 0 ||
  107. strlen(m_szLink_8Msg) == 0 ||
  108. strlen(m_szLink_jMsg) == 0 ||
  109. strlen(m_szLink_X5Msg) == 0 ||
  110. strlen(m_szLink_X6Msg) == 0 ||
  111. strlen(m_szLink_BMsg) == 0 ||
  112. strlen(m_szLink_CMsg) == 0 ||
  113. strlen(m_szLink_XFMsg) == 0 ||
  114. strlen(m_szLink_LMsg) == 0 ||
  115. strlen(m_szLink_MMsg) == 0 ||
  116. strlen(m_szLink_NMsg) == 0 ||
  117. strlen(m_szLink_OMsg) == 0 ||
  118. strlen(m_szLink_PMsg) == 0 ||
  119. strlen(m_szLink_tMsg) == 0 ||
  120. strlen(m_szLink_hMsg) == 0 ||
  121. strlen(m_szLink_XJMsg) == 0 ||
  122. strlen(m_szLink_X7Msg) == 0 ||
  123. strlen(m_szLink_X8Msg) == 0 ||
  124. strcmp(szCmd, "cmd-1") == 0 ||
  125. strcmp(szCmd, "cmd-2") == 0 ||
  126. strcmp(szCmd, "cmd-3") == 0 ||
  127. strcmp(szCmd, "cmd-4") == 0 ||
  128. strcmp(szCmd, "cmd-5") == 0 ||
  129. strcmp(szCmd, "cmd-6") == 0 ||
  130. strcmp(szCmd, "cmd-7") == 0 ||
  131. strcmp(szCmd, "cmd-8") == 0 ||
  132. strcmp(szCmd, "cmd-15") == 0 ||
  133. strcmp(szCmd, "cmd-23") == 0 ||
  134. strcmp(szCmd, "cmd-31") == 0 ||
  135. strcmp(szCmd, "cmd-32") == 0 ||
  136. strcmp(szCmd, "cmd-33") == 0 ||
  137. strcmp(szCmd, "cmd-34") == 0 ||
  138. strcmp(szCmd, "cmd-35") == 0 ||
  139. strcmp(szCmd, "cmd-36") == 0 ||
  140. strcmp(szCmd, "cmd-37") == 0 ||
  141. strcmp(szCmd, "cmd-38") == 0 ||
  142. strcmp(szCmd, "cmd-39") == 0 ||
  143. strcmp(szCmd, "cmd-40") == 0 ||
  144. strcmp(szCmd, "cmd-41") == 0 ||
  145. strcmp(szCmd, "cmd-42") == 0 ||
  146. strcmp(szCmd, "cmd-43") == 0 ||
  147. strcmp(szCmd, "cmd-44") == 0 ||
  148. strcmp(szCmd, "cmd-52") == 0 ||
  149. strcmp(szCmd, "cmd-53") == 0 )
  150. {
  151. int nRet = GetDeviceParam( pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  152. if( nRet != 0 )
  153. {
  154. return nRet;
  155. }
  156. }
  157. if( GetTickCount() - m_dwOnlineTick > 60 *1000 && m_dwOnlineTick > 0 )
  158. {
  159. m_devOnline = FALSE;
  160. }
  161. else if( GetTickCount() - m_dwOnlineTick < 60 *1000 && m_dwOnlineTick > 0 )
  162. {
  163. m_devOnline = TRUE;
  164. }
  165. if( m_devOnline == FALSE )
  166. {
  167. return -1;
  168. }
  169. nRet = GetUpLinkXVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  170. nRet = GetUpLinkX1VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  171. nRet = GetUpLinkX2VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  172. nRet = GetUpLinkGVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  173. nRet = GetUpLinkgVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  174. nRet = GetUpLinkfVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  175. nRet = GetUpLink9VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  176. nRet = GetUpLinkQVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  177. nRet = GetUpLinkX3VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  178. nRet = GetUpLink8VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  179. nRet = GetUpLinkjVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  180. nRet = GetUpLinkX5VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  181. nRet = GetUpLinkX6VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  182. nRet = GetUpLinkBVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  183. nRet = GetUpLinkCVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  184. nRet = GetUpLinkXFVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  185. nRet = GetUpLinkLVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  186. nRet = GetUpLinkMVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  187. nRet = GetUpLinkNVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  188. nRet = GetUpLinkOVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  189. nRet = GetUpLinkPVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  190. nRet = GetUpLinktVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  191. nRet = GetUpLinkhVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  192. nRet = GetUpLinkXJVarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  193. nRet = GetUpLinkX7VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  194. nRet = GetUpLinkX8VarMsg(szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  195. return nRet;
  196. }
  197. int CUpsLink::GetUpLinkXVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit)
  198. {
  199. char *pSource = new char [nLen];
  200. int nRet = 0;
  201. if (strcmp(szCmd, "cmd-1") == 0 )
  202. {
  203. EnterCriticalSection(&m_csWrFinished);
  204. memcpy(pSource, m_szLink_XMsg + nIndex, nLen);
  205. //ConfirmChar(pSource,szMsg,szType,nLen, startBit, endBit);
  206. DataConversion(pSource, szMsg, szType, nLen, startBit, endBit);
  207. LeaveCriticalSection(&m_csWrFinished);
  208. nRet = 0;
  209. }
  210. delete [] pSource;
  211. return nRet;
  212. }
  213. int CUpsLink::GetUpLinkX1VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  214. {
  215. char *pSource = new char [nLen];
  216. int nRet = 0;
  217. if (strcmp(szCmd, "cmd-2") == 0 )
  218. {
  219. EnterCriticalSection(&m_csWrFinished);
  220. memcpy(pSource, m_szLink_X1Msg + nIndex, nLen);
  221. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  222. LeaveCriticalSection(&m_csWrFinished);
  223. nRet = 0;
  224. }
  225. delete [] pSource;
  226. return nRet;
  227. }
  228. int CUpsLink::GetUpLinkX2VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  229. {
  230. char *pSource = new char [nLen];
  231. int nRet = 0;
  232. if (strcmp(szCmd, "cmd-3") == 0 )
  233. {
  234. EnterCriticalSection(&m_csWrFinished);
  235. memcpy(pSource, m_szLink_X2Msg + nIndex, nLen);
  236. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  237. LeaveCriticalSection(&m_csWrFinished);
  238. nRet = 0;
  239. }
  240. delete [] pSource;
  241. return nRet;
  242. }
  243. int CUpsLink::GetUpLinkGVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  244. {
  245. char *pSource = new char [nLen];
  246. int nRet = 0;
  247. if (strcmp(szCmd, "cmd-4") == 0 )
  248. {
  249. EnterCriticalSection(&m_csWrFinished);
  250. memcpy(pSource, m_szLink_GMsg + nIndex, nLen);
  251. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  252. LeaveCriticalSection(&m_csWrFinished);
  253. nRet = 0;
  254. }
  255. delete [] pSource;
  256. return nRet;
  257. }
  258. int CUpsLink::GetUpLinkgVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  259. {
  260. char *pSource = new char [nLen];
  261. int nRet = 0;
  262. if (strcmp(szCmd, "cmd-5") == 0 )
  263. {
  264. EnterCriticalSection(&m_csWrFinished);
  265. memcpy(pSource, m_szLink_gMsg + nIndex, nLen);
  266. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  267. LeaveCriticalSection(&m_csWrFinished);
  268. nRet = 0;
  269. }
  270. delete [] pSource;
  271. return nRet;
  272. }
  273. int CUpsLink::GetUpLinkfVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  274. {
  275. char *pSource = new char [nLen];
  276. int nRet = 0;
  277. if (strcmp(szCmd, "cmd-6") == 0 )
  278. {
  279. memcpy(pSource, m_szLink_fMsg + nIndex, nLen);
  280. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  281. TRACE("szMsg = %s",szMsg);
  282. LeaveCriticalSection(&m_csWrFinished);
  283. nRet = 0;
  284. }
  285. delete [] pSource;
  286. return nRet;
  287. }
  288. int CUpsLink::GetUpLink9VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  289. {
  290. char *pSource = new char [nLen];
  291. int nRet = 0;
  292. if (strcmp(szCmd, "cmd-7") == 0 )
  293. {
  294. memcpy(pSource, m_szLink_9Msg + nIndex, nLen);
  295. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  296. LeaveCriticalSection(&m_csWrFinished);
  297. nRet = 0;
  298. }
  299. delete [] pSource;
  300. return nRet;
  301. }
  302. int CUpsLink::GetUpLinkQVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  303. {
  304. char *pSource = new char [nLen];
  305. int nRet = 0;
  306. if (strcmp(szCmd, "cmd-8") == 0 ||
  307. strcmp(szCmd, "cmd-9") == 0 ||
  308. strcmp(szCmd, "cmd-10") == 0 ||
  309. strcmp(szCmd, "cmd-11") == 0 ||
  310. strcmp(szCmd, "cmd-12") == 0 ||
  311. strcmp(szCmd, "cmd-13") == 0 ||
  312. strcmp(szCmd, "cmd-14") == 0 )
  313. {
  314. memcpy(pSource, m_szLink_QMsg + nIndex, nLen);
  315. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  316. LeaveCriticalSection(&m_csWrFinished);
  317. nRet = 0;
  318. }
  319. delete [] pSource;
  320. return nRet;
  321. }
  322. int CUpsLink::GetUpLinkX3VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  323. {
  324. char *pSource = new char [nLen];
  325. int nRet = 0;
  326. if (strcmp(szCmd, "cmd-15") == 0 ||
  327. strcmp(szCmd, "cmd-16") == 0 ||
  328. strcmp(szCmd, "cmd-17") == 0 ||
  329. strcmp(szCmd, "cmd-18") == 0 ||
  330. strcmp(szCmd, "cmd-19") == 0 ||
  331. strcmp(szCmd, "cmd-20") == 0 ||
  332. strcmp(szCmd, "cmd-21") == 0 ||
  333. strcmp(szCmd, "cmd-22") == 0 )
  334. {
  335. TRACE("EnterCriticalSection9 nIndex = %d,nLen = %d\n",nIndex,nLen);
  336. TRACE("EnterCriticalSection9 m_szLink_X3Msg =%s\n",m_szLink_X3Msg);
  337. memcpy(pSource, m_szLink_X3Msg + nIndex, nLen);
  338. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  339. TRACE("szMsg = %s",szMsg);
  340. LeaveCriticalSection(&m_csWrFinished);
  341. nRet = 0;
  342. }
  343. delete [] pSource;
  344. return nRet;
  345. }
  346. int CUpsLink::GetUpLink8VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  347. {
  348. char *pSource = new char [nLen];
  349. int nRet = 0;
  350. if (strcmp(szCmd, "cmd-23") == 0 ||
  351. strcmp(szCmd, "cmd-24") == 0 ||
  352. strcmp(szCmd, "cmd-25") == 0 ||
  353. strcmp(szCmd, "cmd-26") == 0 ||
  354. strcmp(szCmd, "cmd-27") == 0 ||
  355. strcmp(szCmd, "cmd-28") == 0 ||
  356. strcmp(szCmd, "cmd-29") == 0 ||
  357. strcmp(szCmd, "cmd-30") == 0 )
  358. {
  359. memcpy(pSource, m_szLink_8Msg + nIndex, nLen);
  360. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  361. LeaveCriticalSection(&m_csWrFinished);
  362. nRet = 0;
  363. }
  364. delete [] pSource;
  365. return nRet;
  366. }
  367. int CUpsLink::GetUpLinkjVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  368. {
  369. char *pSource = new char [nLen];
  370. int nRet = 0;
  371. if (strcmp(szCmd, "cmd-31") == 0 )
  372. {
  373. memcpy(pSource, m_szLink_jMsg + nIndex, nLen);
  374. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  375. LeaveCriticalSection(&m_csWrFinished);
  376. nRet = 0;
  377. }
  378. delete [] pSource;
  379. return nRet;
  380. }
  381. int CUpsLink::GetUpLinkX5VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  382. {
  383. char *pSource = new char [nLen];
  384. int nRet = 0;
  385. if (strcmp(szCmd, "cmd-32") == 0 )
  386. {
  387. memcpy(pSource, m_szLink_X5Msg + nIndex, nLen);
  388. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  389. LeaveCriticalSection(&m_csWrFinished);
  390. nRet = 0;
  391. }
  392. delete [] pSource;
  393. return nRet;
  394. }
  395. int CUpsLink::GetUpLinkX6VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  396. {
  397. char *pSource = new char [nLen];
  398. int nRet = 0;
  399. if (strcmp(szCmd, "cmd-33") == 0 )
  400. {
  401. memcpy(pSource, m_szLink_X6Msg + nIndex, nLen);
  402. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  403. LeaveCriticalSection(&m_csWrFinished);
  404. nRet = 0;
  405. }
  406. delete [] pSource;
  407. return nRet;
  408. }
  409. int CUpsLink::GetUpLinkBVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  410. {
  411. char *pSource = new char [nLen];
  412. int nRet = 0;
  413. if (strcmp(szCmd, "cmd-34") == 0 )
  414. {
  415. memcpy(pSource, m_szLink_BMsg + nIndex, nLen);
  416. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  417. LeaveCriticalSection(&m_csWrFinished);
  418. nRet = 0;
  419. }
  420. delete [] pSource;
  421. return nRet;
  422. }
  423. int CUpsLink::GetUpLinkCVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  424. {
  425. char *pSource = new char [nLen];
  426. int nRet = 0;
  427. if (strcmp(szCmd, "cmd-35") == 0 )
  428. {
  429. memcpy(pSource, m_szLink_CMsg + nIndex, nLen);
  430. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  431. LeaveCriticalSection(&m_csWrFinished);
  432. nRet = 0;
  433. }
  434. delete [] pSource;
  435. return nRet;
  436. }
  437. int CUpsLink::GetUpLinkXFVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  438. {
  439. char *pSource = new char [nLen];
  440. int nRet = 0;
  441. if (strcmp(szCmd, "cmd-36") == 0 )
  442. {
  443. memcpy(pSource, m_szLink_XFMsg + nIndex, nLen);
  444. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  445. LeaveCriticalSection(&m_csWrFinished);
  446. nRet = 0;
  447. }
  448. delete [] pSource;
  449. return nRet;
  450. }
  451. int CUpsLink::GetUpLinkLVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  452. {
  453. char *pSource = new char [nLen];
  454. int nRet = 0;
  455. if (strcmp(szCmd, "cmd-37") == 0 )
  456. {
  457. memcpy(pSource, m_szLink_LMsg + nIndex, nLen);
  458. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  459. LeaveCriticalSection(&m_csWrFinished);
  460. nRet = 0;
  461. }
  462. delete [] pSource;
  463. return nRet;
  464. }
  465. int CUpsLink::GetUpLinkMVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  466. {
  467. char *pSource = new char [nLen];
  468. int nRet = 0;
  469. if (strcmp(szCmd, "cmd-38") == 0 )
  470. {
  471. memcpy(pSource, m_szLink_MMsg + nIndex, nLen);
  472. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  473. LeaveCriticalSection(&m_csWrFinished);
  474. nRet = 0;
  475. }
  476. delete [] pSource;
  477. return nRet;
  478. }
  479. int CUpsLink::GetUpLinkNVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  480. {
  481. char *pSource = new char [nLen];
  482. int nRet = 0;
  483. if (strcmp(szCmd, "cmd-39") == 0 )
  484. {
  485. memcpy(pSource, m_szLink_NMsg + nIndex, nLen);
  486. DataConversion(pSource, szMsg, szType, nLen, startBit, endBit);
  487. LeaveCriticalSection(&m_csWrFinished);
  488. nRet = 0;
  489. }
  490. delete [] pSource;
  491. return nRet;
  492. }
  493. int CUpsLink::GetUpLinkOVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  494. {
  495. char *pSource = new char [nLen];
  496. int nRet = 0;
  497. if (strcmp(szCmd, "cmd-40") == 0 )
  498. {
  499. memcpy(pSource, m_szLink_OMsg + nIndex, nLen);
  500. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  501. LeaveCriticalSection(&m_csWrFinished);
  502. nRet = 0;
  503. }
  504. delete [] pSource;
  505. return nRet;
  506. }
  507. int CUpsLink::GetUpLinkPVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  508. {
  509. char *pSource = new char [nLen];
  510. int nRet = 0;
  511. if (strcmp(szCmd, "cmd-41") == 0 )
  512. {
  513. memcpy(pSource, m_szLink_PMsg + nIndex, nLen);
  514. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  515. LeaveCriticalSection(&m_csWrFinished);
  516. nRet = 0;
  517. }
  518. delete [] pSource;
  519. return nRet;
  520. }
  521. int CUpsLink::GetUpLinktVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  522. {
  523. char *pSource = new char [nLen];
  524. int nRet = 0;
  525. if (strcmp(szCmd, "cmd-42") == 0 )
  526. {
  527. memcpy(pSource, m_szLink_tMsg + nIndex, nLen);
  528. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  529. LeaveCriticalSection(&m_csWrFinished);
  530. nRet = 0;
  531. }
  532. delete [] pSource;
  533. return nRet;
  534. }
  535. int CUpsLink::GetUpLinkhVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  536. {
  537. char *pSource = new char [nLen];
  538. int nRet = 0;
  539. if (strcmp(szCmd, "cmd-43") == 0 )
  540. {
  541. memcpy(pSource, m_szLink_hMsg + nIndex, nLen);
  542. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  543. LeaveCriticalSection(&m_csWrFinished);
  544. nRet = 0;
  545. }
  546. delete [] pSource;
  547. return nRet;
  548. }
  549. int CUpsLink::GetUpLinkXJVarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  550. {
  551. char *pSource = new char [nLen];
  552. int nRet = 0;
  553. if (strcmp(szCmd, "cmd-44") == 0 ||
  554. strcmp(szCmd, "cmd-45") == 0 ||
  555. strcmp(szCmd, "cmd-46") == 0 ||
  556. strcmp(szCmd, "cmd-47") == 0 ||
  557. strcmp(szCmd, "cmd-48") == 0 ||
  558. strcmp(szCmd, "cmd-49") == 0 ||
  559. strcmp(szCmd, "cmd-50") == 0 ||
  560. strcmp(szCmd, "cmd-51") == 0 )
  561. {
  562. memcpy(pSource, m_szLink_XJMsg + nIndex, nLen);
  563. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  564. LeaveCriticalSection(&m_csWrFinished);
  565. nRet = 0;
  566. }
  567. delete [] pSource;
  568. return nRet;
  569. }
  570. int CUpsLink::GetUpLinkX7VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  571. {
  572. char *pSource = new char [nLen];
  573. int nRet = 0;
  574. if (strcmp(szCmd, "cmd-52") == 0)
  575. {
  576. memcpy(pSource, m_szLink_X7Msg + nIndex, nLen);
  577. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  578. LeaveCriticalSection(&m_csWrFinished);
  579. nRet = 0;
  580. }
  581. delete [] pSource;
  582. return nRet;
  583. }
  584. int CUpsLink::GetUpLinkX8VarMsg(char szCmd[MAX_CMD], char szMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH], int &startBit, int &endBit )
  585. {
  586. char *pSource = new char [nLen];
  587. int nRet = 0;
  588. if (strcmp(szCmd, "cmd-53") == 0)
  589. {
  590. memcpy(pSource, m_szLink_X8Msg + nIndex, nLen);
  591. DataConversion(szType, pSource, szMsg, nLen, startBit, endBit);
  592. LeaveCriticalSection(&m_csWrFinished);
  593. nRet = 0;
  594. }
  595. delete [] pSource;
  596. return nRet;
  597. }
  598. int CUpsLink::GetDeviceParam(CCommProcess *pComm, //串口对象指针
  599. char szSendMsg[UPS_UHK_SEND_MSG], //发送Buffer
  600. char szCmd[MAX_CMD], // 命令
  601. char szMsg[VAR_MSG], // 接收Buffer
  602. int &nIndex, // 变量索引,针对接收Buffer而言
  603. int &nLen, // 变量长度
  604. char szType[TYPE_LENGTH]) // 变量数据类型
  605. {
  606. int nRet = -1;
  607. nRet = RequestStatus(pComm, szSendMsg);
  608. if( nRet != 0 )
  609. {
  610. return nRet; // 串口忙
  611. }
  612. nRet = ResponseStatus(pComm, szCmd, szMsg, nIndex, nLen, szType);
  613. return nRet;
  614. }
  615. int CUpsLink::GetUpLinkFromIni(char szPath[MAX_PATH], //服务器程序所在目录
  616. char szIniName[MAX_PATH], //配置文件名
  617. char szCmd[MAX_CMD], //命令
  618. char szSanTakSendMsg[MAX_CMD], //发送Buffer
  619. char nType[MAX_CMD],
  620. int &nIndex,
  621. int &nLen,
  622. int &startBit,
  623. int &endBit)
  624. {
  625. CHAR szFile[MAX_PATH + 1] = "";
  626. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  627. GetPrivateProfileString(szCmd, "SendCmd", "", szSanTakSendMsg, sizeof(szSanTakSendMsg), szFile);
  628. GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
  629. nType[strlen(nType)] = '\0';
  630. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  631. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  632. if (strcmp(nType,"BIT") == 0)
  633. {
  634. startBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);
  635. endBit = GetPrivateProfileInt(szCmd, "Endbit", 0 ,szFile);
  636. }
  637. return 0;
  638. }
  639. int CUpsLink::RequestStatus(CCommProcess *pComm, char chSendMsg[UPS_UHK_SEND_MSG] )
  640. {
  641. #if DEBUG_LINK //开关量,用于测试模拟数据
  642. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 )
  643. {
  644. int nDatalen = (int)strlen(chSendMsg);
  645. ResetEvent(m_hSemComm);
  646. int nResult = pComm->Write((unsigned char *)chSendMsg, nDatalen);
  647. if (nResult == nDatalen)
  648. {
  649. }
  650. else
  651. {
  652. SetEvent(m_hSemComm);
  653. return EER_CODE_UPSKEHUA_COM_REGNUM;
  654. }
  655. }
  656. else
  657. {
  658. return ERR_CODE_UPSKEHUA_COM_BUSY; //串口忙
  659. }
  660. #endif
  661. return 0;
  662. }
  663. int CUpsLink::ResponseStatus(
  664. CCommProcess *pComm,
  665. char szCmd[MAX_CMD],
  666. char szMsg[VAR_MSG],
  667. int &nIndex,
  668. int &nLen,
  669. char szType[TYPE_LENGTH] )
  670. {
  671. #if DEBUG_LINK
  672. int nReceiveLen = 0;
  673. int nProcessLen = 0;
  674. int nReadLen = 0;
  675. char pBuff[20] = {0};
  676. memset(pBuff, 0 , nLen);
  677. nReadLen = pComm->Read((BYTE *)pBuff,nReceiveLen);
  678. if (nReadLen <= 0)
  679. {
  680. SetEvent(m_hSemComm);
  681. return ERR_CODE_UPSKEHUA_COM_READ_NO_DATA;
  682. }
  683. SetUpLinkXVarMsg(szCmd, pBuff);
  684. SetUpLinkX1VarMsg(szCmd, pBuff);
  685. SetUpLinkX2VarMsg(szCmd, pBuff);
  686. SetUpLinkGVarMsg(szCmd, pBuff);
  687. SetUpLinkgVarMsg(szCmd, pBuff);
  688. SetUpLinkfVarMsg(szCmd, pBuff);
  689. SetUpLink9VarMsg(szCmd, pBuff);
  690. SetUpLinkQVarMsg(szCmd, pBuff);
  691. SetUpLinkX3VarMsg(szCmd, pBuff);
  692. SetUpLink8VarMsg(szCmd, pBuff);
  693. SetUpLinkjVarMsg(szCmd, pBuff);
  694. SetUpLinkX5VarMsg(szCmd, pBuff);
  695. SetUpLinkX6VarMsg(szCmd, pBuff);
  696. SetUpLinkBVarMsg(szCmd, pBuff);
  697. SetUpLinkCVarMsg(szCmd, pBuff);
  698. SetUpLinkXFVarMsg(szCmd, pBuff);
  699. SetUpLinkLVarMsg(szCmd, pBuff);
  700. SetUpLinkMVarMsg(szCmd, pBuff);
  701. SetUpLinkNVarMsg(szCmd, pBuff);
  702. SetUpLinkOVarMsg(szCmd, pBuff);
  703. SetUpLinkPVarMsg(szCmd, pBuff);
  704. SetUpLinktVarMsg(szCmd, pBuff);
  705. SetUpLinkhVarMsg(szCmd, pBuff);
  706. SetUpLinkXJVarMsg(szCmd, pBuff);
  707. SetUpLinkX7VarMsg(szCmd, pBuff);
  708. SetUpLinkX8VarMsg(szCmd, pBuff);
  709. m_dwOnlineTick[nAddr - 1] = GetTickCount();
  710. // 设置串口等待事件为有信号
  711. SetEvent( m_hSemComm );
  712. #else
  713. SimulationCommData();
  714. #endif
  715. return 0;
  716. }
  717. void CUpsLink::SetUpLinkXVarMsg(char szCmd[MAX_CMD], char *pBuff)
  718. {
  719. if (strcmp(szCmd, "cmd-1") == 0 )
  720. {
  721. EnterCriticalSection(&m_csWrFinished);
  722. memcpy(m_szLink_XMsg, pBuff, sizeof(m_szLink_XMsg));
  723. LeaveCriticalSection(&m_csWrFinished);
  724. }
  725. }
  726. void CUpsLink::SetUpLinkX1VarMsg(char szCmd[MAX_CMD], char *pBuff)
  727. {
  728. if ( strcmp(szCmd, "cmd-2") == 0 )
  729. {
  730. EnterCriticalSection(&m_csWrFinished);
  731. memcpy(m_szLink_X1Msg,pBuff,sizeof(m_szLink_X1Msg));
  732. LeaveCriticalSection(&m_csWrFinished);
  733. }
  734. }
  735. void CUpsLink::SetUpLinkX2VarMsg(char szCmd[MAX_CMD], char *pBuff)
  736. {
  737. if ( strcmp(szCmd, "cmd-3") == 0 )
  738. {
  739. EnterCriticalSection(&m_csWrFinished);
  740. memcpy(m_szLink_X2Msg,pBuff,sizeof(m_szLink_X2Msg));
  741. LeaveCriticalSection(&m_csWrFinished);
  742. }
  743. }
  744. void CUpsLink::SetUpLinkGVarMsg(char szCmd[MAX_CMD], char *pBuff)
  745. {
  746. if ( strcmp(szCmd, "cmd-4") == 0 )
  747. {
  748. EnterCriticalSection(&m_csWrFinished);
  749. memcpy(m_szLink_GMsg,pBuff,sizeof(m_szLink_GMsg));
  750. LeaveCriticalSection(&m_csWrFinished);
  751. }
  752. }
  753. void CUpsLink::SetUpLinkgVarMsg(char szCmd[MAX_CMD], char *pBuff)
  754. {
  755. if ( strcmp(szCmd, "cmd-5") == 0 )
  756. {
  757. EnterCriticalSection(&m_csWrFinished);
  758. memcpy(m_szLink_GMsg,pBuff,sizeof(m_szLink_GMsg));
  759. LeaveCriticalSection(&m_csWrFinished);
  760. }
  761. }
  762. void CUpsLink::SetUpLinkfVarMsg(char szCmd[MAX_CMD], char *pBuff)
  763. {
  764. if ( strcmp(szCmd, "cmd-6") == 0 )
  765. {
  766. EnterCriticalSection(&m_csWrFinished);
  767. memcpy(m_szLink_fMsg,pBuff,sizeof(m_szLink_fMsg));
  768. LeaveCriticalSection(&m_csWrFinished);
  769. }
  770. }
  771. void CUpsLink::SetUpLink9VarMsg(char szCmd[MAX_CMD], char *pBuff)
  772. {
  773. if ( strcmp(szCmd, "cmd-7") == 0 )
  774. {
  775. EnterCriticalSection(&m_csWrFinished);
  776. memcpy(m_szLink_9Msg,pBuff,sizeof(m_szLink_9Msg));
  777. LeaveCriticalSection(&m_csWrFinished);
  778. }
  779. }
  780. void CUpsLink::SetUpLinkQVarMsg(char szCmd[MAX_CMD], char *pBuff)
  781. {
  782. if ( strcmp(szCmd, "cmd-8") == 0||
  783. strcmp(szCmd, "cmd-9") == 0 ||
  784. strcmp(szCmd, "cmd-10") == 0 ||
  785. strcmp(szCmd, "cmd-11") == 0 ||
  786. strcmp(szCmd, "cmd-12") == 0 ||
  787. strcmp(szCmd, "cmd-13") == 0 ||
  788. strcmp(szCmd, "cmd-14") == 0 )
  789. {
  790. EnterCriticalSection(&m_csWrFinished);
  791. memcpy(m_szLink_QMsg,pBuff,sizeof(m_szLink_QMsg));
  792. LeaveCriticalSection(&m_csWrFinished);
  793. }
  794. }
  795. void CUpsLink::SetUpLinkX3VarMsg(char szCmd[MAX_CMD], char *pBuff)
  796. {
  797. if ( strcmp(szCmd, "cmd-15") == 0 ||
  798. strcmp(szCmd, "cmd-16") == 0 ||
  799. strcmp(szCmd, "cmd-17") == 0 ||
  800. strcmp(szCmd, "cmd-18") == 0 ||
  801. strcmp(szCmd, "cmd-19") == 0 ||
  802. strcmp(szCmd, "cmd-20") == 0 ||
  803. strcmp(szCmd, "cmd-21") == 0 ||
  804. strcmp(szCmd, "cmd-22") == 0 )
  805. {
  806. EnterCriticalSection(&m_csWrFinished);
  807. memcpy(m_szLink_X3Msg,pBuff,sizeof(m_szLink_X3Msg));
  808. LeaveCriticalSection(&m_csWrFinished);
  809. }
  810. }
  811. void CUpsLink::SetUpLink8VarMsg(char szCmd[MAX_CMD], char *pBuff)
  812. {
  813. if ( strcmp(szCmd, "cmd-23") == 0 ||
  814. strcmp(szCmd, "cmd-24") == 0 ||
  815. strcmp(szCmd, "cmd-25") == 0 ||
  816. strcmp(szCmd, "cmd-26") == 0 ||
  817. strcmp(szCmd, "cmd-27") == 0 ||
  818. strcmp(szCmd, "cmd-28") == 0 ||
  819. strcmp(szCmd, "cmd-29") == 0 ||
  820. strcmp(szCmd, "cmd-30") == 0 )
  821. {
  822. EnterCriticalSection(&m_csWrFinished);
  823. memcpy(m_szLink_8Msg,pBuff,sizeof(m_szLink_8Msg));
  824. LeaveCriticalSection(&m_csWrFinished);
  825. }
  826. }
  827. void CUpsLink::SetUpLinkjVarMsg(char szCmd[MAX_CMD], char *pBuff)
  828. {
  829. if ( strcmp(szCmd, "cmd-31") == 0 )
  830. {
  831. EnterCriticalSection(&m_csWrFinished);
  832. memcpy(m_szLink_jMsg,pBuff,sizeof(m_szLink_jMsg));
  833. LeaveCriticalSection(&m_csWrFinished);
  834. }
  835. }
  836. void CUpsLink::SetUpLinkX5VarMsg(char szCmd[MAX_CMD], char *pBuff)
  837. {
  838. if ( strcmp(szCmd, "cmd-32") == 0 )
  839. {
  840. EnterCriticalSection(&m_csWrFinished);
  841. memcpy(m_szLink_X5Msg,pBuff,sizeof(m_szLink_X5Msg));
  842. LeaveCriticalSection(&m_csWrFinished);
  843. }
  844. }
  845. void CUpsLink::SetUpLinkX6VarMsg(char szCmd[MAX_CMD], char *pBuff)
  846. {
  847. if ( strcmp(szCmd, "cmd-33") == 0 )
  848. {
  849. EnterCriticalSection(&m_csWrFinished);
  850. memcpy(m_szLink_X6Msg,pBuff,sizeof(m_szLink_X6Msg));
  851. LeaveCriticalSection(&m_csWrFinished);
  852. }
  853. }
  854. void CUpsLink::SetUpLinkBVarMsg(char szCmd[MAX_CMD], char *pBuff)
  855. {
  856. if ( strcmp(szCmd, "cmd-34") == 0 )
  857. {
  858. EnterCriticalSection(&m_csWrFinished);
  859. memcpy(m_szLink_BMsg,pBuff,sizeof(m_szLink_BMsg));
  860. LeaveCriticalSection(&m_csWrFinished);
  861. }
  862. }
  863. void CUpsLink::SetUpLinkCVarMsg(char szCmd[MAX_CMD], char *pBuff)
  864. {
  865. if ( strcmp(szCmd, "cmd-35") == 0 )
  866. {
  867. EnterCriticalSection(&m_csWrFinished);
  868. memcpy(m_szLink_CMsg,pBuff,sizeof(m_szLink_CMsg));
  869. LeaveCriticalSection(&m_csWrFinished);
  870. }
  871. }
  872. void CUpsLink::SetUpLinkXFVarMsg(char szCmd[MAX_CMD], char *pBuff)
  873. {
  874. if ( strcmp(szCmd, "cmd-36") == 0 )
  875. {
  876. EnterCriticalSection(&m_csWrFinished);
  877. memcpy(m_szLink_XFMsg,pBuff,sizeof(m_szLink_XFMsg));
  878. LeaveCriticalSection(&m_csWrFinished);
  879. }
  880. }
  881. void CUpsLink::SetUpLinkLVarMsg(char szCmd[MAX_CMD], char *pBuff)
  882. {
  883. if ( strcmp(szCmd, "cmd-37") == 0 )
  884. {
  885. EnterCriticalSection(&m_csWrFinished);
  886. memcpy(m_szLink_LMsg,pBuff,sizeof(m_szLink_LMsg));
  887. LeaveCriticalSection(&m_csWrFinished);
  888. }
  889. }
  890. void CUpsLink::SetUpLinkMVarMsg(char szCmd[MAX_CMD], char *pBuff)
  891. {
  892. if ( strcmp(szCmd, "cmd-38") == 0 )
  893. {
  894. EnterCriticalSection(&m_csWrFinished);
  895. memcpy(m_szLink_MMsg,pBuff,sizeof(m_szLink_MMsg));
  896. LeaveCriticalSection(&m_csWrFinished);
  897. }
  898. }
  899. void CUpsLink::SetUpLinkNVarMsg(char szCmd[MAX_CMD], char *pBuff)
  900. {
  901. if ( strcmp(szCmd, "cmd-39") == 0 )
  902. {
  903. EnterCriticalSection(&m_csWrFinished);
  904. memcpy(m_szLink_NMsg,pBuff,sizeof(m_szLink_NMsg));
  905. LeaveCriticalSection(&m_csWrFinished);
  906. }
  907. }
  908. void CUpsLink::SetUpLinkOVarMsg(char szCmd[MAX_CMD], char *pBuff)
  909. {
  910. if ( strcmp(szCmd, "cmd-40") == 0 )
  911. {
  912. EnterCriticalSection(&m_csWrFinished);
  913. memcpy(m_szLink_OMsg,pBuff,sizeof(m_szLink_OMsg));
  914. LeaveCriticalSection(&m_csWrFinished);
  915. }
  916. }
  917. void CUpsLink::SetUpLinkPVarMsg(char szCmd[MAX_CMD], char *pBuff)
  918. {
  919. if ( strcmp(szCmd, "cmd-41") == 0 )
  920. {
  921. EnterCriticalSection(&m_csWrFinished);
  922. memcpy(m_szLink_PMsg,pBuff,sizeof(m_szLink_PMsg));
  923. LeaveCriticalSection(&m_csWrFinished);
  924. }
  925. }
  926. void CUpsLink::SetUpLinktVarMsg(char szCmd[MAX_CMD], char *pBuff)
  927. {
  928. if ( strcmp(szCmd, "cmd-42") == 0 )
  929. {
  930. EnterCriticalSection(&m_csWrFinished);
  931. memcpy(m_szLink_tMsg,pBuff,sizeof(m_szLink_tMsg));
  932. LeaveCriticalSection(&m_csWrFinished);
  933. }
  934. }
  935. void CUpsLink::SetUpLinkhVarMsg(char szCmd[MAX_CMD], char *pBuff)
  936. {
  937. if ( strcmp(szCmd, "cmd-43") == 0 )
  938. {
  939. EnterCriticalSection(&m_csWrFinished);
  940. memcpy(m_szLink_hMsg,pBuff,sizeof(m_szLink_hMsg));
  941. LeaveCriticalSection(&m_csWrFinished);
  942. }
  943. }
  944. void CUpsLink::SetUpLinkXJVarMsg(char szCmd[MAX_CMD], char *pBuff)
  945. {
  946. if ( strcmp(szCmd, "cmd-44") == 0 ||
  947. strcmp(szCmd, "cmd-45") == 0 ||
  948. strcmp(szCmd, "cmd-46") == 0 ||
  949. strcmp(szCmd, "cmd-47") == 0 ||
  950. strcmp(szCmd, "cmd-48") == 0 ||
  951. strcmp(szCmd, "cmd-49") == 0 ||
  952. strcmp(szCmd, "cmd-50") == 0 ||
  953. strcmp(szCmd, "cmd-51") == 0 )
  954. {
  955. EnterCriticalSection(&m_csWrFinished);
  956. memcpy(m_szLink_XJMsg,pBuff,sizeof(m_szLink_XJMsg));
  957. LeaveCriticalSection(&m_csWrFinished);
  958. }
  959. }
  960. void CUpsLink::SetUpLinkX7VarMsg(char szCmd[MAX_CMD], char *pBuff)
  961. {
  962. if ( strcmp(szCmd, "cmd-52") == 0)
  963. {
  964. EnterCriticalSection(&m_csWrFinished);
  965. memcpy(m_szLink_X7Msg,pBuff,sizeof(m_szLink_X7Msg));
  966. LeaveCriticalSection(&m_csWrFinished);
  967. }
  968. }
  969. void CUpsLink::SetUpLinkX8VarMsg(char szCmd[MAX_CMD], char *pBuff)
  970. {
  971. if ( strcmp(szCmd, "cmd-53") == 0)
  972. {
  973. EnterCriticalSection(&m_csWrFinished);
  974. memcpy(m_szLink_X8Msg,pBuff,sizeof(m_szLink_X8Msg));
  975. LeaveCriticalSection(&m_csWrFinished);
  976. }
  977. }
  978. void CUpsLink::SimulationCommData(void)
  979. {
  980. m_szLink_XMsg[0] = 0x34; //X
  981. m_szLink_XMsg[1] = 0x66; //X
  982. m_szLink_XMsg[2] = 0x34; //X
  983. m_szLink_XMsg[3] = 0x62; //X
  984. m_szLink_X1Msg[0] = 0x33; //$>
  985. m_szLink_X1Msg[1] = 0x30; //$>
  986. m_szLink_X1Msg[2] = 0x33; //$>
  987. m_szLink_X1Msg[3] = 0x30; //$>
  988. m_szLink_X1Msg[4] = 0x33; //$>
  989. m_szLink_X1Msg[5] = 0x32; //$>
  990. m_szLink_X1Msg[6] = 0x33; //$>
  991. m_szLink_X1Msg[7] = 0x32; //$>
  992. m_szLink_X2Msg[0] = 0x33; //$>
  993. m_szLink_X2Msg[1] = 0x30; //$>
  994. m_szLink_X2Msg[2] = 0x33; //$>
  995. m_szLink_X2Msg[3] = 0x30; //$>
  996. m_szLink_X2Msg[4] = 0x33; //$>
  997. m_szLink_X2Msg[5] = 0x32; //$>
  998. m_szLink_X2Msg[6] = 0x33; //$>
  999. m_szLink_X2Msg[7] = 0x32; //$>
  1000. m_szLink_GMsg[0] = 0x35; //G
  1001. m_szLink_GMsg[1] = 0x32;
  1002. m_szLink_gMsg[0] = 0x33; //$>
  1003. m_szLink_gMsg[1] = 0x30; //$>
  1004. m_szLink_gMsg[2] = 0x33; //$>
  1005. m_szLink_gMsg[3] = 0x32; //$>
  1006. m_szLink_gMsg[4] = 0x33; //$>
  1007. m_szLink_gMsg[5] = 0x32; //$>
  1008. m_szLink_gMsg[6] = 0x33; //$>
  1009. m_szLink_gMsg[7] = 0x30; //$>
  1010. }
  1011. int CUpsLink::UpRequestWrStatus(char szSendMsg[])
  1012. {
  1013. return 0;
  1014. }
  1015. int CUpsLink::UpResponseWrStatus(char szSendMsg[])
  1016. {
  1017. return 0;
  1018. }
  1019. int CUpsLink::StrLower(char *pSource, char *pDest)
  1020. {
  1021. int length, i;
  1022. length = (int)strlen(pSource);
  1023. for (i = 0; i < length; i++) {
  1024. if ((pSource[i] >= 'A') && (pSource[i] <= 'Z')){
  1025. pDest[i] = _tolower(pSource[i]);
  1026. }
  1027. else
  1028. pDest[i] = pSource[i];
  1029. }
  1030. return 0;
  1031. }
  1032. int CUpsLink::SendSetReuest(
  1033. char szPath[MAX_PATH], // 程序所在路径
  1034. char szIniName[MAX_PATH], // 配置文件名称
  1035. int nCommPort, // 串行端口
  1036. int nAddr, // 设备地址
  1037. char szCmd[MAX_CMD], // 请求命令
  1038. char szMsg[VAR_MSG], // 响应的值
  1039. int nReversed1, // 预留整形参数1接口
  1040. int nReversed2, // 预留整形参数2接口
  1041. int nReversed3, // 预留整形参数3接口
  1042. int nReversed4, // 预留整形参数4接口
  1043. int nReversed5, // 预留整形参数5接口
  1044. float fReversed1, // 预留float参数1接口
  1045. float fReversed2, // 预留float参数2接口
  1046. float fReversed3, // 预留float参数3接口
  1047. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  1048. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  1049. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  1050. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  1051. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  1052. )
  1053. {
  1054. return 0;
  1055. }