Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

479 lines
18 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgNetDeviceCLD.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDeviceCLD.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include "..\Device\LgDeviceCLD.h"
  17. #include "LgNetDeviceCLD.h"
  18. #include "..\Comm\CLDm.h"
  19. CLgNetDeviceCLD::CLgNetDeviceCLD()
  20. {
  21. m_nRetryCount = 0;
  22. m_bReadyForNewMessage = TRUE;
  23. m_nMode = MODE_DETECTOR;
  24. memset( &m_SerialNumber, 0, sizeof(m_SerialNumber) );
  25. memset( &m_SoftwareVersion, 0, sizeof(m_SoftwareVersion) );
  26. memset( &m_Parameters, 0, sizeof(m_Parameters) );
  27. memset( &m_TemperatureParameters, 0, sizeof(m_TemperatureParameters) );
  28. memset( &m_CalibrationTable, 0, sizeof(m_CalibrationTable) );
  29. memset( &m_HzTable, 0, sizeof(m_HzTable) );
  30. // connection
  31. m_bConnected = FALSE;
  32. m_bConnectionFisrtTime = TRUE;
  33. m_nConnectionFaults = 0;
  34. }
  35. CLgNetDeviceCLD::~CLgNetDeviceCLD()
  36. {
  37. // nessesary to do it, because "vtable" will be cleared before
  38. // parent's destructor will be called
  39. CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::Unlink();
  40. }
  41. BOOL CLgNetDeviceCLD::Link( CLgLink<CLgNetObject,CLgNetObject,CLgNetObjectChild> *pLink )
  42. {
  43. if( !CLgNetDevice::Link( pLink ) )
  44. return FALSE;
  45. m_OutMsg.SetDistinationID( pLink->GetThis()->GetID() );
  46. return TRUE;
  47. }
  48. BOOL CLgNetDeviceCLD::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
  49. {
  50. // get new command
  51. if( m_bReadyForNewMessage && CLgNetObject::PopMessage( m_InMsg ) )
  52. {
  53. BYTE command;
  54. if( m_InMsg.GetCommand( &command ) )
  55. {
  56. // assume that command is valid
  57. m_bReadyForNewMessage = FALSE;
  58. switch( command )
  59. {
  60. case CLgDeviceCLD::CMD_CHANGE_ADDRESS:
  61. if( m_InMsg.GetAddress( &m_SerialNumber.nAddress ) )
  62. m_nMode = MODE_CHANGE_ADDRESS;
  63. break;
  64. case CLgDeviceCLD::CMD_GET_ADDRESS:
  65. if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
  66. m_nMode = MODE_GET_ADDRESS;
  67. break;
  68. case CLgDeviceCLD::CMD_SET_ADDRESS:
  69. if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
  70. m_nMode = MODE_SET_ADDRESS;
  71. break;
  72. case CLgDeviceCLD::CMD_GET_SERIALNUMBER:
  73. m_nMode = MODE_GET_SERIALNUMBER;
  74. break;
  75. case CLgDeviceCLD::CMD_SET_SERIALNUMBER:
  76. if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
  77. m_nMode = MODE_SET_SERIALNUMBER;
  78. break;
  79. case CLgDeviceCLD::CMD_GET_SOFTWAREVERSION:
  80. m_nMode = MODE_GET_SOFTWAREVERSION;
  81. break;
  82. case CLgDeviceCLD::CMD_RESET:
  83. m_nMode = MODE_RESET;
  84. break;
  85. case CLgDeviceCLD::CMD_GET_PARAMETERS:
  86. m_nMode = MODE_GET_PARAMETERS;
  87. break;
  88. case CLgDeviceCLD::CMD_SET_PARAMETERS:
  89. if( m_InMsg.GetParameters( &m_Parameters ) )
  90. m_nMode = MODE_SET_PARAMETERS;
  91. break;
  92. case CLgDeviceCLD::CMD_GET_RELAY_PARAMETERS:
  93. m_nMode = MODE_GET_RELAY_PARAMETERS;
  94. break;
  95. case CLgDeviceCLD::CMD_SET_RELAY_PARAMETERS:
  96. if( m_InMsg.GetRelayParameters( &m_RelayParameters ) )
  97. m_nMode = MODE_SET_RELAY_PARAMETERS;
  98. break;
  99. case CLgDeviceCLD::CMD_GET_BORDER:
  100. m_nMode = MODE_GET_BORDER;
  101. break;
  102. case CLgDeviceCLD::CMD_GET_TEMPERATURE:
  103. m_nMode = MODE_GET_TEMPERATURE;
  104. break;
  105. case CLgDeviceCLD::CMD_SET_TEMPERATURE_PARAMETERS:
  106. if( m_InMsg.GetTemperatureParameters( &m_TemperatureParameters ) )
  107. m_nMode = MODE_SET_TEMPERATURE_PARAMETERS;
  108. break;
  109. case CLgDeviceCLD::CMD_GET_TEMPERATURE_PARAMETERS:
  110. m_nMode = MODE_GET_TEMPERATURE_PARAMETERS;
  111. break;
  112. case CLgDeviceCLD::CMD_SET_CALIBRATION_TABLE:
  113. if( m_InMsg.GetCalibrationTable( &m_CalibrationTable ) )
  114. m_nMode = MODE_SET_CALIBRATION_TABLE;
  115. break;
  116. case CLgDeviceCLD::CMD_GET_CALIBRATION_TABLE:
  117. m_nMode = MODE_GET_CALIBRATION_TABLE;
  118. break;
  119. case CLgDeviceCLD::CMD_SET_HZ_TABLE:
  120. if( m_InMsg.GetHzTable( &m_HzTable ) )
  121. m_nMode = MODE_SET_HZ_TABLE;
  122. break;
  123. case CLgDeviceCLD::CMD_GET_HZ_TABLE:
  124. m_nMode = MODE_GET_HZ_TABLE;
  125. break;
  126. default:
  127. m_bReadyForNewMessage = TRUE;
  128. break;
  129. }
  130. // remember sender attributes
  131. m_OutMsg.SetSenderID( CLgNetObject::GetID() );
  132. m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
  133. }
  134. }
  135. // prepare request
  136. BYTE pSendBuffer[64];
  137. PBYTE pSendBufferPtr = pSendBuffer;
  138. INT nSendCount = 0;
  139. // making request packet depend on mode
  140. switch( m_nMode )
  141. {
  142. case MODE_DETECTOR:
  143. nSendCount += CLD_DATA::BuildCmdGetState( pSendBufferPtr, GetAddress() );
  144. break;
  145. case MODE_CHANGE_ADDRESS:
  146. nSendCount += CLD_DATA::BuildCmdChangeAddress( pSendBufferPtr, GetAddress(), m_SerialNumber.nAddress );
  147. break;
  148. case MODE_GET_ADDRESS:
  149. nSendCount += CLD_DATA::BuildCmdGetAddress( pSendBufferPtr, m_SerialNumber.pSerialNumber );
  150. break;
  151. case MODE_SET_ADDRESS:
  152. nSendCount += CLD_DATA::BuildCmdSetAddress( pSendBufferPtr, m_SerialNumber.pSerialNumber, m_SerialNumber.nAddress );
  153. break;
  154. case MODE_GET_SERIALNUMBER:
  155. nSendCount += CLD_DATA::BuildCmdGetSerialNumber( pSendBufferPtr, GetAddress() );
  156. break;
  157. case MODE_SET_SERIALNUMBER:
  158. nSendCount += CLD_DATA::BuildCmdSetSerialNumber( pSendBufferPtr, GetAddress(), m_SerialNumber.pSerialNumber );
  159. break;
  160. case MODE_GET_SOFTWAREVERSION:
  161. nSendCount += CLD_DATA::BuildCmdGetSoftwareVersion( pSendBufferPtr, GetAddress() );
  162. break;
  163. case MODE_RESET:
  164. nSendCount += CLD_DATA::BuildCmdReset( pSendBufferPtr, GetAddress() );
  165. break;
  166. case MODE_GET_PARAMETERS:
  167. nSendCount += CLD_DATA::BuildCmdGetParameters( pSendBufferPtr, GetAddress() );
  168. break;
  169. case MODE_SET_PARAMETERS:
  170. nSendCount += CLD_DATA::BuildCmdSetParameters( pSendBufferPtr, GetAddress(), m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
  171. break;
  172. case MODE_GET_RELAY_PARAMETERS:
  173. nSendCount += CLD_DATA::BuildCmdGetRelayParameters( pSendBufferPtr, GetAddress() );
  174. break;
  175. case MODE_SET_RELAY_PARAMETERS:
  176. nSendCount += CLD_DATA::BuildCmdSetRelayParameters( pSendBufferPtr, GetAddress(), m_RelayParameters.bEnable, m_RelayParameters.bInvert );
  177. break;
  178. case MODE_GET_BORDER:
  179. nSendCount += CLD_DATA::BuildCmdGetBorder( pSendBufferPtr, GetAddress() );
  180. break;
  181. case MODE_GET_TEMPERATURE:
  182. nSendCount += CLD_DATA::BuildCmdGetTemperature( pSendBufferPtr, GetAddress() );
  183. break;
  184. case MODE_GET_TEMPERATURE_PARAMETERS:
  185. nSendCount += CLD_DATA::BuildCmdGetTemperatureParameters( pSendBufferPtr, GetAddress() );
  186. break;
  187. case MODE_SET_TEMPERATURE_PARAMETERS:
  188. nSendCount += CLD_DATA::BuildCmdSetTemperatureParameters( pSendBufferPtr, GetAddress(), CLD_DATA::ValueToTemperature( m_TemperatureParameters.dTemperature ) );
  189. break;
  190. case MODE_GET_CALIBRATION_TABLE:
  191. nSendCount += CLD_DATA::BuildCmdGetCalibrationTable( pSendBufferPtr, GetAddress() );
  192. break;
  193. case MODE_SET_CALIBRATION_TABLE:
  194. nSendCount += CLD_DATA::BuildCmdSetCalibrationTable( pSendBufferPtr, GetAddress(), m_CalibrationTable.pItem, m_CalibrationTable.nCount );
  195. break;
  196. case MODE_GET_HZ_TABLE:
  197. nSendCount += CLD_DATA::BuildCmdGetHzTable( pSendBufferPtr, GetAddress() );
  198. break;
  199. case MODE_SET_HZ_TABLE:
  200. nSendCount += CLD_DATA::BuildCmdSetHzTable( pSendBufferPtr, GetAddress(), m_HzTable.pItem, m_HzTable.nCount );
  201. break;
  202. }
  203. // request/reply transaction
  204. BOOL bValid = FALSE;
  205. PBYTE pReadBuffer = NULL;
  206. INT nReadCount = 0;
  207. BOOL bTransaction = pProtocol->Write( pSendBuffer, nSendCount, 1000UL, TRUE ) &&
  208. pProtocol->Read( &pReadBuffer, &nReadCount, 100UL, TRUE );
  209. if( !bTransaction )
  210. {
  211. // notify about error
  212. m_OutMsg.BuildEvtCommunicationError( 1 );
  213. CLgNetObject::SendMessageToParent( m_OutMsg );
  214. // check connection counter
  215. if( m_bConnectionFisrtTime || m_bConnected )
  216. {
  217. if( m_nConnectionFaults <= MAX_CONNECTION_FAULTS )
  218. m_nConnectionFaults++;
  219. else
  220. {
  221. m_bConnectionFisrtTime = FALSE;
  222. m_bConnected = FALSE;
  223. // send event
  224. m_OutMsg.BuildEvtConnection( FALSE );
  225. CLgNetObject::SendMessageToParent( m_OutMsg );
  226. }
  227. }
  228. /*
  229. static DWORD dwTime = 0;
  230. if( GetTickCount() - dwTime > 1000 )
  231. {
  232. double dRange = CLD_DATA::RangeToValue( rand() % 1024 );
  233. dwTime = GetTickCount();
  234. m_OutMsg.BuildEvtAlarm( dRange );
  235. CLgNetObject::SendMessageToParent( m_OutMsg );
  236. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("CLgNetDeviceCLD::DeviceProc"), _T("Test %0.1f"), dRange );
  237. }
  238. */
  239. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_WARNING, this, _T("CLgNetDeviceCLD::DeviceProc"), _T("Transaction failed") );
  240. }
  241. else
  242. {
  243. // mark that connection is ok
  244. if( m_bConnectionFisrtTime || !m_bConnected )
  245. {
  246. m_bConnectionFisrtTime = FALSE;
  247. m_bConnected = TRUE;
  248. // send event
  249. m_OutMsg.BuildEvtConnection( TRUE );
  250. CLgNetObject::SendMessageToParent( m_OutMsg );
  251. }
  252. // each time update connection faults meter
  253. m_nConnectionFaults = 0;
  254. // check addressing
  255. if( nReadCount && ((GetAddress() == *pReadBuffer) || (CLD_DATA::EXCLUSIVE_ADDRESS == *pReadBuffer) ) )
  256. {
  257. // skip address byte
  258. pReadBuffer++;
  259. nReadCount--;
  260. // if exist command data
  261. if( nReadCount-- )
  262. {
  263. BYTE bCommand = *pReadBuffer++;
  264. // command should be according to current mode
  265. switch( m_nMode )
  266. {
  267. case MODE_DETECTOR: if( bCommand == CLD_DATA::CMD_GET_STATE ) bValid = TRUE; break;
  268. case MODE_CHANGE_ADDRESS: if( bCommand == CLD_DATA::CMD_CHANGE_ADDRESS ) bValid = TRUE; break;
  269. case MODE_GET_ADDRESS: if( bCommand == CLD_DATA::CMD_GET_ADDRESS ) bValid = TRUE; break;
  270. case MODE_SET_ADDRESS: if( bCommand == CLD_DATA::CMD_SET_ADDRESS ) bValid = TRUE; break;
  271. case MODE_GET_SERIALNUMBER: if( bCommand == CLD_DATA::CMD_GET_SERIALNUMBER ) bValid = TRUE; break;
  272. case MODE_SET_SERIALNUMBER: if( bCommand == CLD_DATA::CMD_SET_SERIALNUMBER ) bValid = TRUE; break;
  273. case MODE_GET_SOFTWAREVERSION: if( bCommand == CLD_DATA::CMD_GET_SOFTWAREVERSION ) bValid = TRUE; break;
  274. case MODE_RESET: if( bCommand == CLD_DATA::CMD_RESET ) bValid = TRUE; break;
  275. case MODE_GET_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_PARAMETERS ) bValid = TRUE; break;
  276. case MODE_SET_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_PARAMETERS ) bValid = TRUE; break;
  277. case MODE_GET_BORDER: if( bCommand == CLD_DATA::CMD_GET_BORDER ) bValid = TRUE; break;
  278. case MODE_GET_RELAY_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_RELAY_PARAMETERS ) bValid = TRUE; break;
  279. case MODE_SET_RELAY_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_RELAY_PARAMETERS ) bValid = TRUE; break;
  280. case MODE_GET_TEMPERATURE: if( bCommand == CLD_DATA::CMD_GET_TEMPERATURE ) bValid = TRUE; break;
  281. case MODE_SET_TEMPERATURE_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_TEMPERATURE_PARAMETERS ) bValid = TRUE; break;
  282. case MODE_GET_TEMPERATURE_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_TEMPERATURE_PARAMETERS ) bValid = TRUE; break;
  283. case MODE_SET_CALIBRATION_TABLE: if( bCommand == CLD_DATA::CMD_SET_CALIBRATION_TABLE ) bValid = TRUE; break;
  284. case MODE_GET_CALIBRATION_TABLE: if( bCommand == CLD_DATA::CMD_GET_CALIBRATION_TABLE ) bValid = TRUE; break;
  285. case MODE_SET_HZ_TABLE: if( bCommand == CLD_DATA::CMD_SET_HZ_TABLE ) bValid = TRUE; break;
  286. case MODE_GET_HZ_TABLE: if( bCommand == CLD_DATA::CMD_GET_HZ_TABLE ) bValid = TRUE; break;
  287. }
  288. // if reply is valid for current mode
  289. if( bValid )
  290. {
  291. BOOL bEvent = TRUE;
  292. BOOL bAlarm, bError, bTest;
  293. WORD wRange, wValue;
  294. BYTE bErrorID, bNewAddress, pSerialNumber[8], pSoftwareVersion[9];
  295. WORD wMin, wMax;
  296. WORD wTemperature;
  297. switch( m_nMode )
  298. {
  299. case MODE_DETECTOR:
  300. nReadCount -= CLD_DATA::GetEvtGetState( pReadBuffer, &bAlarm, &wRange, &bError, &bErrorID, &bTest, &wValue );
  301. if( bAlarm || bError || bTest )
  302. {
  303. if( bTest )
  304. m_OutMsg.BuildEvtTest( wValue );
  305. if( bAlarm )
  306. m_OutMsg.BuildEvtAlarm( CLD_DATA::RangeToValue( wRange ) );
  307. if( bError )
  308. m_OutMsg.BuildEvtError( bErrorID );
  309. }
  310. else
  311. bEvent = FALSE;
  312. break;
  313. case MODE_CHANGE_ADDRESS:
  314. nReadCount -= CLD_DATA::GetEvtChangeAddress( pReadBuffer, &bNewAddress );
  315. m_OutMsg.BuildEvtChangeAddress( bNewAddress );
  316. break;
  317. case MODE_GET_ADDRESS:
  318. nReadCount -= CLD_DATA::GetEvtGetAddress( pReadBuffer, pSerialNumber, &bNewAddress );
  319. m_OutMsg.BuildEvtGetAddress( pSerialNumber, bNewAddress );
  320. break;
  321. case MODE_SET_ADDRESS:
  322. nReadCount -= CLD_DATA::GetEvtSetAddress( pReadBuffer, pSerialNumber, &bNewAddress );
  323. m_OutMsg.BuildEvtSetAddress( pSerialNumber, bNewAddress );
  324. break;
  325. case MODE_GET_SERIALNUMBER:
  326. nReadCount -= CLD_DATA::GetEvtGetSerialNumber( pReadBuffer, pSerialNumber );
  327. m_OutMsg.BuildEvtGetSerialNumber( pSerialNumber );
  328. break;
  329. case MODE_SET_SERIALNUMBER:
  330. nReadCount -= CLD_DATA::GetEvtSetSerialNumber( pReadBuffer, pSerialNumber );
  331. m_OutMsg.BuildEvtSetSerialNumber( pSerialNumber );
  332. break;
  333. case MODE_GET_SOFTWAREVERSION:
  334. nReadCount -= CLD_DATA::GetEvtGetSoftwareVersion( pReadBuffer, pSoftwareVersion );
  335. m_OutMsg.BuildEvtGetSoftwareVersion( pSoftwareVersion );
  336. break;
  337. case MODE_RESET:
  338. m_OutMsg.BuildEvtReset();
  339. break;
  340. case MODE_GET_PARAMETERS:
  341. nReadCount -= CLD_DATA::GetEvtGetParameters( pReadBuffer, &m_Parameters.nOffset, &m_Parameters.nWidth, &m_Parameters.nFlip );
  342. m_OutMsg.BuildEvtGetParameters( m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
  343. break;
  344. case MODE_SET_PARAMETERS:
  345. nReadCount -= CLD_DATA::GetEvtSetParameters( pReadBuffer, &m_Parameters.nOffset, &m_Parameters.nWidth, &m_Parameters.nFlip );
  346. m_OutMsg.BuildEvtSetParameters( m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
  347. break;
  348. case MODE_GET_RELAY_PARAMETERS:
  349. nReadCount -= CLD_DATA::GetEvtGetRelayParameters( pReadBuffer, &m_RelayParameters.bEnable, &m_RelayParameters.bInvert );
  350. m_OutMsg.BuildEvtGetRelayParameters( m_RelayParameters.bEnable, m_RelayParameters.bInvert );
  351. break;
  352. case MODE_SET_RELAY_PARAMETERS:
  353. nReadCount -= CLD_DATA::GetEvtSetRelayParameters( pReadBuffer, &m_RelayParameters.bEnable, &m_RelayParameters.bInvert );
  354. m_OutMsg.BuildEvtSetRelayParameters( m_RelayParameters.bEnable, m_RelayParameters.bInvert );
  355. break;
  356. case MODE_GET_BORDER:
  357. nReadCount -= CLD_DATA::GetEvtGetBorder( pReadBuffer, &wMin, &wMax );
  358. m_OutMsg.BuildEvtGetBorder( CLD_DATA::RangeToValue( wMin ), CLD_DATA::RangeToValue( wMax ) );
  359. break;
  360. case MODE_GET_TEMPERATURE:
  361. nReadCount -= CLD_DATA::GetEvtGetTemperature( pReadBuffer, &wTemperature );
  362. m_OutMsg.BuildEvtGetTemperature( CLD_DATA::TemperatureToValue( wTemperature ) );
  363. break;
  364. case MODE_GET_TEMPERATURE_PARAMETERS:
  365. nReadCount -= CLD_DATA::GetEvtGetTemperatureParameters( pReadBuffer, &wTemperature );
  366. m_TemperatureParameters.dTemperature = CLD_DATA::TemperatureToValue( wTemperature );
  367. m_OutMsg.BuildEvtGetTemperatureParameters( &m_TemperatureParameters );
  368. break;
  369. case MODE_SET_TEMPERATURE_PARAMETERS:
  370. nReadCount -= CLD_DATA::GetEvtSetTemperatureParameters( pReadBuffer, &wTemperature );
  371. m_TemperatureParameters.dTemperature = CLD_DATA::TemperatureToValue( wTemperature );
  372. m_OutMsg.BuildEvtSetTemperatureParameters( &m_TemperatureParameters );
  373. break;
  374. case MODE_GET_CALIBRATION_TABLE:
  375. nReadCount -= CLD_DATA::GetEvtGetCalibrationTable( pReadBuffer, m_CalibrationTable.pItem, &m_CalibrationTable.nCount );
  376. m_OutMsg.BuildEvtGetCalibrationTable( &m_CalibrationTable );
  377. break;
  378. case MODE_SET_CALIBRATION_TABLE:
  379. nReadCount -= CLD_DATA::GetEvtGetCalibrationTable( pReadBuffer, m_CalibrationTable.pItem, &m_CalibrationTable.nCount );
  380. m_OutMsg.BuildEvtSetCalibrationTable( &m_CalibrationTable );
  381. break;
  382. case MODE_GET_HZ_TABLE:
  383. nReadCount -= CLD_DATA::GetEvtGetHzTable( pReadBuffer, m_HzTable.pItem, &m_HzTable.nCount );
  384. m_OutMsg.BuildEvtGetHzTable( &m_HzTable );
  385. break;
  386. case MODE_SET_HZ_TABLE:
  387. nReadCount -= CLD_DATA::GetEvtGetHzTable( pReadBuffer, m_HzTable.pItem, &m_HzTable.nCount );
  388. m_OutMsg.BuildEvtSetHzTable( &m_HzTable );
  389. break;
  390. }
  391. // send response
  392. if( bEvent )
  393. CLgNetObject::SendMessageToParent( m_OutMsg );
  394. // mark as ready for new message
  395. m_bReadyForNewMessage = TRUE;
  396. // set default work mode
  397. m_nMode = MODE_DETECTOR;
  398. }
  399. }
  400. }
  401. }
  402. // update retry counter
  403. m_nRetryCount = bValid ? 0 : ++m_nRetryCount;
  404. // check retry counter
  405. if( m_nRetryCount > MAX_RETRY_COUNT )
  406. {
  407. /*
  408. need to rewrite !!!!!!! 2003/04/13
  409. switch( m_nMode )
  410. {
  411. case MODE_DETECTOR: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_STATE ); break;
  412. case MODE_CHANGE_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_CHANGE_ADDRESS ); break;
  413. case MODE_GET_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_ADDRESS ); break;
  414. case MODE_SET_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_ADDRESS ); break;
  415. case MODE_GET_SERIALNUMBER: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_SERIALNUMBER ); break;
  416. case MODE_SET_SERIALNUMBER: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_SERIALNUMBER ); break;
  417. case MODE_GET_SOFTWAREVERSION: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_SOFTWAREVERSION ); break;
  418. case MODE_RESET: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_RESET ); break;
  419. case MODE_GET_PARAMETERS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_PARAMETERS ); break;
  420. case MODE_SET_PARAMETERS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_PARAMETERS ); break;
  421. }
  422. // send response
  423. CLgNetObject::SendMessageToParent( m_OutMsg );
  424. */
  425. // mark as ready for new message
  426. m_bReadyForNewMessage = TRUE;
  427. // set default work mode
  428. m_nMode = MODE_DETECTOR;
  429. // reset retry counter
  430. m_nRetryCount = 0;
  431. }
  432. return bTransaction;
  433. }
  434. void CLgNetDeviceCLD::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
  435. {
  436. va_list marker;
  437. va_start( marker, pFormat );
  438. m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
  439. va_end( marker );
  440. CLgNetObject::SendMessageToParent( m_OutMsg );
  441. }