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.
107 lines
2.4 KiB
107 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, INT& nReadCount, PBYTE pSendBuffer, INT& 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::Invalidate( WORD nFastTimer, DWORD nSlowTimer )
|
|
{
|
|
// don't use fast timer
|
|
nFastTimer;
|
|
|
|
// if Relay in auto mode
|
|
if( !m_RelayParameters.bAuto )
|
|
return;
|
|
|
|
#ifdef __RELAY__TEST__BY__TOGGLE__
|
|
if( nSlowTimer - m_dwAutoDelayTime < 18 )
|
|
return;
|
|
|
|
m_dwAutoDelayTime = nSlowTimer;
|
|
SetRelay( m_bOutput = !m_bOutput );
|
|
return;
|
|
#endif //__RELAY__TEST__BY__TOGGLE__
|
|
|
|
// if still old time
|
|
if( m_dwAutoDelayTime == nSlowTimer )
|
|
return;
|
|
|
|
// update timeouts
|
|
if( m_lAutoDelayTimeout > 0 )
|
|
{
|
|
m_lAutoDelayTimeout -= (LONG)(nSlowTimer - m_dwAutoDelayTime);
|
|
}
|
|
else
|
|
{
|
|
// relay off
|
|
if( m_bOutput )
|
|
SetRelay( m_bOutput = FALSE );
|
|
}
|
|
|
|
// store time
|
|
m_dwAutoDelayTime = nSlowTimer;
|
|
}
|
|
|
|
void CRelay::SetRelay( BOOL bOn )
|
|
{
|
|
m_pBoard->SetRelayBit( bOn ? !m_RelayParameters.bNormallyClose : m_RelayParameters.bNormallyClose );
|
|
// m_pBoard->SetRelayBit( bOn );
|
|
}
|
|
|
|
void CRelay::OnTarget( INT, INT )
|
|
{
|
|
#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 * 18L;
|
|
}
|
|
|