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.
174 lines
4.6 KiB
174 lines
4.6 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgNetDeviceGPIOCOM.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgNetDeviceGPIOCOM.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgNetDeviceGPIOCOM.h"
|
|
|
|
CLgNetDeviceGPIOCOM::CLgNetDeviceGPIOCOM()
|
|
{
|
|
|
|
}
|
|
|
|
CLgNetDeviceGPIOCOM::~CLgNetDeviceGPIOCOM()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CLgNetDeviceGPIOCOM::Create( LPCTSTR pPort, BOOL bSelfTest, INT nSelfTestTimeout )
|
|
{
|
|
if( !CLgDeviceGPIOCOM::Create( pPort, bSelfTest, nSelfTestTimeout ) )
|
|
return FALSE;
|
|
|
|
// CLgNetDevice::SetID( 1 );
|
|
m_OutMsg.SetSenderID( CLgNetDevice::GetID() );
|
|
|
|
// attach to itself
|
|
return CLgThread::Start( FALSE );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::Destroy()
|
|
{
|
|
// nessesary to do it, because "vtable" will be cleared before
|
|
// parent's destructor will be called
|
|
CLgThread::Stop( TRUE );
|
|
CLgDeviceGPIOCOM::Destroy();
|
|
}
|
|
|
|
DWORD CLgNetDeviceGPIOCOM::ThreadProc()
|
|
{
|
|
BOOL bLoop = TRUE;
|
|
while( bLoop )
|
|
{
|
|
// as fast as possible but without overheating :)
|
|
switch( ::WaitForSingleObject( CLgThread::GetThreadStopEvent(), 1UL ) )
|
|
{
|
|
default:
|
|
case WAIT_FAILED:
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetDeviceGPIOCOM::ThreadProc"), _T("WaitForSingleObject failed with 0x%08X"), ::GetLastError() );
|
|
|
|
case WAIT_OBJECT_0:
|
|
bLoop = FALSE;
|
|
continue;
|
|
|
|
case WAIT_TIMEOUT:
|
|
break;
|
|
}
|
|
|
|
// check input command
|
|
if( CLgDevice::IsReadyForCmd() && CLgNetDevice::PopMessage( m_InMsg ) )
|
|
{
|
|
m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
|
|
|
|
// depend on command
|
|
BYTE bCommand;
|
|
if( m_InMsg.GetCommand( &bCommand ) )
|
|
{
|
|
CLgDeviceGPIO::GPIO_PIN pin;
|
|
switch( bCommand )
|
|
{
|
|
case CLgDeviceGPIO::CMD_GET_OUTPUT:
|
|
if( m_InMsg.GetOutput( &pin ) )
|
|
CmdGetOutput( pin.nIndex );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::CMD_GET_OUTPUT_ALL:
|
|
CmdGetOutputAll();
|
|
break;
|
|
|
|
case CLgDeviceGPIO::CMD_SET_OUTPUT:
|
|
if( m_InMsg.GetOutput( &pin ) )
|
|
CmdSetOutput( pin.nIndex, pin.bOn );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::CMD_GET_INPUT:
|
|
if( m_InMsg.GetInput( &pin ) )
|
|
CmdGetInput( pin.nIndex );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::CMD_GET_INPUT_ALL:
|
|
CmdGetInputAll();
|
|
break;
|
|
|
|
default:
|
|
OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// call port processing routine
|
|
CLgDeviceGPIOCOM::ReadWriteProc();
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtGetOutput( INT nOutput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtGetOutput( nOutput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtGetOutput", "%d,%d", nOutput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtSetOutput( INT nOutput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtSetOutput( nOutput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtSetOutput", "%d,%d", nOutput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtGetInput( INT nInput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtGetInput( nInput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtGetInput", "%d,%d", nInput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtInputChange( INT nInput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtInputChange( nInput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtInputChange", "%d,%d", nInput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtGetOutputAll( PGPIO_PINS pPins )
|
|
{
|
|
m_OutMsg.BuildEvtGetOutputAll( pPins );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtGetOutputAll" );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::OnEvtGetInputAll( PGPIO_PINS pPins )
|
|
{
|
|
m_OutMsg.BuildEvtGetInputAll( pPins );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtGetInputAll" );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOCOM::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 );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOCOM::OnEvtCommandError" );
|
|
}
|
|
|