UL33.cpp 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. //////////////////////////////////////////////////////////////////////////////
  2. ////// //////
  3. ////// 文 件: UL33.cpp //////
  4. ////// 作 者: wangjianfeng //////
  5. ////// 创建时间: //////
  6. ////// 说 明: UL33协议 //////
  7. ////// //////
  8. ////// 修改时间:2010-05-11 //////
  9. ////// 修改说明:新版本 //////
  10. ////// //////
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include "stdafx.h"
  13. #include "CommProcess.h"
  14. #include "Global.h"
  15. #include "UL33.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[]=__FILE__;
  19. #define new DEBUG_NEW
  20. #endif
  21. //////////////////////////////////////////////////////////////////////
  22. // Construction/Destruction
  23. //////////////////////////////////////////////////////////////////////
  24. CUL33::CUL33(char *szPath,char *szIniName,int nCommPort,int nAddr,int nRate,int nDataBit,int nStopBit,int nParity,int nInterval)
  25. {
  26. #if IS_USE_READMSG_CS
  27. InitializeCriticalSection( &m_csReadMsg ); //初始化一个临界资源对象
  28. #endif
  29. MTVERIFY( m_hSemComm = CreateEvent( NULL, TRUE, TRUE, 0 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
  30. memset(m_szUL33_41Msg, 0, sizeof(m_szUL33_41Msg));
  31. memset(m_szUL33_43Msg, 0, sizeof(m_szUL33_43Msg));
  32. memset(m_szUL33_44Msg, 0, sizeof(m_szUL33_44Msg));
  33. memset(m_szUL33_C0Msg, 0, sizeof(m_szUL33_C0Msg));
  34. memset(m_szUL33_C1Msg, 0, sizeof(m_szUL33_C1Msg));
  35. memset(m_szUL33_C2Msg, 0, sizeof(m_szUL33_C2Msg));
  36. memset(m_szUL33_C3Msg, 0, sizeof(m_szUL33_C3Msg));
  37. memset(m_szUL33_C4Msg, 0, sizeof(m_szUL33_C4Msg));
  38. memset(m_szUL33_C7Msg, 0, sizeof(m_szUL33_C7Msg));
  39. memset(m_szUL33_C8Msg, 0, sizeof(m_szUL33_C8Msg));
  40. m_devOnline = TRUE;
  41. m_dwOnlineTick = 0;
  42. }
  43. CUL33::~CUL33()
  44. {
  45. #if IS_USE_READMSG_CS
  46. DeleteCriticalSection( &m_csReadMsg );
  47. #endif
  48. MTVERIFY( CloseHandle( m_hSemComm ) );
  49. CloseComm();
  50. }
  51. BOOL CUL33::UpsULOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  52. {
  53. BOOL bResult = FALSE;
  54. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  55. return bResult;
  56. }
  57. int CUL33::SendReadRequest(
  58. char szPath[MAX_PATH],
  59. char szIniName[MAX_PATH],
  60. int nCommPort,
  61. int nAddr,
  62. char szCmd[MAX_CMD],
  63. char szMsg[VAR_MSG],
  64. int nReversed1,
  65. int nReversed2,
  66. int nReversed3,
  67. int nReversed4,
  68. int nReversed5,
  69. float fReversed1,
  70. float fReversed2,
  71. float fReversed3,
  72. char szReversed1[MAX_RESERVED1],
  73. char szReversed2[MAX_RESERVED2],
  74. char szReversed3[MAX_RESERVED3],
  75. char szReversed4[MAX_RESERVED4],
  76. char szReversed5[MAX_RESERVED5]
  77. )
  78. {
  79. int nIndex = 0, nLen = 0;
  80. char szSendMsg[UL33_SEND_MSG] = {0};
  81. char szType[TYPE_LENGTH] = {0};
  82. GetULFromIni(szPath, szIniName, szCmd,szSendMsg, szType, nIndex, nLen);
  83. CCommProcess *pComm = FindComm(nCommPort);
  84. if( pComm == NULL ) return -1;
  85. int nRet = -1;
  86. if (
  87. (strlen(m_szUL33_41Msg) ==0 &&
  88. (
  89. strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
  90. strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ||
  91. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  92. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 ||
  93. strcmp(szCmd, "cmd-8") == 0 || strcmp(szCmd, "cmd-9") == 0 ||
  94. strcmp(szCmd, "cmd-10") == 0 || strcmp(szCmd, "cmd-11") == 0
  95. ) )
  96. ||
  97. (strlen(m_szUL33_C0Msg) ==0 &&
  98. (
  99. strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  100. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  101. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 ||
  102. strcmp(szCmd, "cmd-18") == 0
  103. ) )
  104. ||
  105. (strlen(m_szUL33_C1Msg) ==0 &&
  106. (
  107. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0||
  108. strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  109. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
  110. strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0
  111. ) )
  112. ||
  113. (strlen(m_szUL33_C2Msg) ==0 &&
  114. (
  115. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 ||
  116. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 ||
  117. strcmp(szCmd, "cmd-31") == 0
  118. ) )
  119. ||
  120. (strlen(m_szUL33_C3Msg) ==0 &&
  121. (
  122. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 ||
  123. strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  124. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  125. strcmp(szCmd, "cmd-38") == 0
  126. ) )
  127. ||
  128. (strlen(m_szUL33_43Msg) ==0 &&
  129. (
  130. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 ||
  131. strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 ||
  132. strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  133. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 ||
  134. strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 ||
  135. strcmp(szCmd, "cmd-52") == 0
  136. ) )
  137. ||
  138. (strlen(m_szUL33_44Msg) ==0 &&
  139. (
  140. strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  141. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 ||
  142. strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0
  143. ) )
  144. ||
  145. (strlen(m_szUL33_C7Msg) ==0 &&
  146. (
  147. strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  148. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  149. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 ||
  150. strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  151. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  152. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 ||
  153. strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 ||
  154. strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  155. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0 ||
  156. strcmp(szCmd, "cmd-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
  157. strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
  158. strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
  159. strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
  160. strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
  161. strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
  162. ) )
  163. ||
  164. (strlen(m_szUL33_C8Msg) ==0 &&
  165. (
  166. strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
  167. strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
  168. strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
  169. strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
  170. strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
  171. ) )
  172. ||
  173. (strlen(m_szUL33_C4Msg) == 0 &&
  174. (
  175. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
  176. strcmp(szCmd, "cmd-41") == 0
  177. ))
  178. ||
  179. strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-12") == 0 ||
  180. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-27") == 0 ||
  181. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-39") == 0 ||
  182. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-53") == 0 ||
  183. strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-89") == 0
  184. )
  185. {
  186. nRet = GetDeviceParam( nAddr,pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  187. if( nRet != 0 ) return nRet;
  188. }
  189. if( GetTickCount() - m_dwOnlineTick > 60 *1000 && m_dwOnlineTick > 0 )
  190. {
  191. m_devOnline = FALSE;
  192. }
  193. else if( GetTickCount() - m_dwOnlineTick < 60 *1000 && m_dwOnlineTick > 0 )
  194. {
  195. m_devOnline = TRUE;
  196. }
  197. if( m_devOnline == FALSE ) {
  198. return -1;
  199. }
  200. nRet = GetULQ41VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  201. nRet = GetULQ43VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  202. nRet = GetULQ44VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  203. nRet = GetULQC0VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  204. nRet = GetULQC1VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  205. nRet = GetULQC2VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  206. nRet = GetULQC3VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  207. nRet = GetULQC4VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  208. nRet = GetULQC7VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  209. nRet = GetULQC8VarMsg(szCmd, szMsg, nIndex, nLen, szType);
  210. LOG4C((LOG_NOTICE,"nRet = %d,cmd = %s,值 = %s",nRet,szCmd,szMsg));
  211. return nRet;
  212. }
  213. int CUL33::GetDeviceParam(
  214. int nAddr,
  215. CCommProcess *pComm, //串口对象指针
  216. char szSendMsg[UL33_SEND_MSG], //发送Buffer
  217. char szCmd[MAX_CMD], // 命令
  218. char szRecvMsg[VAR_MSG], // 接收Buffer
  219. int &nIndex, // 变量索引,针对接收Buffer而言
  220. int &nLen, // 变量长度
  221. char szType[TYPE_LENGTH]) // 变量数据类型
  222. {
  223. int nRet = -1;
  224. nRet = RequestReadStatus(nAddr,pComm, szSendMsg);
  225. if( nRet != 0 )
  226. {
  227. return nRet; // 串口忙
  228. }
  229. nRet = ResponseReadStatus(pComm, szCmd, szRecvMsg, nIndex, nLen, szType);
  230. return nRet;
  231. }
  232. int CUL33::GetULQ41VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  233. {
  234. int nRet = 0;
  235. if( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
  236. strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ||
  237. strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 ||
  238. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 ||
  239. strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ||
  240. strcmp(szCmd, "cmd-11") == 0
  241. )
  242. {
  243. #if IS_USE_READMSG_CS
  244. EnterCriticalSection( &m_csReadMsg );
  245. #endif
  246. DataConversion(szType, m_szUL33_41Msg + nIndex, szRecvMsg, nLen,0,0 );
  247. #if IS_USE_READMSG_CS
  248. LeaveCriticalSection(&m_csReadMsg);
  249. #endif
  250. nRet = 0;
  251. }
  252. return nRet;
  253. }
  254. int CUL33::GetULQC0VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  255. {
  256. int nRet = 0;
  257. if(
  258. strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  259. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  260. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 ||
  261. strcmp(szCmd, "cmd-18") == 0 )
  262. {
  263. #if IS_USE_READMSG_CS
  264. EnterCriticalSection( &m_csReadMsg );
  265. #endif
  266. DataConversion(szType, m_szUL33_C0Msg + nIndex, szRecvMsg, nLen, 0, 0);
  267. #if IS_USE_READMSG_CS
  268. LeaveCriticalSection(&m_csReadMsg);
  269. #endif
  270. nRet = 0;
  271. }
  272. return nRet;
  273. }
  274. int CUL33::GetULQC1VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  275. {
  276. int nRet = 0;
  277. if(
  278. strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 ||
  279. strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  280. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
  281. strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0
  282. )
  283. {
  284. #if IS_USE_READMSG_CS
  285. EnterCriticalSection( &m_csReadMsg );
  286. #endif
  287. DataConversion(szType, m_szUL33_C1Msg + nIndex, szRecvMsg, nLen, 0, 0);
  288. #if IS_USE_READMSG_CS
  289. LeaveCriticalSection(&m_csReadMsg);
  290. #endif
  291. nRet = 0;
  292. }
  293. return nRet;
  294. }
  295. int CUL33::GetULQC2VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  296. {
  297. int nRet = 0;
  298. if(
  299. strcmp(szCmd, "cmd-27") == 0 || strcmp(szCmd, "cmd-28") == 0 ||
  300. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 ||
  301. strcmp(szCmd, "cmd-31") == 0
  302. )
  303. {
  304. #if IS_USE_READMSG_CS
  305. EnterCriticalSection( &m_csReadMsg );
  306. #endif
  307. DataConversion(szType, m_szUL33_C2Msg + nIndex, szRecvMsg, nLen, 0, 0);
  308. #if IS_USE_READMSG_CS
  309. LeaveCriticalSection(&m_csReadMsg);
  310. #endif
  311. nRet = 0;
  312. }
  313. return nRet;
  314. }
  315. int CUL33::GetULQC3VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  316. {
  317. int nRet = 0;
  318. if( strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 ||
  319. strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  320. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  321. strcmp(szCmd, "cmd-38") == 0
  322. )
  323. {
  324. #if IS_USE_READMSG_CS
  325. EnterCriticalSection( &m_csReadMsg );
  326. #endif
  327. DataConversion(szType, m_szUL33_C3Msg + nIndex, szRecvMsg, nLen, 0, 0);
  328. #if IS_USE_READMSG_CS
  329. LeaveCriticalSection(&m_csReadMsg);
  330. #endif
  331. nRet = 0;
  332. }
  333. return nRet;
  334. }
  335. int CUL33::GetULQ43VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  336. {
  337. int nRet = 0;
  338. if(
  339. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 ||
  340. strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 ||
  341. strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  342. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 ||
  343. strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 ||
  344. strcmp(szCmd, "cmd-52") == 0
  345. )
  346. {
  347. #if IS_USE_READMSG_CS
  348. EnterCriticalSection( &m_csReadMsg );
  349. #endif
  350. DataConversion(szType, m_szUL33_43Msg + nIndex, szRecvMsg, nLen, 0, 0);
  351. #if IS_USE_READMSG_CS
  352. LeaveCriticalSection(&m_csReadMsg);
  353. #endif
  354. nRet = 0;
  355. }
  356. return nRet;
  357. }
  358. int CUL33::GetULQ44VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  359. {
  360. int nRet = 0;
  361. if( strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  362. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 ||
  363. strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0
  364. )
  365. {
  366. #if IS_USE_READMSG_CS
  367. EnterCriticalSection( &m_csReadMsg );
  368. #endif
  369. DataConversion(szType, m_szUL33_44Msg + nIndex, szRecvMsg, nLen, 0, 0);
  370. #if IS_USE_READMSG_CS
  371. LeaveCriticalSection(&m_csReadMsg);
  372. #endif
  373. nRet = 0;
  374. }
  375. return nRet;
  376. }
  377. int CUL33::GetULQC7VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  378. {
  379. int nRet = 0;
  380. if(strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  381. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  382. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 ||
  383. strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  384. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  385. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 ||
  386. strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 ||
  387. strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  388. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0 ||
  389. strcmp(szCmd, "cmd-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
  390. strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
  391. strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
  392. strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
  393. strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
  394. strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
  395. )
  396. {
  397. #if IS_USE_READMSG_CS
  398. EnterCriticalSection( &m_csReadMsg );
  399. #endif
  400. DataConversion(szType,m_szUL33_C7Msg + nIndex, szRecvMsg, nLen, 0, 0);
  401. #if IS_USE_READMSG_CS
  402. LeaveCriticalSection(&m_csReadMsg);
  403. #endif
  404. nRet = 0;
  405. }
  406. return nRet;
  407. }
  408. int CUL33::GetULQC8VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  409. {
  410. int nRet = 0;
  411. if(
  412. strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
  413. strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
  414. strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
  415. strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
  416. strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
  417. )
  418. {
  419. #if IS_USE_READMSG_CS
  420. EnterCriticalSection( &m_csReadMsg );
  421. #endif
  422. DataConversion(szType, m_szUL33_C8Msg + nIndex, szRecvMsg, nLen, 0, 0);
  423. #if IS_USE_READMSG_CS
  424. LeaveCriticalSection(&m_csReadMsg);
  425. #endif
  426. nRet = 0;
  427. }
  428. return nRet;
  429. }
  430. int CUL33::GetULQC4VarMsg(char szCmd[MAX_CMD], char szRecvMsg[VAR_MSG], int &nIndex, int &nLen, char szType[TYPE_LENGTH])
  431. {
  432. int nRet = 0;
  433. if(
  434. strcmp(szCmd, "cmd-39") == 0 || strcmp(szCmd, "cmd-40") == 0 ||
  435. strcmp(szCmd, "cmd-41") == 0
  436. )
  437. {
  438. #if IS_USE_READMSG_CS
  439. EnterCriticalSection( &m_csReadMsg );
  440. #endif
  441. DataConversion(szType, m_szUL33_C4Msg + nIndex, szRecvMsg, nLen, 0, 0);
  442. #if IS_USE_READMSG_CS
  443. LeaveCriticalSection(&m_csReadMsg);
  444. #endif
  445. nRet = 0;
  446. }
  447. return nRet;
  448. }
  449. // 发送设置设备参数请求
  450. int CUL33::SendSetReuest(
  451. char szPath[MAX_PATH], // 程序所在路径
  452. char szIniName[MAX_PATH], // 配置文件名称
  453. int nCommPort, // 串行端口
  454. int nAddr, // 设备地址
  455. char szCmd[MAX_CMD], // 请求命令
  456. char szRecvMsg[VAR_MSG], // 响应的值
  457. int nReversed1, // 预留整形参数1接口
  458. int nReversed2, // 预留整形参数2接口
  459. int nReversed3, // 预留整形参数3接口
  460. int nReversed4, // 预留整形参数4接口
  461. int nReversed5, // 预留整形参数5接口
  462. float fReversed1, // 预留float参数1接口
  463. float fReversed2, // 预留float参数2接口
  464. float fReversed3, // 预留float参数3接口
  465. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  466. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  467. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  468. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  469. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  470. )
  471. {
  472. return 0;
  473. }
  474. int CUL33::ResponseReadStatus( CCommProcess *pComm,
  475. char szCmd[MAX_CMD],
  476. char szRecvMsg[VAR_MSG],
  477. int &nIndex,
  478. int &nLen,
  479. char szType[TYPE_LENGTH] )
  480. {
  481. #if DEBUG_UL33
  482. //LOG4C((LOG_NOTICE,"->0"));
  483. RESPONSE_STRUCT structResponse;
  484. memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  485. int nReceiveLen = 0;
  486. nReceiveLen = sizeof(RESPONSE_STRUCT);
  487. char *pBuffer = new char[ nReceiveLen ];
  488. memset(pBuffer, 0, nLen);
  489. int nReadLen = 0;
  490. nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
  491. if (!CheckLength(pBuffer))
  492. {
  493. SetEvent(m_hSemComm);
  494. if (pBuffer !=NULL)
  495. {
  496. delete[] pBuffer;
  497. pBuffer = NULL;
  498. }
  499. LOG4C((LOG_NOTICE,"->长度校验出错"));
  500. return ERR_CODE_UL33_COM_CHKSUM_LOST; //长度校验出错
  501. }
  502. if (!ChkSumCheck(pBuffer,nReadLen))
  503. {
  504. SetEvent(m_hSemComm);
  505. if (pBuffer !=NULL)
  506. {
  507. delete[] pBuffer;
  508. pBuffer = NULL;
  509. }
  510. LOG4C((LOG_NOTICE,"->校验码校验出错"));
  511. return ERR_CODE_UL33_COM_CHKSUM_LOST; //校验码校验出错
  512. }
  513. int nRet = RtnCheck(pBuffer, nReadLen);
  514. if (nRet != 0)
  515. {
  516. SetEvent( m_hSemComm );
  517. if( pBuffer != NULL)
  518. {
  519. delete[] pBuffer;
  520. pBuffer = NULL;
  521. }
  522. LOG4C((LOG_NOTICE,"->RTN校验出错"));
  523. return nRet; //RTN校验出错
  524. }
  525. if( nReadLen <= 0)
  526. {
  527. // 串口没有读到数据
  528. SetEvent( m_hSemComm );
  529. if( pBuffer != NULL)
  530. {
  531. delete[] pBuffer;
  532. pBuffer = NULL;
  533. }
  534. LOG4C((LOG_NOTICE,"->串口没有读到数据"));
  535. return ERR_CODE_UL33_COM_READ_NO_DATA;
  536. }
  537. SetULQ41VarMsg( szCmd, pBuffer);
  538. SetULQ43VarMsg( szCmd, pBuffer);
  539. SetULQ44VarMsg( szCmd, pBuffer);
  540. SetULQC0VarMsg( szCmd, pBuffer);
  541. SetULQC1VarMsg( szCmd, pBuffer);
  542. SetULQC2VarMsg( szCmd, pBuffer);
  543. SetULQC3VarMsg( szCmd, pBuffer);
  544. SetULQC4VarMsg( szCmd, pBuffer);
  545. SetULQC7VarMsg( szCmd, pBuffer);
  546. SetULQC8VarMsg( szCmd, pBuffer);
  547. m_dwOnlineTick = GetTickCount();
  548. SetEvent( m_hSemComm );
  549. if( pBuffer != NULL)
  550. {
  551. delete[] pBuffer;
  552. pBuffer = NULL;
  553. }
  554. #else
  555. SimulationCommData();
  556. #endif
  557. return 0;
  558. }
  559. int CUL33::RequestReadStatus(int nAddr,CCommProcess *pComm,char chSendMsg[UL33_SEND_MSG])
  560. {
  561. #if DEBUG_UL33
  562. #if 0
  563. char chLength[4] = {0};
  564. char chChkSum[5] = {0};
  565. REQUESTPARAM RequestPara;
  566. int iLen = sizeof(RequestPara);
  567. memset( &RequestPara, 0, iLen );
  568. //起始位
  569. RequestPara.RequestChild.bySoi = 0x7E;
  570. //通讯协议版本
  571. RequestPara.RequestChild.byVer[0] = 0x31;
  572. RequestPara.RequestChild.byVer[1] = 0x37;
  573. //设备地址描述
  574. RequestPara.RequestChild.byAdr[0] = ByteToAscii((nAddr >> 4) & 0x0f);
  575. RequestPara.RequestChild.byAdr[1] = ByteToAscii(nAddr & 0x0f);
  576. //Cid1
  577. RequestPara.RequestChild.byCid1[0] = 0x32;
  578. RequestPara.RequestChild.byCid1[1] = 0x41;
  579. //Cid2
  580. memcpy(RequestPara.RequestChild.byCid2, chSendMsg, 2);
  581. RequestPara.RequestChild.byLength[0] = 0x45;
  582. RequestPara.RequestChild.byLength[1] = 0x30;
  583. RequestPara.RequestChild.byLength[2] = 0x30;
  584. RequestPara.RequestChild.byLength[3] = 0x32;
  585. //Info
  586. RequestPara.RequestChild.byInfo[0] = 0x30;
  587. RequestPara.RequestChild.byInfo[1] = 0x31;
  588. int nLen = sizeof(RequestPara.byCheckSum) -1;
  589. //校验码
  590. BYTE *pDataBuf = new BYTE[ iLen - nLen];
  591. memset(pDataBuf, 0, iLen -nLen );
  592. memcpy(pDataBuf, &RequestPara, iLen - nLen);
  593. GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.byCheckSum) - 2 );
  594. delete []pDataBuf;
  595. pDataBuf = NULL;
  596. RequestPara.byCheckSum[0] = chChkSum[0];
  597. RequestPara.byCheckSum[1] = chChkSum[1];
  598. RequestPara.byCheckSum[2] = chChkSum[2];
  599. RequestPara.byCheckSum[3] = chChkSum[3];
  600. //结束符
  601. RequestPara.byEoi = 0x0D;
  602. //LOG4C((LOG_NOTICE,"sendmsg = %s",(char*)RequestPara));
  603. //WaitForSingObject();等待有信号;
  604. if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
  605. {
  606. //求得数组字符实际长度;
  607. int nDataLen = (int)sizeof(RequestPara);
  608. //ResetEvent()设置无信号状态
  609. ResetEvent( m_hSemComm );
  610. int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen);
  611. if( nResult != nDataLen )
  612. {
  613. //SetEvent设置有信号;
  614. SetEvent( m_hSemComm );
  615. //返回 错误值;
  616. return EER_CODE_UL33_COM_REGNUM;
  617. }
  618. }
  619. else
  620. {
  621. //如果m_hSemCom无信号,返回错误;
  622. return ERR_CODE_UL33_COM_BUSY;
  623. }
  624. #endif
  625. BYTE szSendMSG[32] = {0};
  626. // 对数组进行赋值;
  627. szSendMSG[0] = 0x7E;
  628. szSendMSG[1] = 0x31;
  629. szSendMSG[2] = 0x37;
  630. szSendMSG[3] = ByteToAscii( (nAddr >> 4) & 0x0F);
  631. szSendMSG[4] = ByteToAscii( nAddr & 0x0F);
  632. szSendMSG[5] = 0x32;
  633. szSendMSG[6] = 0x41;
  634. memcpy(szSendMSG + 7, chSendMsg, 2);
  635. // 进行lengcheck判断;
  636. if ( nAddr == 4 )
  637. {
  638. BYTE szCheck[5] = {0};
  639. memcpy(szSendMSG + 9, "E002", 4); // LENID;
  640. memcpy(szSendMSG + 13, "01", 2); // DATAF;
  641. GetEmersonCheck((char *)szSendMSG, (char*)szCheck);
  642. memcpy(szSendMSG + 15,szCheck,4);
  643. szSendMSG[strlen((char*)szSendMSG)] = 0x0D;
  644. }
  645. else if ( nAddr == 3)
  646. {
  647. BYTE szCheck[5] = {0};
  648. memcpy(szSendMSG + 9, "E002", 4); // LENID;
  649. memcpy(szSendMSG + 13, "02", 2); // DATAF;
  650. GetEmersonCheck((char *)szSendMSG, (char*)szCheck);
  651. memcpy(szSendMSG + 15,szCheck,4);
  652. szSendMSG[strlen((char*)szSendMSG)] = 0x0D;
  653. }
  654. int iLen = strlen((char*)szSendMSG);
  655. if (WaitForSingleObject(m_hSemComm,0) == WAIT_OBJECT_0 ) {
  656. ResetEvent(m_hSemComm);
  657. int nResult = pComm->Write(szSendMSG, iLen);
  658. if (nResult != iLen){
  659. SetEvent(m_hSemComm);
  660. return EER_CODE_UL33_COM_REGNUM;
  661. }
  662. }
  663. else{
  664. return ERR_CODE_UL33_COM_BUSY;
  665. }
  666. LOG4C((LOG_NOTICE,"发送命令=%s",szSendMSG));
  667. #endif
  668. return 0;
  669. }
  670. void CUL33::GetEmersonCheck(char *szData, char *szCheck ,int nlen /* = 12 */)
  671. {
  672. DWORD dwSum(0);
  673. nlen = strlen(szData);
  674. for (int i(0); i < nlen; i++)
  675. {
  676. dwSum += szData[i+1] ;
  677. }
  678. WORD iCompliment = dwSum;
  679. iCompliment = ~iCompliment;//取反
  680. iCompliment++;
  681. itoa(iCompliment, szCheck, 16);
  682. for (int i(0); i < 5 ; i++)
  683. {
  684. lowcase2uppcase((BYTE &)szCheck[i]);
  685. }
  686. }
  687. void CUL33::lowcase2uppcase(BYTE &btSrc)
  688. {
  689. if( btSrc >= 'a' && btSrc <= 'z' )
  690. {
  691. btSrc = btSrc - 'a' + 'A';
  692. }
  693. }
  694. void CUL33::SetULQ41VarMsg(char szCmd[MAX_CMD], char *pBuff)
  695. {
  696. if( strcmp(szCmd, "cmd-1") == 0 || strcmp(szCmd, "cmd-2") == 0 ||
  697. strcmp(szCmd, "cmd-3") == 0 || strcmp(szCmd, "cmd-4") == 0 ||
  698. strcmp(szCmd, "cmd-5") == 0 || strcmp(szCmd, "cmd-6") == 0 ||
  699. strcmp(szCmd, "cmd-7") == 0 || strcmp(szCmd, "cmd-8") == 0 ||
  700. strcmp(szCmd, "cmd-9") == 0 || strcmp(szCmd, "cmd-10") == 0 ||
  701. strcmp(szCmd, "cmd-11") == 0
  702. )
  703. {
  704. #if IS_USE_READMSG_CS
  705. EnterCriticalSection( &m_csReadMsg );
  706. #endif
  707. memcpy(m_szUL33_41Msg, pBuff, sizeof(m_szUL33_41Msg));
  708. #if IS_USE_READMSG_CS
  709. LeaveCriticalSection(&m_csReadMsg);
  710. #endif
  711. }
  712. }
  713. void CUL33::SetULQC0VarMsg(char szCmd[MAX_CMD], char *pBuff)
  714. {
  715. if(
  716. strcmp(szCmd, "cmd-12") == 0 || strcmp(szCmd, "cmd-13") == 0 ||
  717. strcmp(szCmd, "cmd-14") == 0 || strcmp(szCmd, "cmd-15") == 0 ||
  718. strcmp(szCmd, "cmd-16") == 0 || strcmp(szCmd, "cmd-17") == 0 ||
  719. strcmp(szCmd, "cmd-18") == 0
  720. )
  721. {
  722. #if IS_USE_READMSG_CS
  723. EnterCriticalSection( &m_csReadMsg );
  724. #endif
  725. memcpy(m_szUL33_C0Msg, pBuff, sizeof(m_szUL33_C0Msg));
  726. #if IS_USE_READMSG_CS
  727. LeaveCriticalSection(&m_csReadMsg);
  728. #endif
  729. }
  730. }
  731. void CUL33::SetULQC1VarMsg(char szCmd[MAX_CMD], char *pBuff)
  732. {
  733. if( strcmp(szCmd, "cmd-19") == 0 || strcmp(szCmd, "cmd-20") == 0 ||
  734. strcmp(szCmd, "cmd-21") == 0 || strcmp(szCmd, "cmd-22") == 0 ||
  735. strcmp(szCmd, "cmd-23") == 0 || strcmp(szCmd, "cmd-24") == 0 ||
  736. strcmp(szCmd, "cmd-25") == 0 || strcmp(szCmd, "cmd-26") == 0
  737. )
  738. {
  739. #if IS_USE_READMSG_CS
  740. EnterCriticalSection( &m_csReadMsg );
  741. #endif
  742. memcpy(m_szUL33_C1Msg, pBuff, sizeof(m_szUL33_C1Msg));
  743. #if IS_USE_READMSG_CS
  744. LeaveCriticalSection(&m_csReadMsg);
  745. #endif
  746. }
  747. }
  748. void CUL33::SetULQC2VarMsg(char szCmd[MAX_CMD], char *pBuff)
  749. {
  750. if( strcmp(szCmd, "cmd-27") == 0|| strcmp(szCmd, "cmd-28") == 0 ||
  751. strcmp(szCmd, "cmd-29") == 0 || strcmp(szCmd, "cmd-30") == 0 ||
  752. strcmp(szCmd, "cmd-31") == 0
  753. )
  754. {
  755. #if IS_USE_READMSG_CS
  756. EnterCriticalSection( &m_csReadMsg );
  757. #endif
  758. memcpy(m_szUL33_C2Msg, pBuff, sizeof(m_szUL33_C2Msg));
  759. #if IS_USE_READMSG_CS
  760. LeaveCriticalSection(&m_csReadMsg);
  761. #endif
  762. }
  763. }
  764. void CUL33::SetULQC3VarMsg(char szCmd[MAX_CMD], char *pBuff)
  765. {
  766. if(
  767. strcmp(szCmd, "cmd-32") == 0 || strcmp(szCmd, "cmd-33") == 0 ||
  768. strcmp(szCmd, "cmd-34") == 0 || strcmp(szCmd, "cmd-35") == 0 ||
  769. strcmp(szCmd, "cmd-36") == 0 || strcmp(szCmd, "cmd-37") == 0 ||
  770. strcmp(szCmd, "cmd-38") == 0
  771. )
  772. {
  773. #if IS_USE_READMSG_CS
  774. EnterCriticalSection( &m_csReadMsg );
  775. #endif
  776. memcpy(m_szUL33_C3Msg, pBuff, sizeof(m_szUL33_C3Msg));
  777. #if IS_USE_READMSG_CS
  778. LeaveCriticalSection(&m_csReadMsg);
  779. #endif
  780. }
  781. }
  782. void CUL33::SetULQ43VarMsg(char szCmd[MAX_CMD], char *pBuff)
  783. {
  784. if(
  785. strcmp(szCmd, "cmd-42") == 0 || strcmp(szCmd, "cmd-43") == 0 ||
  786. strcmp(szCmd, "cmd-44") == 0 || strcmp(szCmd, "cmd-45") == 0 ||
  787. strcmp(szCmd, "cmd-46") == 0 || strcmp(szCmd, "cmd-47") == 0 ||
  788. strcmp(szCmd, "cmd-48") == 0 || strcmp(szCmd, "cmd-49") == 0 ||
  789. strcmp(szCmd, "cmd-50") == 0 || strcmp(szCmd, "cmd-51") == 0 ||
  790. strcmp(szCmd, "cmd-52") == 0
  791. )
  792. {
  793. #if IS_USE_READMSG_CS
  794. EnterCriticalSection( &m_csReadMsg );
  795. #endif
  796. memcpy(m_szUL33_43Msg, pBuff, sizeof(m_szUL33_43Msg));
  797. #if IS_USE_READMSG_CS
  798. LeaveCriticalSection(&m_csReadMsg);
  799. #endif
  800. }
  801. }
  802. void CUL33::SetULQ44VarMsg(char szCmd[MAX_CMD], char *pBuff)
  803. {
  804. if(
  805. strcmp(szCmd, "cmd-53") == 0 || strcmp(szCmd, "cmd-54") == 0 ||
  806. strcmp(szCmd, "cmd-55") == 0 || strcmp(szCmd, "cmd-56") == 0 ||
  807. strcmp(szCmd, "cmd-57") == 0 || strcmp(szCmd, "cmd-58") == 0
  808. )
  809. {
  810. #if IS_USE_READMSG_CS
  811. EnterCriticalSection( &m_csReadMsg );
  812. #endif
  813. memcpy(m_szUL33_44Msg, pBuff, sizeof(m_szUL33_44Msg));
  814. #if IS_USE_READMSG_CS
  815. LeaveCriticalSection(&m_csReadMsg);
  816. #endif
  817. }
  818. }
  819. void CUL33::SetULQC7VarMsg(char szCmd[MAX_CMD], char *pBuff)
  820. {
  821. if(
  822. strcmp(szCmd, "cmd-59") == 0 || strcmp(szCmd, "cmd-60") == 0 ||
  823. strcmp(szCmd, "cmd-61") == 0 || strcmp(szCmd, "cmd-62") == 0 ||
  824. strcmp(szCmd, "cmd-63") == 0 || strcmp(szCmd, "cmd-64") == 0 ||
  825. strcmp(szCmd, "cmd-65") == 0 || strcmp(szCmd, "cmd-66") == 0 ||
  826. strcmp(szCmd, "cmd-67") == 0 || strcmp(szCmd, "cmd-68") == 0 ||
  827. strcmp(szCmd, "cmd-69") == 0 || strcmp(szCmd, "cmd-70") == 0 ||
  828. strcmp(szCmd, "cmd-71") == 0 || strcmp(szCmd, "cmd-72") == 0 ||
  829. strcmp(szCmd, "cmd-73") == 0 || strcmp(szCmd, "cmd-74") == 0 ||
  830. strcmp(szCmd, "cmd-75") == 0 || strcmp(szCmd, "cmd-76") == 0 ||
  831. strcmp(szCmd, "cmd-77") == 0 || strcmp(szCmd, "cmd-78") == 0 ||
  832. strcmp(szCmd, "cmd-79") == 0 || strcmp(szCmd, "cmd-80") == 0 ||
  833. strcmp(szCmd, "cmd-81") == 0 || strcmp(szCmd, "cmd-82") == 0 ||
  834. strcmp(szCmd, "cmd-83") == 0 || strcmp(szCmd, "cmd-84") == 0 ||
  835. strcmp(szCmd, "cmd-85") == 0 || strcmp(szCmd, "cmd-86") == 0 ||
  836. strcmp(szCmd, "cmd-87") == 0 || strcmp(szCmd, "cmd-88") == 0
  837. )
  838. {
  839. #if IS_USE_READMSG_CS
  840. EnterCriticalSection( &m_csReadMsg );
  841. #endif
  842. memcpy(m_szUL33_C7Msg, pBuff, sizeof(m_szUL33_C7Msg));
  843. #if IS_USE_READMSG_CS
  844. LeaveCriticalSection(&m_csReadMsg);
  845. #endif
  846. }
  847. }
  848. void CUL33::SetULQC8VarMsg(char szCmd[MAX_CMD], char *pBuff)
  849. {
  850. if(
  851. strcmp(szCmd, "cmd-89") == 0 || strcmp(szCmd, "cmd-90") == 0 ||
  852. strcmp(szCmd, "cmd-91") == 0 || strcmp(szCmd, "cmd-92") == 0 ||
  853. strcmp(szCmd, "cmd-93") == 0 || strcmp(szCmd, "cmd-94") == 0 ||
  854. strcmp(szCmd, "cmd-95") == 0 || strcmp(szCmd, "cmd-96") == 0 ||
  855. strcmp(szCmd, "cmd-97") == 0 || strcmp(szCmd, "cmd-98") == 0
  856. )
  857. {
  858. #if IS_USE_READMSG_CS
  859. EnterCriticalSection( &m_csReadMsg );
  860. #endif
  861. memcpy(m_szUL33_C8Msg, pBuff, sizeof(m_szUL33_C8Msg));
  862. #if IS_USE_READMSG_CS
  863. LeaveCriticalSection(&m_csReadMsg);
  864. #endif
  865. }
  866. }
  867. void CUL33::SetULQC4VarMsg(char szCmd[MAX_CMD], char *pBuff)
  868. {
  869. if(
  870. strcmp(szCmd, "cmd-39") == 0 ||
  871. strcmp(szCmd, "cmd-40") == 0 ||
  872. strcmp(szCmd, "cmd-41") == 0
  873. )
  874. {
  875. #if IS_USE_READMSG_CS
  876. EnterCriticalSection( &m_csReadMsg );
  877. #endif
  878. memcpy(m_szUL33_C4Msg, pBuff, sizeof(m_szUL33_C4Msg));
  879. #if IS_USE_READMSG_CS
  880. LeaveCriticalSection(&m_csReadMsg);
  881. #endif
  882. }
  883. }
  884. UINT CUL33::GetCheckSum(char *pBuf, char chDest[5], int len)
  885. {
  886. WORD iSum = 0;;
  887. for(int i=0; i<len; i++)//求和
  888. {
  889. iSum += pBuf[i];
  890. }
  891. WORD iCompliment = iSum;
  892. iCompliment = ~iCompliment;//取反
  893. iCompliment++;
  894. itoa(iCompliment, chDest, 16);
  895. chDest[0] = lowercase2uppercase(chDest[0]);
  896. chDest[1] = lowercase2uppercase(chDest[1]);
  897. chDest[2] = lowercase2uppercase(chDest[2]);
  898. chDest[3] = lowercase2uppercase(chDest[3]);
  899. return atoi(chDest);
  900. }
  901. //
  902. //BOOL CUL33::LengthCheck(char szRecvdMsg[VAR_MSG])
  903. //{
  904. //
  905. // WORD len ,index , lenID;
  906. // len = 4;
  907. // index = 9;
  908. // char ch[4];
  909. //
  910. // for (int i=0;i<len;i++)
  911. // {
  912. // ch[i] = szRecvdMsg[index+i];
  913. // }
  914. //
  915. // lenID = AsciiToBYTE(ch[1]) + AsciiToBYTE(ch[2]) + AsciiToBYTE(ch[3]);
  916. // lenID = lenID%16;
  917. // lenID = ~lenID + 1;
  918. // lenID = lenID & 15;
  919. //
  920. // if (AsciiToBYTE(ch[0]) == lenID)
  921. // {
  922. // return TRUE;
  923. // }
  924. // else
  925. // {
  926. // return FALSE;
  927. // }
  928. //}
  929. //BOOL CUL33::ChkSumCheck(char szSendMsg[],int len)
  930. //{
  931. // char *buffer = new char[5];
  932. //
  933. // memset(buffer,0,sizeof(buffer));
  934. //
  935. // unsigned int nData = 0;
  936. // unsigned int nDataLen = 0;
  937. //
  938. // for (int i = 1; i < len-5; i++)
  939. // {
  940. // nData += szSendMsg[i];
  941. // }
  942. //
  943. // nData = ~nData +1;
  944. //
  945. // nData = nData << 16;
  946. // itoa(nData,buffer,16);
  947. //
  948. // int j = 0;
  949. // for (i = len-5; i <len -1,j < 4; i++,j++)
  950. // {
  951. // if(lowercase2uppercase(buffer[j]) != szSendMsg[i])
  952. // {
  953. // return FALSE;
  954. // }
  955. // }
  956. //
  957. // return TRUE;
  958. //}
  959. WORD CUL33::RtnCheck(char szRecvdMsg[],int len)
  960. {
  961. char ch[2] = {0};
  962. ch[0] = szRecvdMsg[7];
  963. ch[1] = szRecvdMsg[8];
  964. if (atoi(ch) == 0)
  965. {
  966. return ERR_CODE_RTN_NATURAL;
  967. }
  968. else if (atoi(ch) ==1)
  969. {
  970. return ERR_CODE_RTN_VER_ERROR;
  971. }
  972. else if (atoi(ch) ==2)
  973. {
  974. return ERR_CODE_RTN_CHKSUM_ERROR;
  975. }
  976. else if (atoi(ch) ==3)
  977. {
  978. return ERR_CODE_RTN_LCHKSUM_ERROR;
  979. }
  980. else if (atoi(ch) ==4)
  981. {
  982. return ERR_CODE_RTN_CID_ERROR;
  983. }
  984. else if (atoi(ch) ==5)
  985. {
  986. return ERR_CODE_RTN_COMMAND_FORMAT;
  987. }
  988. else if (atoi(ch) ==6)
  989. {
  990. return ERR_CODE_RTN_INVALID_DATA;
  991. }
  992. else if (atoi(ch) ==16)
  993. {
  994. return ERR_CODE_RTN_INVALID_LIMIT;
  995. }
  996. else if (atoi(ch) ==17)
  997. {
  998. return ERR_CODE_RTN_OPERATE_FAIL;
  999. }
  1000. else if (atoi(ch) ==18)
  1001. {
  1002. return ERR_CODE_RTN_EQUIT_FAIL;
  1003. }
  1004. return -1;
  1005. }
  1006. int CUL33::GetULFromIni(
  1007. char szPath[MAX_PATH], //服务器程序所在目录
  1008. char szIniName[MAX_PATH], //配置文件名
  1009. char szCmd[MAX_CMD], //命令
  1010. char szSendMsg[MAX_CMD], //发送Buffer
  1011. char nType[MAX_CMD],
  1012. int &nIndex,
  1013. int &nLen
  1014. )
  1015. {
  1016. CHAR szFile[MAX_PATH + 1] = "";
  1017. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);
  1018. GetPrivateProfileString(szCmd, "SendCmd", "", szSendMsg, 10, szFile);
  1019. szSendMsg[strlen(szSendMsg)] = '\0';
  1020. GetPrivateProfileString(szCmd, "type", "", nType, 10, szFile);
  1021. nType[strlen(nType)] = '\0';
  1022. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);
  1023. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  1024. return 0;
  1025. }
  1026. void CUL33::SimulationCommData(void)
  1027. {
  1028. }