复件 Daikin.cpp 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. // DataMate3000.cpp: implementation of the CDataMate3000 class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Daikin.h"
  6. #include "CommProcess.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CDaiKin::CDaiKin( char szPath[MAX_PATH], // 程序所在路径
  16. char szIniName[MAX_PATH], // 配置文件名称
  17. int nCommPort, // 串行端口
  18. int nAddr, // 设备地址
  19. int nRate, // 波特率
  20. int nDataBit, // 数据位
  21. int nStopBit, // 停止位
  22. int nParity, // 校验位
  23. int nInterval // 时间间隔
  24. )
  25. {
  26. #if IS_USE_READMSG_CS
  27. InitializeCriticalSection( &m_csReadMsg ); //初始化一个临界资源对象
  28. #endif
  29. MTVERIFY( m_hSemComm = CreateEvent( NULL, TRUE, TRUE, 0 ) ); //CreateEvent()创建或打开一个命名的或无名的事件对象
  30. for( int i = 0; i < MAX_ADDR; i++ )
  31. {
  32. memset(m_szDaKin_42Msg[i], 0, sizeof(m_szDaKin_42Msg[i]));
  33. memset(m_szDaKin_43Msg[i], 0, sizeof(m_szDaKin_43Msg[i]));
  34. memset(m_szDaKin_44Msg[i], 0, sizeof(m_szDaKin_44Msg[i]));
  35. m_devOnline[i] = TRUE;
  36. m_dwOnlineTick[i] = 0;
  37. }
  38. }
  39. CDaiKin::~CDaiKin()
  40. {
  41. #if IS_USE_READMSG_CS
  42. DeleteCriticalSection( &m_csReadMsg );
  43. #endif
  44. MTVERIFY( CloseHandle( m_hSemComm ) );
  45. CloseComm();
  46. }
  47. BOOL CDaiKin::DaiKinOpenComm(int nCommPort, int nAddr, int nRate, int nDataBit, int nStopBit, int nParity, int nInterval)
  48. {
  49. BOOL bResult = FALSE;
  50. bResult = OpenComm( nCommPort, nAddr, nRate, nDataBit, nStopBit, nParity, nInterval );
  51. return bResult;
  52. }
  53. // 发送读取设备参数请求
  54. int CDaiKin::SendReadRequest(
  55. char szPath[MAX_PATH], // 程序所在路径
  56. char szIniName[MAX_PATH], // 配置文件名称
  57. int nCommPort, // 串行端口
  58. int nAddr, // 设备地址
  59. char szCmd[MAX_CMD], // 请求命令
  60. char szMsg[VAR_MSG], // 响应的值
  61. int nReversed1, // 预留整形参数1接口
  62. int nReversed2, // 预留整形参数2接口
  63. int nReversed3, // 预留整形参数3接口
  64. int nReversed4, // 预留整形参数4接口
  65. int nReversed5, // 预留整形参数5接口
  66. float fReversed1, // 预留float参数1接口
  67. float fReversed2, // 预留float参数2接口
  68. float fReversed3, // 预留float参数3接口
  69. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  70. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  71. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  72. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  73. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  74. )
  75. {
  76. int nIndex = 0, nLen = 0;
  77. char szSendMsg[DAIKIN_SEND_MSG] = {0};
  78. char szType[DK_TYPE_LENGTH] = {0};
  79. int startBit = 0;
  80. int endBit = 0;
  81. GetFromIni(szPath, szIniName, szCmd, szSendMsg, szType, nIndex, nLen, startBit, endBit);
  82. CCommProcess *pComm = FindComm(nCommPort);
  83. if( pComm == NULL ) return -1;
  84. int nRet = -1;
  85. if( (strlen(m_szDaKin_42Msg[nAddr - 1]) == 0 &&
  86. (strcmp(szCmd, "cmd-1") == 0 ) )|| //获取系统模拟量量化数据(浮点数)
  87. ( strlen(m_szDaKin_43Msg[nAddr - 1]) == 0 &&
  88. (strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  89. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  90. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 ) )|| //获取开关输入状态
  91. ( strlen(m_szDaKin_44Msg[nAddr - 1]) == 0 &&
  92. (strcmp(szCmd, "cmd-8") == 0 ) ) ||
  93. strcmp(szCmd, "cmd-1") == 0 ||
  94. strcmp(szCmd, "cmd-2") ==0 ||
  95. strcmp(szCmd, "cmd-8") == 0
  96. ) //获取系统参数(定点数)
  97. {
  98. nRet = GetDeviceParam(nAddr, pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  99. if( nRet != 0 ) return nRet;
  100. }
  101. if( GetTickCount() - m_dwOnlineTick[nAddr - 1] > 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  102. {
  103. m_devOnline[nAddr - 1] = FALSE;
  104. }
  105. else if( GetTickCount() - m_dwOnlineTick[nAddr - 1] < 60 *1000 && m_dwOnlineTick[nAddr - 1] > 0 )
  106. {
  107. m_devOnline[nAddr - 1] = TRUE;
  108. }
  109. if( m_devOnline[nAddr - 1] == FALSE )
  110. {
  111. return -1;
  112. }
  113. nRet = GetDaiKin_42VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  114. nRet = GetDaiKin_43VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  115. nRet = GetDaiKin_44VarMsg(nAddr, szCmd, szMsg, nIndex, nLen, szType, startBit, endBit);
  116. return nRet;
  117. }
  118. int CDaiKin::GetDaiKin_42VarMsg( int nAddr, //设备地址
  119. char szCmd[MAX_CMD], // 命令
  120. char szMsg[VAR_MSG], // 接收Buffer
  121. int &nIndex, // 变量索引,针对接收Buffer而言
  122. int &nLen, // 变量长度
  123. char szType[TYPE_LENGTH], // 变量数据类型
  124. int startBit,
  125. int endBit )
  126. {
  127. int nRet = 0;
  128. if( strcmp(szCmd, "cmd-1") == 0 )
  129. {
  130. #if IS_USE_READMSG_CS
  131. EnterCriticalSection( &m_csReadMsg );
  132. #endif
  133. DataConversion(szType, m_szDaKin_42Msg[nAddr - 1] + nIndex, szMsg, nLen, startBit, endBit);
  134. //LOG4C_HEX_DUMP((LOG_INFO, szMsg, 5));
  135. #if IS_USE_READMSG_CS
  136. LeaveCriticalSection(&m_csReadMsg);
  137. #endif
  138. nRet = 0;
  139. }
  140. return nRet;
  141. }
  142. int CDaiKin::GetDaiKin_43VarMsg( int nAddr, //设备地址
  143. char szCmd[MAX_CMD], // 命令
  144. char szMsg[VAR_MSG], // 接收Buffer
  145. int &nIndex, // 变量索引,针对接收Buffer而言
  146. int &nLen, // 变量长度
  147. char szType[TYPE_LENGTH],// 变量数据类型
  148. int startBit,
  149. int endBit )
  150. {
  151. int nRet = 0;
  152. if( strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  153. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  154. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 )
  155. {
  156. #if IS_USE_READMSG_CS
  157. EnterCriticalSection( &m_csReadMsg );
  158. #endif
  159. DataConversion(szType, m_szDaKin_43Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  160. #if IS_USE_READMSG_CS
  161. LeaveCriticalSection(&m_csReadMsg);
  162. #endif
  163. nRet = 0;
  164. }
  165. return nRet;
  166. }
  167. int CDaiKin::GetDaiKin_44VarMsg(int nAddr, //设备地址
  168. char szCmd[MAX_CMD], // 命令
  169. char szMsg[VAR_MSG], // 接收Buffer
  170. int &nIndex, // 变量索引,针对接收Buffer而言
  171. int &nLen, // 变量长度
  172. char szType[TYPE_LENGTH],// 变量数据类型
  173. int startBit,
  174. int endBit )
  175. {
  176. int nRet = 0;
  177. if( strcmp(szCmd, "cmd-8") == 0 )
  178. {
  179. #if IS_USE_READMSG_CS
  180. EnterCriticalSection( &m_csReadMsg );
  181. #endif
  182. DataConversion(szType, m_szDaKin_44Msg[nAddr - 1] + nIndex, szMsg, nLen, 0, 0);
  183. #if IS_USE_READMSG_CS
  184. LeaveCriticalSection(&m_csReadMsg);
  185. #endif
  186. nRet = 0;
  187. }
  188. return nRet;
  189. }
  190. int CDaiKin::GetDeviceParam(int nAddr,
  191. CCommProcess *pComm, //串口对象指针
  192. char szSendMsg[DAIKIN_SEND_MSG], //发送Buffer
  193. char szCmd[MAX_CMD], // 命令
  194. char szMsg[VAR_MSG], // 接收Buffer
  195. int &nIndex, // 变量索引,针对接收Buffer而言
  196. int &nLen, // 变量长度
  197. char szType[TYPE_LENGTH]) // 变量数据类型
  198. {
  199. int nRet = -1;
  200. nRet = RequestStatus(nAddr, szCmd, pComm, szSendMsg);
  201. if( nRet != 0 )
  202. {
  203. return nRet; // 串口忙
  204. }
  205. nRet = ResponseStatus(nAddr, pComm, szCmd, szMsg, nIndex, nLen, szType);
  206. return nRet;
  207. }
  208. int CDaiKin::SetDeviceParam(int nAddr,
  209. CCommProcess *pComm, //串口对象指针
  210. char szSendMsg[DAIKIN_SEND_MSG], //发送Buffer
  211. char szCmd[MAX_CMD], // 命令
  212. char szMsg[VAR_MSG], // 接收Buffer
  213. int &nIndex, // 变量索引,针对接收Buffer而言
  214. int &nLen, // 变量长度
  215. char szType[TYPE_LENGTH]) // 变量数据类型
  216. {
  217. int nRet = -1;
  218. nRet = WriteRequestStatus(nAddr, szCmd, pComm, szSendMsg);
  219. if( nRet != 0 )
  220. {
  221. return nRet; // 串口忙
  222. }
  223. nRet = WriteResponseStatus(nAddr, pComm, szCmd, szMsg, nIndex, nLen, szType);
  224. return nRet;
  225. }
  226. void CDaiKin::SetDaKin_42VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  227. {
  228. if( strcmp(szCmd, "cmd-1") == 0 )
  229. {
  230. #if IS_USE_READMSG_CS
  231. EnterCriticalSection( &m_csReadMsg );
  232. #endif
  233. memcpy(m_szDaKin_42Msg[nAddr - 1], pBuffer, sizeof(m_szDaKin_42Msg[nAddr - 1]));
  234. #if IS_USE_READMSG_CS
  235. LeaveCriticalSection(&m_csReadMsg);
  236. #endif
  237. }
  238. }
  239. void CDaiKin::SetDaKin_43VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  240. {
  241. if( strcmp(szCmd, "cmd-2") == 0 || strcmp(szCmd, "cmd-3") == 0 ||
  242. strcmp(szCmd, "cmd-4") == 0 || strcmp(szCmd, "cmd-5") == 0 ||
  243. strcmp(szCmd, "cmd-6") == 0 || strcmp(szCmd, "cmd-7") == 0 )
  244. {
  245. #if IS_USE_READMSG_CS
  246. EnterCriticalSection( &m_csReadMsg );
  247. #endif
  248. memcpy(m_szDaKin_43Msg[nAddr - 1], pBuffer, sizeof(m_szDaKin_43Msg[nAddr - 1]));
  249. #if IS_USE_READMSG_CS
  250. LeaveCriticalSection(&m_csReadMsg);
  251. #endif
  252. }
  253. }
  254. void CDaiKin::SetDaKin_44VarMsg( int nAddr, char szCmd[MAX_CMD], char *pBuffer)
  255. {
  256. if( strcmp(szCmd, "cmd-8") == 0 )
  257. {
  258. #if IS_USE_READMSG_CS
  259. EnterCriticalSection( &m_csReadMsg );
  260. #endif
  261. memcpy(m_szDaKin_44Msg[nAddr - 1], pBuffer, sizeof(m_szDaKin_44Msg[nAddr - 1]));
  262. #if IS_USE_READMSG_CS
  263. LeaveCriticalSection(&m_csReadMsg);
  264. #endif
  265. }
  266. }
  267. // WORD CDaiKin::GetDataLength(const WORD wLENID, char chLength[4])
  268. // {
  269. // //char szLenID[3] = {0};
  270. // ////int nLen = 10;
  271. // //DigitToBinary(wLENID, szLenID, sizeof(szLenID));
  272. //
  273. // //char chCheckSum = GetLCheckSum(szLenID, sizeof(szLenID));
  274. //
  275. // //chLength[0] = chCheckSum;
  276. // //chLength[1] = szLenID[0];
  277. // //chLength[2] = szLenID[1];
  278. // //chLength[3] = szLenID[2];
  279. //
  280. // return 0;
  281. // }
  282. // 发送设置设备参数请求
  283. int CDaiKin::SendSetReuest(
  284. char szPath[MAX_PATH], // 程序所在路径
  285. char szIniName[MAX_PATH], // 配置文件名称
  286. int nCommPort, // 串行端口
  287. int nAddr, // 设备地址
  288. char szCmd[MAX_CMD], // 请求命令
  289. char szMsg[VAR_MSG], // 响应的值
  290. int nReversed1, // 预留整形参数1接口
  291. int nReversed2, // 预留整形参数2接口
  292. int nReversed3, // 预留整形参数3接口
  293. int nReversed4, // 预留整形参数4接口
  294. int nReversed5, // 预留整形参数5接口
  295. float fReversed1, // 预留float参数1接口
  296. float fReversed2, // 预留float参数2接口
  297. float fReversed3, // 预留float参数3接口
  298. char szReversed1[MAX_RESERVED1], // 预留字符数组参数1接口
  299. char szReversed2[MAX_RESERVED2], // 预留字符数组参数2接口
  300. char szReversed3[MAX_RESERVED3], // 预留字符数组参数3接口
  301. char szReversed4[MAX_RESERVED4], // 预留字符数组参数4接口
  302. char szReversed5[MAX_RESERVED5] // 预留字符数组参数5接口
  303. )
  304. {
  305. int nIndex = 0, nLen = 0, StaBit = 0, EndBit = 0;
  306. char szSendMsg[DAIKIN_SEND_MSG];
  307. char szType[TYPE_LENGTH] = {0};
  308. char szCid2[CID2_LENGTH] = {0};
  309. char szAddr[2] = {0};
  310. char szLength[4] = {0};
  311. REQUESTSET_STRCUT szSend = {0};
  312. memset(szSendMsg, 0, DAIKIN_SEND_MSG);
  313. GetFromIni(szPath, szIniName, szCmd, szCid2, szType, nIndex, nLen, StaBit, EndBit);
  314. int iLen = sizeof(REQUESTSET_STRCUT);
  315. char chLength[4] = {0};
  316. char chChkSum[5] = {0};
  317. REQUESTSET_STRCUT RequestPara;
  318. memset( &RequestPara, 0, iLen );
  319. //起始位
  320. RequestPara.Sol = 0x7E;
  321. //通讯协议版本
  322. RequestPara.Ver[0] = 0x32;
  323. RequestPara.Ver[1] = 0x30;
  324. //设备地址描述
  325. RequestPara.Adr[0] = ByteToAscii((nAddr>>4) & 0x0f);
  326. RequestPara.Adr[1] = ByteToAscii(nAddr & 0x0f);
  327. //Cid1
  328. RequestPara.Cid1[0] = 0x36;
  329. RequestPara.Cid1[1] = 0x30;
  330. //Cid2
  331. RequestPara.Cid2[0] = ByteToAscii(szCid2[0] & 0x0f);
  332. RequestPara.Cid2[1] = ByteToAscii(szCid2[1] & 0x0f);
  333. RequestPara.Length[0] = 0x45;
  334. RequestPara.Length[1] = 0x30;
  335. RequestPara.Length[2] = 0x30;
  336. RequestPara.Length[3] = 0x30;
  337. memcpy(RequestPara.szInfo, szMsg, sizeof(RequestPara.szInfo));
  338. memset(RequestPara.Chksum, 0, sizeof(RequestPara.Chksum));
  339. //校验码
  340. BYTE *pDataBuf = new BYTE[ iLen - sizeof(RequestPara.Chksum) - 1 ];
  341. memset(pDataBuf, 0, iLen - sizeof(RequestPara.Chksum) - 1 );
  342. memcpy(pDataBuf, &RequestPara, iLen - sizeof(RequestPara.Chksum) - 1 );
  343. GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.Chksum) - 2 );
  344. RequestPara.Chksum[0] = chChkSum[0];
  345. RequestPara.Chksum[1] = chChkSum[1];
  346. RequestPara.Chksum[2] = chChkSum[2];
  347. RequestPara.Chksum[3] = chChkSum[3];
  348. //结束符
  349. RequestPara.Eol = 0x0D;
  350. memcpy(szSendMsg, &RequestPara, sizeof(REQUESTSET_STRCUT));
  351. CCommProcess *pComm = FindComm(nCommPort);
  352. if( pComm == NULL ) return -1;
  353. int nRet = -1;
  354. if( nAddr < 1 ) return -1;
  355. //LOG4C((LOG_NOTICE, "CDaiKin::SendSetReuest szSendMsg= %s, cmd = %s", szSendMsg, szCmd));
  356. if( (strcmp(szCmd, "cmd-9") == 0))
  357. {
  358. SetDeviceParam(nAddr, pComm, szSendMsg, szCmd, szMsg, nIndex, nLen, szType );
  359. }
  360. return 0;
  361. }
  362. //读取配置文件
  363. int CDaiKin::GetFromIni(
  364. char szPath[MAX_PATH], //服务器程序所在目录
  365. char szIniName[MAX_PATH], //配置文件名
  366. char szCmd[MAX_CMD], //命令
  367. char szCid2[CID2_LENGTH], //发送Buffer
  368. char szType[TYPE_LENGTH],
  369. int &nIndex,
  370. int &nLen,
  371. int &nStaBit,
  372. int &nEndBit
  373. )
  374. {
  375. char szFile[MAX_PATH + 1] = "";
  376. memset(szType, 0, TYPE_LENGTH);
  377. wsprintf(szFile, "%s\\config\\%s", szPath, szIniName);//只读config下面的ini
  378. GetPrivateProfileString(szCmd, "SendCmd", "", szCid2, CID2_LENGTH, szFile);//读取配置文件中的一段字符串
  379. GetPrivateProfileString(szCmd, "Type", "", szType, TYPE_LENGTH, szFile);
  380. nIndex = GetPrivateProfileInt(szCmd, "Index", 0, szFile);//从配置文件中取值
  381. nLen = GetPrivateProfileInt(szCmd, "Len", 0, szFile);
  382. nStaBit = GetPrivateProfileInt(szCmd, "StaBit", 0, szFile);//从配置文件中取值
  383. nEndBit = GetPrivateProfileInt(szCmd, "EndBit", 0, szFile);
  384. return 0;
  385. }
  386. int CDaiKin::RequestStatus( int nAddr,
  387. char szCmd[MAX_CMD], // 命令
  388. CCommProcess *pComm, //串口对象指针
  389. char chSendMsg[DAIKIN_SEND_MSG] //发送Buffer
  390. )
  391. {
  392. int nRet = -1;
  393. #if DEBUG_DAIKIN
  394. int iLen = sizeof(REQUEST_STRUCT);
  395. char chLength[4] = {0};
  396. char chChkSum[5] = {0};
  397. REQUEST_STRUCT RequestPara;
  398. memset( &RequestPara, 0, iLen );
  399. //起始位
  400. RequestPara.headMes.Start = 0x7E;
  401. //通讯协议版本
  402. RequestPara.headMes.Version[0] = 0x32;
  403. RequestPara.headMes.Version[1] = 0x30;
  404. //设备地址描述
  405. RequestPara.headMes.Address[0] = ByteToAscii((nAddr>>4) & 0x0f);
  406. RequestPara.headMes.Address[1] = ByteToAscii(nAddr & 0x0f);
  407. //Cid1
  408. RequestPara.headMes.Cid1[0] = 0x36;
  409. RequestPara.headMes.Cid1[1] = 0x30;
  410. //Cid2
  411. RequestPara.headMes.Cid2[0] = ByteToAscii(chSendMsg[0] & 0x0f);
  412. RequestPara.headMes.Cid2[1] = ByteToAscii(chSendMsg[1] & 0x0f);
  413. RequestPara.headMes.Lenth[0] = 0x30;
  414. RequestPara.headMes.Lenth[1] = 0x30;
  415. RequestPara.headMes.Lenth[2] = 0x30;
  416. RequestPara.headMes.Lenth[3] = 0x30;
  417. //校验码
  418. BYTE *pDataBuf = new BYTE[ iLen - sizeof(RequestPara.chkSum) - 1 ];
  419. memset(pDataBuf, 0, iLen - sizeof(RequestPara.chkSum) - 1 );
  420. memcpy(pDataBuf, &RequestPara, iLen - sizeof(RequestPara.chkSum) - 1 );
  421. GetCheckSum((char *)pDataBuf + 1, chChkSum, iLen - sizeof(RequestPara.chkSum) - 2 );
  422. RequestPara.chkSum[0] = chChkSum[0];
  423. RequestPara.chkSum[1] = chChkSum[1];
  424. RequestPara.chkSum[2] = chChkSum[2];
  425. RequestPara.chkSum[3] = chChkSum[3];
  426. //结束符
  427. RequestPara.End = 0x0D;
  428. if( WaitForSingleObject( m_hSemComm, 0 ) == WAIT_OBJECT_0 ) // 有信号才写串口
  429. {
  430. int nDataLen = (int)sizeof(RequestPara);
  431. ResetEvent( m_hSemComm );
  432. int nResult = pComm->Write((BYTE *)&RequestPara, nDataLen);
  433. if( nResult == iLen )
  434. {
  435. }
  436. else
  437. {
  438. delete []pDataBuf;
  439. SetEvent( m_hSemComm );
  440. return EER_CODE_DAIKIN_COM_WRITE_DATA;
  441. }
  442. }
  443. else
  444. {
  445. delete []pDataBuf;
  446. return ERR_CODE_DAIKIN_COM_BUSY;
  447. }
  448. delete[]pDataBuf;
  449. #endif
  450. return 0;
  451. }
  452. int CDaiKin::ResponseStatus(
  453. int nAddr, // 设备地址
  454. CCommProcess *pComm, //串口对象指针
  455. char szCmd[MAX_CMD], // 命令
  456. char szMsg[VAR_MSG], // 接收Buffer
  457. int &nIndex, // 变量索引,针对接收Buffer而言
  458. int &nLen, // 变量长度
  459. char szType[TYPE_LENGTH] // 变量数据类型
  460. )
  461. {
  462. #if DEBUG_DAIKIN
  463. int nReceiveLen = 0;
  464. int nProcessLen = 0;
  465. int nReadLen = 0;
  466. RESPONSE_STRUCT structResponse;
  467. memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  468. nReceiveLen = sizeof(RESPONSE_STRUCT);
  469. char *pBuffer = new char[ nReceiveLen ];
  470. memset(pBuffer, 0, nLen);
  471. nReadLen = pComm->Read((BYTE *)pBuffer,nLen);
  472. if( nReadLen <= 0)
  473. {
  474. // 串口没有读到数据
  475. TRACE("串口没有读到数据!\r\n");
  476. SetEvent( m_hSemComm );
  477. if( pBuffer != NULL)
  478. {
  479. delete[] pBuffer;
  480. pBuffer = NULL;
  481. }
  482. return ERR_CODE_DAIKIN_COM_READ_NO_DATA;
  483. }
  484. else if( nReadLen < nLen )
  485. {
  486. TRACE("长度没有收够,断续接收,止到收完为止!\r\n");
  487. SetEvent( m_hSemComm );
  488. if( pBuffer )
  489. {
  490. delete[] pBuffer;
  491. pBuffer = NULL;
  492. }
  493. return ERR_CODE_DAIKIN_COM_FAULT;
  494. }
  495. else if( nReadLen > nLen )
  496. {
  497. // 完全代码,不一定能执行到
  498. TRACE("接收的长度超时所需的长度,认为是非法包,扔掉\r\n");
  499. SetEvent( m_hSemComm );
  500. if( pBuffer != NULL)
  501. {
  502. delete[] pBuffer;
  503. pBuffer = NULL;
  504. }
  505. return ERR_CODE_DAIKIN_COM_READ_LEN_OVER;
  506. }
  507. if (!ChkSumCheck(pBuffer, nReadLen))
  508. {
  509. TRACE("校验码校验出错");
  510. SetEvent(m_hSemComm);
  511. if (pBuffer != NULL)
  512. {
  513. delete [] pBuffer;
  514. pBuffer = NULL;
  515. }
  516. return ERR_CODE_RTN_CHKSUM_ERROR; //校验码校验出错
  517. }
  518. if (RtnCheck(pBuffer) != 0)
  519. {
  520. SetEvent(m_hSemComm);
  521. TRACE("RTN校验出错");
  522. if (pBuffer != NULL)
  523. {
  524. delete [] pBuffer;
  525. pBuffer = NULL;
  526. }
  527. return ERR_CODE_RTN_CHKSUM_RTN_ERROR; //RTN校验出错
  528. }
  529. SetDaKin_42VarMsg(nAddr, szCmd, pBuffer);
  530. SetDaKin_43VarMsg(nAddr, szCmd, pBuffer);
  531. SetDaKin_44VarMsg(nAddr, szCmd, pBuffer);
  532. //SetDaKin_45VarMsg(nAddr, szCmd, pBuffer);
  533. //SetDaKin_47VarMsg(nAddr, szCmd, pBuffer);
  534. m_dwOnlineTick[nAddr - 1] = GetTickCount();
  535. // 设置串口等待事件为有信号
  536. SetEvent( m_hSemComm );
  537. if( pBuffer != NULL)
  538. {
  539. delete[] pBuffer;
  540. pBuffer = NULL;
  541. }
  542. #else
  543. SimulationCommData(nAddr);
  544. #endif
  545. return 0;
  546. }
  547. int CDaiKin::WriteRequestStatus( int nAddr,
  548. char szCmd[MAX_CMD], // 命令
  549. CCommProcess *pComm, //串口对象指针
  550. char chSendMsg[DAIKIN_SEND_MSG] //发送Buffer
  551. )
  552. {
  553. #if DEBUG_DAIKIN
  554. int nDataLen = (int)strlen(chSendMsg);
  555. ResetEvent( m_hSemComm );
  556. int nResult = pComm->Write((unsigned char *)chSendMsg, nDataLen);
  557. if( nResult == nDataLen )
  558. {
  559. }
  560. else
  561. {
  562. SetEvent( m_hSemComm );
  563. return EER_CODE_DAIKIN_COM_WRITE_DATA;
  564. }
  565. #endif
  566. return 0;
  567. }
  568. int CDaiKin::WriteResponseStatus( int nAddr, // 设备地址
  569. CCommProcess *pComm, //串口对象指针
  570. char szCmd[MAX_CMD], // 命令
  571. char szMsg[VAR_MSG], // 接收Buffer
  572. int &nIndex, // 变量索引,针对接收Buffer而言
  573. int &nLen, // 变量长度
  574. char szType[TYPE_LENGTH] // 变量数据类型
  575. )
  576. {
  577. #if DEBUG_DAIKIN
  578. int nReceiveLen = 0;
  579. int nProcessLen = 0;
  580. int nReadLen = 0;
  581. RESPONSE_STRUCT structResponse;
  582. memset( &structResponse, 0, sizeof(RESPONSE_STRUCT) );
  583. nReceiveLen = sizeof(RESPONSE_STRUCT) - sizeof(structResponse);
  584. char *pBuffer = new char[ nReceiveLen ];
  585. memset(pBuffer, 0, nReceiveLen);
  586. nReadLen = pComm->Read((BYTE *)pBuffer, nReceiveLen);
  587. if( nReadLen <= 0)
  588. {
  589. // 串口没有读到数据
  590. //TRACE("串口没有读到数据!\r\n");
  591. //AfxMessageBox("串口没有读到数据!");
  592. SetEvent( m_hSemComm );
  593. if( pBuffer != NULL)
  594. {
  595. delete[] pBuffer;
  596. pBuffer = NULL;
  597. }
  598. return ERR_CODE_DAIKIN_COM_READ_NO_DATA;
  599. }
  600. #if 0
  601. //int nTempLen = strlen(pBuffer);
  602. //CString str;
  603. //str.Format("%d", nTempLen);
  604. //AfxMessageBox(str);
  605. if (!ChkSumCheck(pBuffer, strlen(pBuffer)))
  606. {
  607. // 校检错误
  608. //AfxMessageBox("校检错误");
  609. //TRACE("校检错误!\r\n");
  610. SetEvent( m_hSemComm );
  611. if( pBuffer != NULL)
  612. {
  613. delete[] pBuffer;
  614. pBuffer = NULL;
  615. }
  616. return ERR_CODE_DAIKIN_COM_CHKSUM_LOST;
  617. }
  618. if (!CheckLength(pBuffer))
  619. {
  620. // 数据长度校检错误
  621. //TRACE("数据长度校检错误!\r\n");
  622. //AfxMessageBox("数据长度校检错误!");
  623. SetEvent( m_hSemComm );
  624. if( pBuffer != NULL)
  625. {
  626. delete[] pBuffer;
  627. pBuffer = NULL;
  628. }
  629. return ERR_CODE_DAIKIN_COM_VARLEN;
  630. }
  631. int nRet = RtnCheck(pBuffer);
  632. if(0 != nRet)
  633. {
  634. //AfxMessageBox("校验出错");
  635. // 设置串口等待事件为有信号
  636. SetEvent( m_hSemComm );
  637. if( pBuffer != NULL)
  638. {
  639. delete[] pBuffer;
  640. pBuffer = NULL;
  641. }
  642. return nRet;
  643. }
  644. #endif
  645. // 设置串口等待事件为有信号
  646. SetEvent( m_hSemComm );
  647. if( pBuffer != NULL)
  648. {
  649. delete[] pBuffer;
  650. pBuffer = NULL;
  651. }
  652. #else
  653. SimulationCommData(nAddr);
  654. #endif
  655. return 0;
  656. }
  657. void CDaiKin::SimulationCommData(int nAddr)
  658. {
  659. m_szDaKin_42Msg[nAddr - 1][0] = 0x7E;
  660. m_szDaKin_42Msg[nAddr - 1][1] = 0x32;
  661. m_szDaKin_42Msg[nAddr - 1][2] = 0x30;
  662. m_szDaKin_42Msg[nAddr - 1][3] = 0x30;
  663. m_szDaKin_42Msg[nAddr - 1][4] = 0x31;
  664. m_szDaKin_42Msg[nAddr - 1][5] = 0x36;
  665. m_szDaKin_42Msg[nAddr - 1][6] = 0x30;
  666. m_szDaKin_42Msg[nAddr - 1][7] = 0x30;
  667. m_szDaKin_42Msg[nAddr - 1][8] = 0x30;
  668. m_szDaKin_42Msg[nAddr - 1][9] = 0x39;
  669. m_szDaKin_42Msg[nAddr - 1][10] = 0x30;
  670. m_szDaKin_42Msg[nAddr - 1][11] = 0x33;
  671. m_szDaKin_42Msg[nAddr - 1][12] = 0x34;
  672. m_szDaKin_42Msg[nAddr - 1][13] = 0x30;
  673. m_szDaKin_42Msg[nAddr - 1][14] = 0x30;
  674. m_szDaKin_42Msg[nAddr - 1][15] = 0x20;
  675. m_szDaKin_42Msg[nAddr - 1][16] = 0x20;
  676. m_szDaKin_42Msg[nAddr - 1][17] = 0x20;
  677. m_szDaKin_42Msg[nAddr - 1][18] = 0x20;
  678. m_szDaKin_42Msg[nAddr - 1][19] = 0x20;
  679. m_szDaKin_42Msg[nAddr - 1][20] = 0x20;
  680. m_szDaKin_42Msg[nAddr - 1][21] = 0x20;
  681. m_szDaKin_42Msg[nAddr - 1][22] = 0x20;
  682. m_szDaKin_42Msg[nAddr - 1][23] = 0x20;
  683. m_szDaKin_42Msg[nAddr - 1][24] = 0x20;
  684. m_szDaKin_42Msg[nAddr - 1][25] = 0x20;
  685. m_szDaKin_42Msg[nAddr - 1][26] = 0x20;
  686. m_szDaKin_42Msg[nAddr - 1][27] = 0x20;
  687. m_szDaKin_42Msg[nAddr - 1][28] = 0x20;
  688. m_szDaKin_42Msg[nAddr - 1][29] = 0x20;
  689. m_szDaKin_42Msg[nAddr - 1][30] = 0x20;
  690. m_szDaKin_42Msg[nAddr - 1][31] = 0x20;
  691. m_szDaKin_42Msg[nAddr - 1][32] = 0x20;
  692. m_szDaKin_42Msg[nAddr - 1][33] = 0x20;
  693. m_szDaKin_42Msg[nAddr - 1][34] = 0x20;
  694. m_szDaKin_42Msg[nAddr - 1][35] = 0x20;
  695. m_szDaKin_42Msg[nAddr - 1][36] = 0x20;
  696. m_szDaKin_42Msg[nAddr - 1][37] = 0x20;
  697. m_szDaKin_42Msg[nAddr - 1][38] = 0x20;
  698. m_szDaKin_42Msg[nAddr - 1][39] = 0x20;
  699. m_szDaKin_42Msg[nAddr - 1][40] = 0x20;
  700. m_szDaKin_42Msg[nAddr - 1][41] = 0x20;
  701. m_szDaKin_42Msg[nAddr - 1][42] = 0x20;
  702. m_szDaKin_42Msg[nAddr - 1][43] = 0x30;
  703. m_szDaKin_42Msg[nAddr - 1][44] = 0x38;
  704. m_szDaKin_42Msg[nAddr - 1][45] = 0x44;
  705. m_szDaKin_42Msg[nAddr - 1][46] = 0x31;
  706. m_szDaKin_42Msg[nAddr - 1][47] = 0x20;
  707. m_szDaKin_42Msg[nAddr - 1][48] = 0x20;
  708. m_szDaKin_42Msg[nAddr - 1][49] = 0x20;
  709. m_szDaKin_42Msg[nAddr - 1][50] = 0x20;
  710. m_szDaKin_42Msg[nAddr - 1][51] = 0x20;
  711. m_szDaKin_42Msg[nAddr - 1][52] = 0x20;
  712. m_szDaKin_42Msg[nAddr - 1][53] = 0x20;
  713. m_szDaKin_42Msg[nAddr - 1][54] = 0x20;
  714. m_szDaKin_42Msg[nAddr - 1][55] = 0x20;
  715. m_szDaKin_42Msg[nAddr - 1][56] = 0x20;
  716. m_szDaKin_42Msg[nAddr - 1][57] = 0x20;
  717. m_szDaKin_42Msg[nAddr - 1][58] = 0x20;
  718. m_szDaKin_42Msg[nAddr - 1][59] = 0x20;
  719. m_szDaKin_42Msg[nAddr - 1][60] = 0x20;
  720. m_szDaKin_42Msg[nAddr - 1][61] = 0x20;
  721. m_szDaKin_42Msg[nAddr - 1][62] = 0x20;
  722. m_szDaKin_42Msg[nAddr - 1][63] = 0x30;
  723. m_szDaKin_42Msg[nAddr - 1][64] = 0x30;
  724. m_szDaKin_42Msg[nAddr - 1][65] = 0x46;
  725. m_szDaKin_42Msg[nAddr - 1][66] = 0x36;
  726. m_szDaKin_42Msg[nAddr - 1][67] = 0x38;
  727. m_szDaKin_42Msg[nAddr - 1][68] = 0x41;
  728. m_szDaKin_42Msg[nAddr - 1][69] = 0x0D;
  729. m_szDaKin_43Msg[nAddr - 1][0] = 0x7E;
  730. m_szDaKin_43Msg[nAddr - 1][1] = 0x32;
  731. m_szDaKin_43Msg[nAddr - 1][2] = 0x30;
  732. m_szDaKin_43Msg[nAddr - 1][3] = 0x30;
  733. m_szDaKin_43Msg[nAddr - 1][4] = 0x31;
  734. m_szDaKin_43Msg[nAddr - 1][5] = 0x36;
  735. m_szDaKin_43Msg[nAddr - 1][6] = 0x30;
  736. m_szDaKin_43Msg[nAddr - 1][7] = 0x30;
  737. m_szDaKin_43Msg[nAddr - 1][8] = 0x30;
  738. m_szDaKin_43Msg[nAddr - 1][9] = 0x37;
  739. m_szDaKin_43Msg[nAddr - 1][10] = 0x30;
  740. m_szDaKin_43Msg[nAddr - 1][11] = 0x31;
  741. m_szDaKin_43Msg[nAddr - 1][12] = 0x38;
  742. m_szDaKin_43Msg[nAddr - 1][13] = 0x30;
  743. m_szDaKin_43Msg[nAddr - 1][14] = 0x30;
  744. m_szDaKin_43Msg[nAddr - 1][15] = 0x30;
  745. m_szDaKin_43Msg[nAddr - 1][16] = 0x31;
  746. m_szDaKin_43Msg[nAddr - 1][17] = 0x30;
  747. m_szDaKin_43Msg[nAddr - 1][18] = 0x39;
  748. m_szDaKin_43Msg[nAddr - 1][19] = 0x30;
  749. m_szDaKin_43Msg[nAddr - 1][20] = 0x30;
  750. m_szDaKin_43Msg[nAddr - 1][21] = 0x30;
  751. m_szDaKin_43Msg[nAddr - 1][22] = 0x30;
  752. m_szDaKin_43Msg[nAddr - 1][23] = 0x30;
  753. m_szDaKin_43Msg[nAddr - 1][24] = 0x31;
  754. m_szDaKin_43Msg[nAddr - 1][25] = 0x30;
  755. m_szDaKin_43Msg[nAddr - 1][26] = 0x31;
  756. m_szDaKin_43Msg[nAddr - 1][27] = 0x30;
  757. m_szDaKin_43Msg[nAddr - 1][28] = 0x30;
  758. m_szDaKin_43Msg[nAddr - 1][29] = 0x30;
  759. m_szDaKin_43Msg[nAddr - 1][30] = 0x30;
  760. m_szDaKin_43Msg[nAddr - 1][31] = 0x30;
  761. m_szDaKin_43Msg[nAddr - 1][32] = 0x30;
  762. m_szDaKin_43Msg[nAddr - 1][33] = 0x30;
  763. m_szDaKin_43Msg[nAddr - 1][34] = 0x30;
  764. m_szDaKin_43Msg[nAddr - 1][35] = 0x30;
  765. m_szDaKin_43Msg[nAddr - 1][36] = 0x32;
  766. m_szDaKin_43Msg[nAddr - 1][37] = 0x46;
  767. m_szDaKin_43Msg[nAddr - 1][38] = 0x39;
  768. m_szDaKin_43Msg[nAddr - 1][39] = 0x31;
  769. m_szDaKin_43Msg[nAddr - 1][40] = 0x38;
  770. m_szDaKin_43Msg[nAddr - 1][41] = 0x0D;
  771. m_szDaKin_44Msg[nAddr - 1][0] = 0x7E;
  772. m_szDaKin_44Msg[nAddr - 1][1] = 0x32;
  773. m_szDaKin_44Msg[nAddr - 1][2] = 0x30;
  774. m_szDaKin_44Msg[nAddr - 1][3] = 0x30;
  775. m_szDaKin_44Msg[nAddr - 1][4] = 0x31;
  776. m_szDaKin_44Msg[nAddr - 1][5] = 0x36;
  777. m_szDaKin_44Msg[nAddr - 1][6] = 0x30;
  778. m_szDaKin_44Msg[nAddr - 1][7] = 0x30;
  779. m_szDaKin_44Msg[nAddr - 1][8] = 0x30;
  780. m_szDaKin_44Msg[nAddr - 1][9] = 0x33;
  781. m_szDaKin_44Msg[nAddr - 1][10] = 0x30;
  782. m_szDaKin_44Msg[nAddr - 1][11] = 0x31;
  783. m_szDaKin_44Msg[nAddr - 1][12] = 0x43;
  784. m_szDaKin_44Msg[nAddr - 1][13] = 0x30;
  785. m_szDaKin_44Msg[nAddr - 1][14] = 0x30;
  786. m_szDaKin_44Msg[nAddr - 1][15] = 0x20;
  787. m_szDaKin_44Msg[nAddr - 1][16] = 0x20;
  788. m_szDaKin_44Msg[nAddr - 1][17] = 0x20;
  789. m_szDaKin_44Msg[nAddr - 1][18] = 0x20;
  790. m_szDaKin_44Msg[nAddr - 1][19] = 0x20;
  791. m_szDaKin_44Msg[nAddr - 1][20] = 0x20;
  792. m_szDaKin_44Msg[nAddr - 1][21] = 0x20;
  793. m_szDaKin_44Msg[nAddr - 1][22] = 0x20;
  794. m_szDaKin_44Msg[nAddr - 1][23] = 0x20;
  795. m_szDaKin_44Msg[nAddr - 1][24] = 0x20;
  796. m_szDaKin_44Msg[nAddr - 1][25] = 0x20;
  797. m_szDaKin_44Msg[nAddr - 1][26] = 0x20;
  798. m_szDaKin_44Msg[nAddr - 1][27] = 0x30;
  799. m_szDaKin_44Msg[nAddr - 1][28] = 0x32;
  800. m_szDaKin_44Msg[nAddr - 1][29] = 0x20;
  801. m_szDaKin_44Msg[nAddr - 1][30] = 0x20;
  802. m_szDaKin_44Msg[nAddr - 1][31] = 0x20;
  803. m_szDaKin_44Msg[nAddr - 1][32] = 0x20;
  804. m_szDaKin_44Msg[nAddr - 1][33] = 0x20;
  805. m_szDaKin_44Msg[nAddr - 1][34] = 0x20;
  806. m_szDaKin_44Msg[nAddr - 1][35] = 0x20;
  807. m_szDaKin_44Msg[nAddr - 1][36] = 0x30;
  808. m_szDaKin_44Msg[nAddr - 1][37] = 0x31;
  809. m_szDaKin_44Msg[nAddr - 1][38] = 0x30;
  810. m_szDaKin_44Msg[nAddr - 1][39] = 0x30;
  811. m_szDaKin_44Msg[nAddr - 1][40] = 0x30;
  812. m_szDaKin_44Msg[nAddr - 1][41] = 0x46;
  813. m_szDaKin_44Msg[nAddr - 1][42] = 0x39;
  814. m_szDaKin_44Msg[nAddr - 1][43] = 0x39;
  815. m_szDaKin_44Msg[nAddr - 1][44] = 0x44;
  816. m_szDaKin_44Msg[nAddr - 1][45] = 0x0D;
  817. }
  818. WORD CDaiKin::RtnCheck(char Msg[VAR_MSG])
  819. {
  820. int len ,index;
  821. len = 2;
  822. index = 7;
  823. char ch[2];
  824. ch[0] = Msg[index];
  825. ch[1] = Msg[index+1];
  826. if (atoi(ch)==ERR_CID_RTN_VAR)
  827. {
  828. return ERR_CID_RTN_VAR;
  829. }
  830. else if (atoi(ch)==ERR_CID_RTN_CHKSUM)
  831. {
  832. return ERR_CID_RTN_CHKSUM;
  833. }
  834. else if (atoi(ch)==ERR_CID_RTN_LCHKSUM)
  835. {
  836. return ERR_CID_RTN_LCHKSUM;
  837. }
  838. else if (atoi(ch)==ERR_CID_RTN_CID2)
  839. {
  840. return ERR_CID_RTN_CID2;
  841. }
  842. else if (atoi(ch)==ERR_CID_RTN_FORMAT)
  843. {
  844. return ERR_CID_RTN_FORMAT;
  845. }
  846. else if (atoi(ch)==ERR_CID_RTN_INVALI_DATA)
  847. {
  848. return ERR_CID_RTN_INVALI_DATA;
  849. }
  850. else /*if (atoi(ch)==ERR_CID_RTN_NORMAL)*/
  851. {
  852. return ERR_CID_RTN_NORMAL;
  853. }
  854. }
  855. UINT CDaiKin::GetCheckSum(char *pBuf, char chDest[5], int len)
  856. {
  857. WORD iSum = 0;
  858. //unsigned char chCompliment[2] = {0};
  859. for(int i=0; i<len; i++)//求和
  860. {
  861. //TRACE("%x\r\n", pBuf[i]);
  862. iSum += pBuf[i];
  863. }
  864. WORD iCompliment = iSum;
  865. iCompliment = ~iCompliment;//取反
  866. iCompliment++;
  867. //DigitToBinary(iCompliment, chDest, sizeof(chDest));
  868. itoa(iCompliment, chDest, 16);
  869. chDest[0] = lowercase2uppercase(chDest[0]);
  870. chDest[1] = lowercase2uppercase(chDest[1]);
  871. chDest[2] = lowercase2uppercase(chDest[2]);
  872. chDest[3] = lowercase2uppercase(chDest[3]);
  873. return atoi(chDest);
  874. }