Data.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #include "stdafx.h"
  2. #include "kernel.h"
  3. #include "resource.h"
  4. #include "Client2SrvType.h"
  5. #include "TCPClient.h"
  6. //---------------------------------------------- CBaseVar ----------
  7. IMPLEMENT_SERIAL(CBaseVar, CObject, 0)
  8. CBaseVar::CBaseVar():CObject()
  9. {
  10. m_strVarUID = _T("");
  11. m_strName = _T("");
  12. m_strDesc = _T("");
  13. m_strSetValue = _T("");
  14. m_strUnit = _T("");
  15. m_strOnDesc = _T("On");
  16. m_strOffDesc = _T("Off");
  17. m_strRelatePage = _T("");
  18. m_strFields = _T("public");
  19. m_strSnmpOid = _T("");
  20. m_strRs232Cmd = _T("");
  21. m_strRs232Type = _T("");
  22. m_nVarID = 0;
  23. m_nVarChildID = 0;
  24. m_nVarItemID = 0;
  25. m_nVarTypeID = 0;
  26. m_nDevID = 0;
  27. m_nMinValues = 0;
  28. m_nMaxValues = 0;
  29. m_nMaxConvtRate = 0;
  30. m_nMinConvtRate = 0;
  31. m_nUpperLimit = 0;
  32. m_nLowerLimit = 0;
  33. m_nNormalState = 0;
  34. m_nCollectFreq = 0;
  35. m_nRearm = 0;
  36. m_nOffset = 0;
  37. //m_nCoefficient = 0;
  38. m_nFuncCode = 0;
  39. m_nRegStartAddr = 0;
  40. m_nRegNum = 0;
  41. m_nDataLen = 0;
  42. m_nWaringLevel = 0;
  43. m_nPurview = 0;
  44. m_nRs232Index = 0;
  45. m_bIsSave = FALSE;
  46. m_bRealtimeFlag = FALSE;
  47. m_bIsDDE = FALSE;
  48. m_bRecCurve = FALSE;
  49. //===============================================
  50. // 新增成员变量 in 2010-04-07
  51. m_fCoef = 0.0;
  52. m_nIdentifyTime = 0;
  53. m_nRedetectTime = 0;
  54. m_bIsNormalAlarm = FALSE;
  55. m_nStartBit = 0;
  56. m_nEndBit = 0;
  57. m_strReserved1 = _T("");
  58. m_strReserved2 = _T("");
  59. m_strReserved3 = _T("");
  60. m_strReserved4 = _T("");
  61. m_strReserved5 = _T("");
  62. m_strReserved6 = _T("");
  63. m_strReserved7 = _T("");
  64. m_strReserved8 = _T("");
  65. m_strReserved9 = _T("");
  66. m_strReserved10 = _T("");
  67. m_nReserved1 = 0;
  68. m_nReserved2 = 0;
  69. m_nReserved3 = 0;
  70. m_nReserved4 = 0;
  71. m_nReserved5 = 0;
  72. m_nReserved6 = 0;
  73. m_nReserved7 = 0;
  74. m_nReserved8 = 0;
  75. m_nReserved9 = 0;
  76. m_nReserved10 = 0;
  77. m_bReserved1 = FALSE;
  78. m_bReserved2 = FALSE;
  79. m_bReserved3 = FALSE;
  80. m_bReserved4 = FALSE;
  81. m_bReserved5 = FALSE;
  82. m_bReserved6 = FALSE;
  83. m_bReserved7 = FALSE;
  84. m_bReserved8 = FALSE;
  85. m_bReserved9 = FALSE;
  86. m_bReserved10 = FALSE;
  87. m_strContent = "";
  88. m_nReadNum = 0;
  89. m_bExistDatePlan = true;
  90. m_dwIdentityTick = 0;
  91. m_dwReturnNormalIdentityTick = 0;
  92. }
  93. CBaseVar &CBaseVar::operator=(CBaseVar& member)
  94. {
  95. m_strVarUID = member.m_strVarUID;
  96. m_strName = member.m_strName;
  97. m_strDesc = member.m_strDesc;
  98. m_strSetValue = member.m_strSetValue;
  99. m_strUnit = member.m_strUnit;
  100. m_strOnDesc = member.m_strOnDesc;
  101. m_strOffDesc = member.m_strOffDesc;
  102. m_strRelatePage = member.m_strRelatePage;
  103. m_strFields = member.m_strFields;
  104. m_strSnmpOid = member.m_strSnmpOid;
  105. m_nVarID = member.m_nVarID;
  106. m_nVarChildID = member.m_nVarChildID;
  107. m_nVarItemID = member.m_nVarItemID;
  108. m_nVarTypeID = member.m_nVarTypeID;
  109. m_nDevID = member.m_nDevID;
  110. m_nMinValues = member.m_nMinValues;
  111. m_nMaxValues = member.m_nMaxValues;
  112. m_nMaxConvtRate = member.m_nMaxConvtRate;
  113. m_nMinConvtRate = member.m_nMinConvtRate;
  114. //m_nCoefficient = member.m_nCoefficient;
  115. m_nUpperLimit = member.m_nUpperLimit;
  116. m_nLowerLimit = member.m_nLowerLimit;
  117. m_nNormalState = member.m_nNormalState;
  118. m_nCollectFreq = member.m_nCollectFreq;
  119. m_nRearm = member.m_nRearm;
  120. m_nOffset = member.m_nOffset;
  121. m_nFuncCode = member.m_nFuncCode;
  122. m_nRegStartAddr = member.m_nRegStartAddr;
  123. m_nRegNum = member.m_nRegNum;
  124. m_nDataLen = member.m_nDataLen;
  125. m_nWaringLevel = member.m_nWaringLevel;
  126. m_nPurview = member.m_nPurview;
  127. m_bIsDDE = member.m_bIsDDE;
  128. m_bRecCurve = member.m_bRecCurve;
  129. m_bIsSave = member.m_bIsSave;
  130. m_bRealtimeFlag = member.m_bRealtimeFlag;
  131. m_strRs232Cmd = member.m_strRs232Cmd;
  132. m_strRs232Type = member.m_strRs232Type;
  133. m_nRs232Index = member.m_nRs232Index;
  134. //===============================================
  135. // 新增成员变量 in 2010-04-07
  136. m_fCoef = member.m_fCoef;
  137. m_nIdentifyTime = member.m_nIdentifyTime;
  138. m_nRedetectTime = member.m_nRedetectTime;
  139. m_bIsNormalAlarm = member.m_bIsNormalAlarm;
  140. m_nStartBit = member.m_nStartBit;
  141. m_nEndBit = member.m_nEndBit;
  142. m_nStatusListNum = member.m_nStatusListNum;
  143. list<int>::iterator it_status_id;
  144. int nStatusID;
  145. for( it_status_id = member.m_listStatusID.begin(); it_status_id != member.m_listStatusID.end(); )
  146. {
  147. nStatusID = *(it_status_id++);
  148. m_listStatusID.insert(m_listStatusID.end(), nStatusID);
  149. }
  150. list<CString>::iterator it_status_desc;
  151. CString strStatusDesc;
  152. for( it_status_desc = member.m_listStatusDesc.begin(); it_status_desc != member.m_listStatusDesc.end(); )
  153. {
  154. strStatusDesc = *(it_status_desc++);
  155. m_listStatusDesc.insert(m_listStatusDesc.end(), strStatusDesc);
  156. }
  157. m_strReserved1 = member.m_strReserved1;
  158. m_strReserved2 = member.m_strReserved2;
  159. m_strReserved3 = member.m_strReserved3;
  160. m_strReserved4 = member.m_strReserved4;
  161. m_strReserved5 = member.m_strReserved5;
  162. m_strReserved6 = member.m_strReserved6;
  163. m_strReserved7 = member.m_strReserved7;
  164. m_strReserved8 = member.m_strReserved8;
  165. m_strReserved9 = member.m_strReserved9;
  166. m_strReserved10 = member.m_strReserved10;
  167. m_nReserved1 = member.m_nReserved1;
  168. m_nReserved2 = member.m_nReserved2;
  169. m_nReserved3 = member.m_nReserved3;
  170. m_nReserved4 = member.m_nReserved4;
  171. m_nReserved5 = member.m_nReserved5;
  172. m_nReserved6 = member.m_nReserved6;
  173. m_nReserved7 = member.m_nReserved7;
  174. m_nReserved8 = member.m_nReserved8;
  175. m_nReserved9 = member.m_nReserved9;
  176. m_nReserved10 = member.m_nReserved10;
  177. m_bReserved1 = member.m_bReserved1;
  178. m_bReserved2 = member.m_bReserved2;
  179. m_bReserved3 = member.m_bReserved3;
  180. m_bReserved4 = member.m_bReserved4;
  181. m_bReserved5 = member.m_bReserved5;
  182. m_bReserved6 = member.m_bReserved6;
  183. m_bReserved7 = member.m_bReserved7;
  184. m_bReserved8 = member.m_bReserved8;
  185. m_bReserved9 = member.m_bReserved9;
  186. m_bReserved10 = member.m_bReserved10;
  187. m_strContent = member.m_strContent;
  188. m_nReadNum = member.m_nReadNum;
  189. m_bExistDatePlan = member.m_bExistDatePlan;
  190. m_dwIdentityTick = member.m_dwIdentityTick;
  191. m_dwReturnNormalIdentityTick = member.m_dwReturnNormalIdentityTick;
  192. return *this;
  193. }
  194. void CBaseVar::Serialize(CArchive& ar)
  195. {
  196. CObject::Serialize(ar);
  197. if(ar.IsStoring())
  198. {
  199. ar << m_strVarUID;
  200. ar << m_strName;
  201. ar << m_strDesc;
  202. ar << m_strSetValue;
  203. ar << m_strUnit;
  204. ar << m_strOnDesc;
  205. ar << m_strOffDesc;
  206. ar << m_strRelatePage;
  207. ar << m_strFields;
  208. ar << m_strSnmpOid;
  209. ar << m_nVarID;
  210. ar << m_nVarChildID;
  211. ar << m_nVarItemID;
  212. ar << m_nVarTypeID;
  213. ar << m_nDevID;
  214. ar << m_nMinValues;
  215. ar << m_nMaxValues;
  216. ar << m_nMaxConvtRate;
  217. ar << m_nMinConvtRate;
  218. //ar << m_nCoefficient;
  219. ar << m_nUpperLimit;
  220. ar << m_nLowerLimit;
  221. ar << m_nNormalState;
  222. ar << m_nCollectFreq;
  223. ar << m_nRearm;
  224. ar << m_nOffset;
  225. ar << m_nFuncCode;
  226. ar << m_nRegStartAddr;
  227. ar << m_nRegNum;
  228. ar << m_nDataLen;
  229. ar << m_nWaringLevel;
  230. ar << m_nPurview;
  231. ar << m_bIsDDE;
  232. ar << m_bRecCurve;
  233. ar << m_bIsSave;
  234. ar << m_bRealtimeFlag;
  235. ar << m_strRs232Cmd;
  236. ar << m_strRs232Type;
  237. ar << m_nRs232Index;
  238. //===============================================
  239. // 新增成员变量 in 2010-04-07
  240. ar << m_fCoef;
  241. ar << m_nIdentifyTime;
  242. ar << m_nRedetectTime;
  243. ar << m_bIsNormalAlarm;
  244. ar << m_nStartBit;
  245. ar << m_nEndBit;
  246. m_nStatusListNum = m_listStatusID.size();
  247. ar << m_nStatusListNum;
  248. list<int>::iterator it_status_id;
  249. int nStatusID;
  250. for( it_status_id = m_listStatusID.begin(); it_status_id != m_listStatusID.end(); )
  251. {
  252. nStatusID = *(it_status_id++);
  253. ar << nStatusID;
  254. }
  255. list<CString>::iterator it_status_desc;
  256. CString strStatusDesc;
  257. for( it_status_desc = m_listStatusDesc.begin(); it_status_desc != m_listStatusDesc.end(); )
  258. {
  259. strStatusDesc = *(it_status_desc++);
  260. ar << strStatusDesc;
  261. }
  262. //ar << m_listEndBit;
  263. //ar << m_listStatusID;
  264. //ar << m_listStatusDesc;
  265. ar << m_strReserved1;
  266. ar << m_strReserved2;
  267. ar << m_strReserved3;
  268. ar << m_strReserved4;
  269. ar << m_strReserved5;
  270. ar << m_strReserved6;
  271. ar << m_strReserved7;
  272. ar << m_strReserved8;
  273. ar << m_strReserved9;
  274. ar << m_strReserved10;
  275. ar << m_nReserved1;
  276. ar << m_nReserved2;
  277. ar << m_nReserved3;
  278. ar << m_nReserved4;
  279. ar << m_nReserved5;
  280. ar << m_nReserved6;
  281. ar << m_nReserved7;
  282. ar << m_nReserved8;
  283. ar << m_nReserved9;
  284. ar << m_nReserved10;
  285. ar << m_bReserved1;
  286. ar << m_bReserved2;
  287. ar << m_bReserved3;
  288. ar << m_bReserved4;
  289. ar << m_bReserved5;
  290. ar << m_bReserved6;
  291. ar << m_bReserved7;
  292. ar << m_bReserved8;
  293. ar << m_bReserved9;
  294. ar << m_bReserved10;
  295. }
  296. else
  297. {
  298. ar >> m_strVarUID;
  299. ar >> m_strName;
  300. ar >> m_strDesc;
  301. ar >> m_strSetValue;
  302. ar >> m_strUnit;
  303. ar >> m_strOnDesc;
  304. ar >> m_strOffDesc;
  305. ar >> m_strRelatePage;
  306. ar >> m_strFields;
  307. ar >> m_strSnmpOid;
  308. ar >> m_nVarID;
  309. ar >> m_nVarChildID;
  310. ar >> m_nVarItemID;
  311. ar >> m_nVarTypeID;
  312. ar >> m_nDevID;
  313. ar >> m_nMinValues;
  314. ar >> m_nMaxValues;
  315. ar >> m_nMaxConvtRate;
  316. ar >> m_nMinConvtRate;
  317. //ar >> m_nCoefficient;
  318. ar >> m_nUpperLimit;
  319. ar >> m_nLowerLimit;
  320. ar >> m_nNormalState;
  321. ar >> m_nCollectFreq;
  322. ar >> m_nRearm;
  323. ar >> m_nOffset;
  324. ar >> m_nFuncCode;
  325. ar >> m_nRegStartAddr;
  326. ar >> m_nRegNum;
  327. ar >> m_nDataLen;
  328. ar >> m_nWaringLevel;
  329. ar >> m_nPurview;
  330. ar >> m_bIsDDE;
  331. ar >> m_bRecCurve;
  332. ar >> m_bIsSave;
  333. ar >> m_bRealtimeFlag;
  334. ar >> m_strRs232Cmd;
  335. ar >> m_strRs232Type;
  336. ar >> m_nRs232Index;
  337. #if IS_NEW_VERSION
  338. //===============================================
  339. // 新增成员变量 in 2010-04-07
  340. ar >> m_fCoef;
  341. ar >> m_nIdentifyTime;
  342. ar >> m_nRedetectTime;
  343. ar >> m_bIsNormalAlarm;
  344. //LOG4C((LOG_NOTICE, "m_strName=%s m_nVarID=%d m_nIdentifyTime=%d",m_strName,m_nVarID,m_nIdentifyTime));
  345. ar >> m_nStartBit;
  346. ar >> m_nEndBit;
  347. ar >> m_nStatusListNum;
  348. int nStatusID;
  349. CString strStatusDesc;
  350. for( int i = 0; i < m_nStatusListNum; i++ )
  351. {
  352. ar >> nStatusID;
  353. m_listStatusID.insert(m_listStatusID.end(), nStatusID);
  354. }
  355. for( int i = 0; i < m_nStatusListNum; i++ )
  356. {
  357. ar >> strStatusDesc;
  358. m_listStatusDesc.insert(m_listStatusDesc.end(), strStatusDesc);
  359. }
  360. ar >> m_strReserved1;
  361. ar >> m_strReserved2;
  362. ar >> m_strReserved3;
  363. ar >> m_strReserved4;
  364. ar >> m_strReserved5;
  365. ar >> m_strReserved6;
  366. ar >> m_strReserved7;
  367. ar >> m_strReserved8;
  368. ar >> m_strReserved9;
  369. ar >> m_strReserved10;
  370. ar >> m_nReserved1;
  371. ar >> m_nReserved2;
  372. ar >> m_nReserved3;
  373. ar >> m_nReserved4;
  374. ar >> m_nReserved5;
  375. ar >> m_nReserved6;
  376. ar >> m_nReserved7;
  377. ar >> m_nReserved8;
  378. ar >> m_nReserved9;
  379. ar >> m_nReserved10;
  380. ar >> m_bReserved1;
  381. ar >> m_bReserved2;
  382. ar >> m_bReserved3;
  383. ar >> m_bReserved4;
  384. ar >> m_bReserved5;
  385. ar >> m_bReserved6;
  386. ar >> m_bReserved7;
  387. ar >> m_bReserved8;
  388. ar >> m_bReserved9;
  389. ar >> m_bReserved10;
  390. #endif
  391. }
  392. }
  393. //---------------------------------------------- CAnalog ----------
  394. IMPLEMENT_SERIAL(CAnalog, CBaseVar, 0)
  395. CAnalog::CAnalog():CBaseVar()
  396. {
  397. m_bSave = FALSE;
  398. addr = NULL;
  399. m_nMonth = 1;
  400. m_nDay = 1;
  401. m_nMinCount = 0;
  402. m_nMinutes = 0;
  403. m_fDayMax = 0;
  404. m_fDayAvg = 0;
  405. m_fDayMin = 9999;
  406. m_fData = -1;
  407. bConfirm = false;
  408. }
  409. CAnalog &CAnalog::operator=(CAnalog& analog)
  410. {
  411. *(CBaseVar*)this = *((CBaseVar*)&analog);
  412. return *this;
  413. }
  414. void CAnalog::Serialize(CArchive& ar)
  415. {
  416. CBaseVar::Serialize(ar);
  417. if(ar.IsStoring())
  418. {
  419. ar << m_bSave;
  420. ar << m_fData;
  421. ar << m_nMonth;
  422. ar << m_nDay;
  423. ar << m_nMinCount;
  424. ar << m_fDayMax;
  425. ar << m_fDayAvg;
  426. ar << m_fDayMin;
  427. }
  428. else
  429. {
  430. ar >> m_bSave;
  431. ar >> m_fData;
  432. ar >> m_nMonth;
  433. ar >> m_nDay;
  434. ar >> m_nMinCount;
  435. ar >> m_fDayMax;
  436. ar >> m_fDayAvg;
  437. ar >> m_fDayMin;
  438. }
  439. //if( m_strDesc=="主机A机柜NPM 1通信" )
  440. {
  441. //LOG4C(( LOG_NOTICE,"var=%s m_nReserved1=%d m_fData=%d",m_strDesc,m_nReserved1,(int)m_fData));
  442. //m_fData = m_nReserved1;
  443. }
  444. }
  445. // 获取特殊处理变量
  446. void CAnalog::GetSpecialVarContent(int iTCPIndex)
  447. {
  448. if( !CTCPClient::GetInstancePtr(iTCPIndex)->m_SocketClient.IsOpen() )
  449. {
  450. return;
  451. }
  452. CBaseVar *pBaseVar = (CBaseVar *)this;
  453. ReadSingleSpecialVarData tagReadSingleSpecialVarData;
  454. int nLen = sizeof(ReadSingleSpecialVarData);
  455. memset( &tagReadSingleSpecialVarData, 0, nLen );
  456. tagReadSingleSpecialVarData.Header.nLen = nLen;
  457. tagReadSingleSpecialVarData.Header.nCmd = CMD_READ_SPECIAL_SINGLE_VAR_DATA;
  458. tagReadSingleSpecialVarData.Header.nCmdType = 0;
  459. strcpy( (char *)tagReadSingleSpecialVarData.DevUid, (char *)(LPCTSTR)pBaseVar->m_strVarUID );
  460. tagReadSingleSpecialVarData.iVarid = pBaseVar->m_nVarID;
  461. tagReadSingleSpecialVarData.iSpecialFlag = pBaseVar->m_nVarTypeID;
  462. tagReadSingleSpecialVarData.Header.Verify = CTCPClient::GetInstancePtr(iTCPIndex)->m_TcpParse.CalcCheckSum( &tagReadSingleSpecialVarData, nLen );
  463. USES_CONVERSION;
  464. CTCPClient::GetInstancePtr(iTCPIndex)->m_SocketClient.Write((const LPBYTE)&tagReadSingleSpecialVarData, nLen, NULL);
  465. }
  466. void CAnalog::GetVarContent(int iTCPIndex)
  467. {
  468. //请求服务器得到变量的内容和报警状态
  469. if( !CTCPClient::GetInstancePtr(iTCPIndex)->m_SocketClient.IsOpen() )
  470. {
  471. return;
  472. }
  473. CBaseVar *pBaseVar = (CBaseVar *)this;
  474. if( pBaseVar->m_nVarTypeID == 1000 ) // 内存变量,现在只用来处理设备在线状态
  475. {
  476. DevOnline tagDevOnline;
  477. int nLen = sizeof(DevOnline);
  478. memset( &tagDevOnline, 0, nLen );
  479. tagDevOnline.Header.nLen = nLen;
  480. tagDevOnline.Header.nCmd = CMD_DEV_ONLINE;
  481. tagDevOnline.Header.nCmdType = 0;
  482. tagDevOnline.nVarID = pBaseVar->m_nVarID;
  483. strcpy((char *)tagDevOnline.DevUid, (char *)(LPCTSTR)pBaseVar->m_strVarUID);
  484. tagDevOnline.Header.Verify = CTCPClient::GetInstancePtr(iTCPIndex)->m_TcpParse.CalcCheckSum( &tagDevOnline, nLen );
  485. USES_CONVERSION;
  486. CTCPClient::GetInstancePtr(iTCPIndex)->m_SocketClient.Write((const LPBYTE)&tagDevOnline, nLen, NULL);
  487. }
  488. else // I/O变量
  489. {
  490. // 请求变量在线状态,只有采集设备才会用到
  491. if( this->m_pDevice->m_nIsCollectDev == 1 )
  492. {
  493. // 暂不做处理
  494. }
  495. ReadSingleVarData tagReadSingleVarData;
  496. int nLen = sizeof(ReadSingleVarData);
  497. memset( &tagReadSingleVarData, 0, nLen );
  498. tagReadSingleVarData.Header.nLen = nLen;
  499. tagReadSingleVarData.Header.nCmd = CMD_READ_SINGLE_VAR_DATA;
  500. tagReadSingleVarData.Header.nCmdType = 0;
  501. strcpy( (char *)tagReadSingleVarData.DevUid, (char *)(LPCTSTR)pBaseVar->m_strVarUID );
  502. tagReadSingleVarData.nVarID = pBaseVar->m_nVarID;
  503. //TRACE1( "读求变量ID = %d \r\n", tagReadSingleVarData.nVarID );
  504. tagReadSingleVarData.Header.Verify = CTCPClient::GetInstancePtr(iTCPIndex)->m_TcpParse.CalcCheckSum( &tagReadSingleVarData, nLen );
  505. USES_CONVERSION;
  506. CTCPClient::GetInstancePtr(iTCPIndex)->m_SocketClient.Write((const LPBYTE)&tagReadSingleVarData, nLen, NULL);
  507. }
  508. }
  509. void CAnalog::SetValue(float fValue)
  510. {
  511. if( !CTCPClient::GetInstancePtr(0)->m_SocketClient.IsOpen() )
  512. {
  513. return;
  514. }
  515. CBaseVar *pBaseVar = (CBaseVar *)this;
  516. CString sTemp;
  517. sTemp.Format("%f",pBaseVar->m_fCoef );
  518. int RATE=0;
  519. if( sTemp.Left(3)=="0.1" )
  520. {
  521. RATE = 10;
  522. CString s;
  523. s.Format("%s 10",sTemp );
  524. //AfxMessageBox(s );
  525. }
  526. else
  527. {
  528. RATE = 1;
  529. CString s;
  530. s.Format("%s 1",sTemp );
  531. //AfxMessageBox(s );
  532. }
  533. WrSingleVarData tagWrSingleVarData;
  534. int nLen = sizeof(WrSingleVarData);
  535. memset( &tagWrSingleVarData, 0, nLen );
  536. tagWrSingleVarData.Header.nLen = nLen;
  537. tagWrSingleVarData.Header.nCmd = CMD_WRITE_SINGLE_VAR_DATA;
  538. tagWrSingleVarData.Header.nCmdType = 0;
  539. memcpy( &tagWrSingleVarData.DevUid, (char *)(LPCTSTR)pBaseVar->m_strVarUID, sizeof(tagWrSingleVarData.DevUid) );
  540. tagWrSingleVarData.iVarid = pBaseVar->m_nVarID;
  541. #if 0
  542. if( RATE==10 )
  543. tagWrSingleVarData.Data = (DOUBLE)(fValue/0.1);
  544. else
  545. tagWrSingleVarData.Data = (DOUBLE)(fValue);
  546. #else
  547. tagWrSingleVarData.Data = (DOUBLE)(fValue/pBaseVar->m_fCoef);
  548. #endif
  549. tagWrSingleVarData.Header.Verify = CTCPClient::GetInstancePtr(0)->m_TcpParse.CalcCheckSum( &tagWrSingleVarData, nLen );
  550. USES_CONVERSION;
  551. CTCPClient::GetInstancePtr(0)->m_SocketClient.Write((const LPBYTE)&tagWrSingleVarData, nLen, NULL);
  552. #if 0
  553. if( RATE==10 )
  554. m_fData = (fValue/pBaseVar->m_fCoef/0.1);
  555. else
  556. m_fData = (fValue/pBaseVar->m_fCoef);
  557. #else
  558. m_fData = (fValue/pBaseVar->m_fCoef/pBaseVar->m_fCoef);
  559. #endif
  560. }
  561. void CAnalog::Fresh( int iTCPIndex )
  562. {
  563. // 特殊处理变量单独处理
  564. if( m_nVarTypeID >= SPECIAL_VAR_TYPE_MIN_ID && m_nVarTypeID <= SPECIAL_VAR_TYPE_MAX_ID )
  565. {
  566. GetSpecialVarContent( iTCPIndex );
  567. }
  568. else
  569. {
  570. // 得到变量值和报警状态
  571. GetVarContent( iTCPIndex );
  572. }
  573. }