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
479 lines
18 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgNetDeviceCLD.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgNetDeviceCLD.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "..\Version.h"
|
|
#include "..\Device\LgDeviceCLD.h"
|
|
#include "LgNetDeviceCLD.h"
|
|
#include "..\Comm\CLDm.h"
|
|
|
|
CLgNetDeviceCLD::CLgNetDeviceCLD()
|
|
{
|
|
m_nRetryCount = 0;
|
|
m_bReadyForNewMessage = TRUE;
|
|
m_nMode = MODE_DETECTOR;
|
|
memset( &m_SerialNumber, 0, sizeof(m_SerialNumber) );
|
|
memset( &m_SoftwareVersion, 0, sizeof(m_SoftwareVersion) );
|
|
memset( &m_Parameters, 0, sizeof(m_Parameters) );
|
|
memset( &m_TemperatureParameters, 0, sizeof(m_TemperatureParameters) );
|
|
memset( &m_CalibrationTable, 0, sizeof(m_CalibrationTable) );
|
|
memset( &m_HzTable, 0, sizeof(m_HzTable) );
|
|
|
|
// connection
|
|
m_bConnected = FALSE;
|
|
m_bConnectionFisrtTime = TRUE;
|
|
m_nConnectionFaults = 0;
|
|
}
|
|
|
|
CLgNetDeviceCLD::~CLgNetDeviceCLD()
|
|
{
|
|
// nessesary to do it, because "vtable" will be cleared before
|
|
// parent's destructor will be called
|
|
CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::Unlink();
|
|
}
|
|
|
|
BOOL CLgNetDeviceCLD::Link( CLgLink<CLgNetObject,CLgNetObject,CLgNetObjectChild> *pLink )
|
|
{
|
|
if( !CLgNetDevice::Link( pLink ) )
|
|
return FALSE;
|
|
|
|
m_OutMsg.SetDistinationID( pLink->GetThis()->GetID() );
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLgNetDeviceCLD::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
|
|
{
|
|
// get new command
|
|
if( m_bReadyForNewMessage && CLgNetObject::PopMessage( m_InMsg ) )
|
|
{
|
|
BYTE command;
|
|
if( m_InMsg.GetCommand( &command ) )
|
|
{
|
|
// assume that command is valid
|
|
m_bReadyForNewMessage = FALSE;
|
|
|
|
switch( command )
|
|
{
|
|
case CLgDeviceCLD::CMD_CHANGE_ADDRESS:
|
|
if( m_InMsg.GetAddress( &m_SerialNumber.nAddress ) )
|
|
m_nMode = MODE_CHANGE_ADDRESS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_ADDRESS:
|
|
if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
|
|
m_nMode = MODE_GET_ADDRESS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_SET_ADDRESS:
|
|
if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
|
|
m_nMode = MODE_SET_ADDRESS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_SERIALNUMBER:
|
|
m_nMode = MODE_GET_SERIALNUMBER;
|
|
break;
|
|
case CLgDeviceCLD::CMD_SET_SERIALNUMBER:
|
|
if( m_InMsg.GetSerialNumber( &m_SerialNumber ) )
|
|
m_nMode = MODE_SET_SERIALNUMBER;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_SOFTWAREVERSION:
|
|
m_nMode = MODE_GET_SOFTWAREVERSION;
|
|
break;
|
|
case CLgDeviceCLD::CMD_RESET:
|
|
m_nMode = MODE_RESET;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_PARAMETERS:
|
|
m_nMode = MODE_GET_PARAMETERS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_SET_PARAMETERS:
|
|
if( m_InMsg.GetParameters( &m_Parameters ) )
|
|
m_nMode = MODE_SET_PARAMETERS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_RELAY_PARAMETERS:
|
|
m_nMode = MODE_GET_RELAY_PARAMETERS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_SET_RELAY_PARAMETERS:
|
|
if( m_InMsg.GetRelayParameters( &m_RelayParameters ) )
|
|
m_nMode = MODE_SET_RELAY_PARAMETERS;
|
|
break;
|
|
case CLgDeviceCLD::CMD_GET_BORDER:
|
|
m_nMode = MODE_GET_BORDER;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_GET_TEMPERATURE:
|
|
m_nMode = MODE_GET_TEMPERATURE;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_SET_TEMPERATURE_PARAMETERS:
|
|
if( m_InMsg.GetTemperatureParameters( &m_TemperatureParameters ) )
|
|
m_nMode = MODE_SET_TEMPERATURE_PARAMETERS;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_GET_TEMPERATURE_PARAMETERS:
|
|
m_nMode = MODE_GET_TEMPERATURE_PARAMETERS;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_SET_CALIBRATION_TABLE:
|
|
if( m_InMsg.GetCalibrationTable( &m_CalibrationTable ) )
|
|
m_nMode = MODE_SET_CALIBRATION_TABLE;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_GET_CALIBRATION_TABLE:
|
|
m_nMode = MODE_GET_CALIBRATION_TABLE;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_SET_HZ_TABLE:
|
|
if( m_InMsg.GetHzTable( &m_HzTable ) )
|
|
m_nMode = MODE_SET_HZ_TABLE;
|
|
break;
|
|
|
|
case CLgDeviceCLD::CMD_GET_HZ_TABLE:
|
|
m_nMode = MODE_GET_HZ_TABLE;
|
|
break;
|
|
|
|
default:
|
|
m_bReadyForNewMessage = TRUE;
|
|
break;
|
|
}
|
|
|
|
// remember sender attributes
|
|
m_OutMsg.SetSenderID( CLgNetObject::GetID() );
|
|
m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
|
|
}
|
|
}
|
|
|
|
// prepare request
|
|
BYTE pSendBuffer[64];
|
|
PBYTE pSendBufferPtr = pSendBuffer;
|
|
INT nSendCount = 0;
|
|
|
|
// making request packet depend on mode
|
|
switch( m_nMode )
|
|
{
|
|
case MODE_DETECTOR:
|
|
nSendCount += CLD_DATA::BuildCmdGetState( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_CHANGE_ADDRESS:
|
|
nSendCount += CLD_DATA::BuildCmdChangeAddress( pSendBufferPtr, GetAddress(), m_SerialNumber.nAddress );
|
|
break;
|
|
case MODE_GET_ADDRESS:
|
|
nSendCount += CLD_DATA::BuildCmdGetAddress( pSendBufferPtr, m_SerialNumber.pSerialNumber );
|
|
break;
|
|
case MODE_SET_ADDRESS:
|
|
nSendCount += CLD_DATA::BuildCmdSetAddress( pSendBufferPtr, m_SerialNumber.pSerialNumber, m_SerialNumber.nAddress );
|
|
break;
|
|
case MODE_GET_SERIALNUMBER:
|
|
nSendCount += CLD_DATA::BuildCmdGetSerialNumber( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_SERIALNUMBER:
|
|
nSendCount += CLD_DATA::BuildCmdSetSerialNumber( pSendBufferPtr, GetAddress(), m_SerialNumber.pSerialNumber );
|
|
break;
|
|
case MODE_GET_SOFTWAREVERSION:
|
|
nSendCount += CLD_DATA::BuildCmdGetSoftwareVersion( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_RESET:
|
|
nSendCount += CLD_DATA::BuildCmdReset( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_GET_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdGetParameters( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdSetParameters( pSendBufferPtr, GetAddress(), m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
|
|
break;
|
|
case MODE_GET_RELAY_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdGetRelayParameters( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_RELAY_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdSetRelayParameters( pSendBufferPtr, GetAddress(), m_RelayParameters.bEnable, m_RelayParameters.bInvert );
|
|
break;
|
|
case MODE_GET_BORDER:
|
|
nSendCount += CLD_DATA::BuildCmdGetBorder( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_GET_TEMPERATURE:
|
|
nSendCount += CLD_DATA::BuildCmdGetTemperature( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_GET_TEMPERATURE_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdGetTemperatureParameters( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_TEMPERATURE_PARAMETERS:
|
|
nSendCount += CLD_DATA::BuildCmdSetTemperatureParameters( pSendBufferPtr, GetAddress(), CLD_DATA::ValueToTemperature( m_TemperatureParameters.dTemperature ) );
|
|
break;
|
|
case MODE_GET_CALIBRATION_TABLE:
|
|
nSendCount += CLD_DATA::BuildCmdGetCalibrationTable( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_CALIBRATION_TABLE:
|
|
nSendCount += CLD_DATA::BuildCmdSetCalibrationTable( pSendBufferPtr, GetAddress(), m_CalibrationTable.pItem, m_CalibrationTable.nCount );
|
|
break;
|
|
case MODE_GET_HZ_TABLE:
|
|
nSendCount += CLD_DATA::BuildCmdGetHzTable( pSendBufferPtr, GetAddress() );
|
|
break;
|
|
case MODE_SET_HZ_TABLE:
|
|
nSendCount += CLD_DATA::BuildCmdSetHzTable( pSendBufferPtr, GetAddress(), m_HzTable.pItem, m_HzTable.nCount );
|
|
break;
|
|
}
|
|
|
|
// request/reply transaction
|
|
BOOL bValid = FALSE;
|
|
PBYTE pReadBuffer = NULL;
|
|
INT nReadCount = 0;
|
|
BOOL bTransaction = pProtocol->Write( pSendBuffer, nSendCount, 1000UL, TRUE ) &&
|
|
pProtocol->Read( &pReadBuffer, &nReadCount, 100UL, TRUE );
|
|
if( !bTransaction )
|
|
{
|
|
// notify about error
|
|
m_OutMsg.BuildEvtCommunicationError( 1 );
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
|
|
// check connection counter
|
|
if( m_bConnectionFisrtTime || m_bConnected )
|
|
{
|
|
if( m_nConnectionFaults <= MAX_CONNECTION_FAULTS )
|
|
m_nConnectionFaults++;
|
|
else
|
|
{
|
|
m_bConnectionFisrtTime = FALSE;
|
|
m_bConnected = FALSE;
|
|
// send event
|
|
m_OutMsg.BuildEvtConnection( FALSE );
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
}
|
|
}
|
|
/*
|
|
static DWORD dwTime = 0;
|
|
if( GetTickCount() - dwTime > 1000 )
|
|
{
|
|
double dRange = CLD_DATA::RangeToValue( rand() % 1024 );
|
|
|
|
dwTime = GetTickCount();
|
|
m_OutMsg.BuildEvtAlarm( dRange );
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("CLgNetDeviceCLD::DeviceProc"), _T("Test %0.1f"), dRange );
|
|
}
|
|
*/
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_WARNING, this, _T("CLgNetDeviceCLD::DeviceProc"), _T("Transaction failed") );
|
|
}
|
|
else
|
|
{
|
|
// mark that connection is ok
|
|
if( m_bConnectionFisrtTime || !m_bConnected )
|
|
{
|
|
m_bConnectionFisrtTime = FALSE;
|
|
m_bConnected = TRUE;
|
|
// send event
|
|
m_OutMsg.BuildEvtConnection( TRUE );
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
}
|
|
// each time update connection faults meter
|
|
m_nConnectionFaults = 0;
|
|
|
|
// check addressing
|
|
if( nReadCount && ((GetAddress() == *pReadBuffer) || (CLD_DATA::EXCLUSIVE_ADDRESS == *pReadBuffer) ) )
|
|
{
|
|
// skip address byte
|
|
pReadBuffer++;
|
|
nReadCount--;
|
|
|
|
// if exist command data
|
|
if( nReadCount-- )
|
|
{
|
|
BYTE bCommand = *pReadBuffer++;
|
|
|
|
// command should be according to current mode
|
|
switch( m_nMode )
|
|
{
|
|
case MODE_DETECTOR: if( bCommand == CLD_DATA::CMD_GET_STATE ) bValid = TRUE; break;
|
|
case MODE_CHANGE_ADDRESS: if( bCommand == CLD_DATA::CMD_CHANGE_ADDRESS ) bValid = TRUE; break;
|
|
case MODE_GET_ADDRESS: if( bCommand == CLD_DATA::CMD_GET_ADDRESS ) bValid = TRUE; break;
|
|
case MODE_SET_ADDRESS: if( bCommand == CLD_DATA::CMD_SET_ADDRESS ) bValid = TRUE; break;
|
|
case MODE_GET_SERIALNUMBER: if( bCommand == CLD_DATA::CMD_GET_SERIALNUMBER ) bValid = TRUE; break;
|
|
case MODE_SET_SERIALNUMBER: if( bCommand == CLD_DATA::CMD_SET_SERIALNUMBER ) bValid = TRUE; break;
|
|
case MODE_GET_SOFTWAREVERSION: if( bCommand == CLD_DATA::CMD_GET_SOFTWAREVERSION ) bValid = TRUE; break;
|
|
case MODE_RESET: if( bCommand == CLD_DATA::CMD_RESET ) bValid = TRUE; break;
|
|
case MODE_GET_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_SET_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_GET_BORDER: if( bCommand == CLD_DATA::CMD_GET_BORDER ) bValid = TRUE; break;
|
|
case MODE_GET_RELAY_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_RELAY_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_SET_RELAY_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_RELAY_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_GET_TEMPERATURE: if( bCommand == CLD_DATA::CMD_GET_TEMPERATURE ) bValid = TRUE; break;
|
|
case MODE_SET_TEMPERATURE_PARAMETERS: if( bCommand == CLD_DATA::CMD_SET_TEMPERATURE_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_GET_TEMPERATURE_PARAMETERS: if( bCommand == CLD_DATA::CMD_GET_TEMPERATURE_PARAMETERS ) bValid = TRUE; break;
|
|
case MODE_SET_CALIBRATION_TABLE: if( bCommand == CLD_DATA::CMD_SET_CALIBRATION_TABLE ) bValid = TRUE; break;
|
|
case MODE_GET_CALIBRATION_TABLE: if( bCommand == CLD_DATA::CMD_GET_CALIBRATION_TABLE ) bValid = TRUE; break;
|
|
case MODE_SET_HZ_TABLE: if( bCommand == CLD_DATA::CMD_SET_HZ_TABLE ) bValid = TRUE; break;
|
|
case MODE_GET_HZ_TABLE: if( bCommand == CLD_DATA::CMD_GET_HZ_TABLE ) bValid = TRUE; break;
|
|
}
|
|
|
|
// if reply is valid for current mode
|
|
if( bValid )
|
|
{
|
|
BOOL bEvent = TRUE;
|
|
BOOL bAlarm, bError, bTest;
|
|
WORD wRange, wValue;
|
|
BYTE bErrorID, bNewAddress, pSerialNumber[8], pSoftwareVersion[9];
|
|
WORD wMin, wMax;
|
|
WORD wTemperature;
|
|
switch( m_nMode )
|
|
{
|
|
case MODE_DETECTOR:
|
|
nReadCount -= CLD_DATA::GetEvtGetState( pReadBuffer, &bAlarm, &wRange, &bError, &bErrorID, &bTest, &wValue );
|
|
if( bAlarm || bError || bTest )
|
|
{
|
|
if( bTest )
|
|
m_OutMsg.BuildEvtTest( wValue );
|
|
if( bAlarm )
|
|
m_OutMsg.BuildEvtAlarm( CLD_DATA::RangeToValue( wRange ) );
|
|
if( bError )
|
|
m_OutMsg.BuildEvtError( bErrorID );
|
|
}
|
|
else
|
|
bEvent = FALSE;
|
|
break;
|
|
|
|
case MODE_CHANGE_ADDRESS:
|
|
nReadCount -= CLD_DATA::GetEvtChangeAddress( pReadBuffer, &bNewAddress );
|
|
m_OutMsg.BuildEvtChangeAddress( bNewAddress );
|
|
break;
|
|
case MODE_GET_ADDRESS:
|
|
nReadCount -= CLD_DATA::GetEvtGetAddress( pReadBuffer, pSerialNumber, &bNewAddress );
|
|
m_OutMsg.BuildEvtGetAddress( pSerialNumber, bNewAddress );
|
|
break;
|
|
case MODE_SET_ADDRESS:
|
|
nReadCount -= CLD_DATA::GetEvtSetAddress( pReadBuffer, pSerialNumber, &bNewAddress );
|
|
m_OutMsg.BuildEvtSetAddress( pSerialNumber, bNewAddress );
|
|
break;
|
|
case MODE_GET_SERIALNUMBER:
|
|
nReadCount -= CLD_DATA::GetEvtGetSerialNumber( pReadBuffer, pSerialNumber );
|
|
m_OutMsg.BuildEvtGetSerialNumber( pSerialNumber );
|
|
break;
|
|
case MODE_SET_SERIALNUMBER:
|
|
nReadCount -= CLD_DATA::GetEvtSetSerialNumber( pReadBuffer, pSerialNumber );
|
|
m_OutMsg.BuildEvtSetSerialNumber( pSerialNumber );
|
|
break;
|
|
case MODE_GET_SOFTWAREVERSION:
|
|
nReadCount -= CLD_DATA::GetEvtGetSoftwareVersion( pReadBuffer, pSoftwareVersion );
|
|
m_OutMsg.BuildEvtGetSoftwareVersion( pSoftwareVersion );
|
|
break;
|
|
case MODE_RESET:
|
|
m_OutMsg.BuildEvtReset();
|
|
break;
|
|
case MODE_GET_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtGetParameters( pReadBuffer, &m_Parameters.nOffset, &m_Parameters.nWidth, &m_Parameters.nFlip );
|
|
m_OutMsg.BuildEvtGetParameters( m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
|
|
break;
|
|
case MODE_SET_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtSetParameters( pReadBuffer, &m_Parameters.nOffset, &m_Parameters.nWidth, &m_Parameters.nFlip );
|
|
m_OutMsg.BuildEvtSetParameters( m_Parameters.nOffset, m_Parameters.nWidth, m_Parameters.nFlip );
|
|
break;
|
|
case MODE_GET_RELAY_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtGetRelayParameters( pReadBuffer, &m_RelayParameters.bEnable, &m_RelayParameters.bInvert );
|
|
m_OutMsg.BuildEvtGetRelayParameters( m_RelayParameters.bEnable, m_RelayParameters.bInvert );
|
|
break;
|
|
case MODE_SET_RELAY_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtSetRelayParameters( pReadBuffer, &m_RelayParameters.bEnable, &m_RelayParameters.bInvert );
|
|
m_OutMsg.BuildEvtSetRelayParameters( m_RelayParameters.bEnable, m_RelayParameters.bInvert );
|
|
break;
|
|
case MODE_GET_BORDER:
|
|
nReadCount -= CLD_DATA::GetEvtGetBorder( pReadBuffer, &wMin, &wMax );
|
|
m_OutMsg.BuildEvtGetBorder( CLD_DATA::RangeToValue( wMin ), CLD_DATA::RangeToValue( wMax ) );
|
|
break;
|
|
case MODE_GET_TEMPERATURE:
|
|
nReadCount -= CLD_DATA::GetEvtGetTemperature( pReadBuffer, &wTemperature );
|
|
m_OutMsg.BuildEvtGetTemperature( CLD_DATA::TemperatureToValue( wTemperature ) );
|
|
break;
|
|
case MODE_GET_TEMPERATURE_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtGetTemperatureParameters( pReadBuffer, &wTemperature );
|
|
m_TemperatureParameters.dTemperature = CLD_DATA::TemperatureToValue( wTemperature );
|
|
m_OutMsg.BuildEvtGetTemperatureParameters( &m_TemperatureParameters );
|
|
break;
|
|
case MODE_SET_TEMPERATURE_PARAMETERS:
|
|
nReadCount -= CLD_DATA::GetEvtSetTemperatureParameters( pReadBuffer, &wTemperature );
|
|
m_TemperatureParameters.dTemperature = CLD_DATA::TemperatureToValue( wTemperature );
|
|
m_OutMsg.BuildEvtSetTemperatureParameters( &m_TemperatureParameters );
|
|
break;
|
|
case MODE_GET_CALIBRATION_TABLE:
|
|
nReadCount -= CLD_DATA::GetEvtGetCalibrationTable( pReadBuffer, m_CalibrationTable.pItem, &m_CalibrationTable.nCount );
|
|
m_OutMsg.BuildEvtGetCalibrationTable( &m_CalibrationTable );
|
|
break;
|
|
case MODE_SET_CALIBRATION_TABLE:
|
|
nReadCount -= CLD_DATA::GetEvtGetCalibrationTable( pReadBuffer, m_CalibrationTable.pItem, &m_CalibrationTable.nCount );
|
|
m_OutMsg.BuildEvtSetCalibrationTable( &m_CalibrationTable );
|
|
break;
|
|
case MODE_GET_HZ_TABLE:
|
|
nReadCount -= CLD_DATA::GetEvtGetHzTable( pReadBuffer, m_HzTable.pItem, &m_HzTable.nCount );
|
|
m_OutMsg.BuildEvtGetHzTable( &m_HzTable );
|
|
break;
|
|
case MODE_SET_HZ_TABLE:
|
|
nReadCount -= CLD_DATA::GetEvtGetHzTable( pReadBuffer, m_HzTable.pItem, &m_HzTable.nCount );
|
|
m_OutMsg.BuildEvtSetHzTable( &m_HzTable );
|
|
break;
|
|
}
|
|
|
|
// send response
|
|
if( bEvent )
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
|
|
// mark as ready for new message
|
|
m_bReadyForNewMessage = TRUE;
|
|
|
|
// set default work mode
|
|
m_nMode = MODE_DETECTOR;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// update retry counter
|
|
m_nRetryCount = bValid ? 0 : ++m_nRetryCount;
|
|
|
|
// check retry counter
|
|
if( m_nRetryCount > MAX_RETRY_COUNT )
|
|
{
|
|
/*
|
|
need to rewrite !!!!!!! 2003/04/13
|
|
switch( m_nMode )
|
|
{
|
|
case MODE_DETECTOR: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_STATE ); break;
|
|
case MODE_CHANGE_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_CHANGE_ADDRESS ); break;
|
|
case MODE_GET_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_ADDRESS ); break;
|
|
case MODE_SET_ADDRESS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_ADDRESS ); break;
|
|
case MODE_GET_SERIALNUMBER: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_SERIALNUMBER ); break;
|
|
case MODE_SET_SERIALNUMBER: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_SERIALNUMBER ); break;
|
|
case MODE_GET_SOFTWAREVERSION: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_SOFTWAREVERSION ); break;
|
|
case MODE_RESET: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_RESET ); break;
|
|
case MODE_GET_PARAMETERS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_GET_PARAMETERS ); break;
|
|
case MODE_SET_PARAMETERS: m_OutMsg.BuildEvtCmdError( CLD_DATA::CMD_SET_PARAMETERS ); break;
|
|
}
|
|
|
|
// send response
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
*/
|
|
// mark as ready for new message
|
|
m_bReadyForNewMessage = TRUE;
|
|
|
|
// set default work mode
|
|
m_nMode = MODE_DETECTOR;
|
|
|
|
// reset retry counter
|
|
m_nRetryCount = 0;
|
|
}
|
|
|
|
return bTransaction;
|
|
}
|
|
|
|
void CLgNetDeviceCLD::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
|
|
{
|
|
va_list marker;
|
|
va_start( marker, pFormat );
|
|
m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
|
|
va_end( marker );
|
|
CLgNetObject::SendMessageToParent( m_OutMsg );
|
|
}
|
|
|