For DOS Protected Mode version of sensor core software
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.
 
 
 
 

109 lines
2.4 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: RELAY.CPP
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of RELAY.CPP
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "relay.h"
void CRelay::OnProtocolLgsRelayCommand( PBYTE pReadBuffer, int16_t& nReadCount, PBYTE pSendBuffer, int16_t& nSendCount )
{
// input command parsing
LGS::RELAY_DATA InData;
// translate Relay command
nReadCount -= LGS::GetCmdRelay( pReadBuffer, &InData );
// prepare output Relay data
LGS::RELAY_DATA OutData;
// depend on command
switch( InData.nCommand )
{
case LGS::CMD_RELAY_GET:
break;
case LGS::CMD_RELAY_SET:
m_bOutput = InData.bOutput;
SetRelay( InData.nCommand );
break;
}
// send reply
OutData.nCommand = InData.nCommand;
OutData.bOutput = m_bOutput;
nSendCount += LGS::BuildEvtRelay( pSendBuffer, &OutData );
}
//#define __RELAY__TEST__BY__TOGGLE__
void CRelay::validate( uint64_t nTimer ){
// if Relay in auto mode
if( !m_RelayParameters.bAuto ) return;
#ifdef __RELAY__TEST__BY__TOGGLE__
if( nTimer - m_dwAutoDelayTime < 1000 ) return; // 1 second
m_dwAutoDelayTime = nTimer;
SetRelay( m_bOutput = !m_bOutput );
return;
#endif //__RELAY__TEST__BY__TOGGLE__
// if still old time
if( m_dwAutoDelayTime == nTimer ) return;
// update timeouts
if( m_lAutoDelayTimeout > 0 ){
m_lAutoDelayTimeout -= ( nTimer - m_dwAutoDelayTime );
} else {
// relay off
if( m_bOutput ) SetRelay( m_bOutput = false );
};
// store time
m_dwAutoDelayTime = nTimer;
};
void CRelay::Reset( void ){
// Turn Off Relay
SetRelay( m_bOutput = false );
// set timeout
m_lAutoDelayTimeout = 0;
}
void CRelay::SetRelay( bool bOn ){
#ifdef DEBUG
printf("Set R-Bit\n");
#endif
m_pBoard->SetRelayBit( bOn ? !m_RelayParameters.bNormallyClose : m_RelayParameters.bNormallyClose );
#ifdef DEBUG
printf("Done\n");
#endif
// m_pBoard->SetRelayBit( bOn );
}
void CRelay::OnTarget( int16_t, int16_t )
{
#ifdef __RELAY__TEST__BY__TOGGLE__
return;
#endif
// if Relay in auto mode
if( !m_RelayParameters.bAuto )
return;
// relay on
SetRelay( m_bOutput = true );
// set timeout
m_lAutoDelayTimeout = m_RelayParameters.nAutoDelay * 1000;//18L;
}