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.
175 lines
4.8 KiB
175 lines
4.8 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgNetDeviceGPIOPCI1762.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgNetDeviceGPIOPCI1762.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgNetDeviceGPIOPCI1762.h"
|
|
|
|
CLgNetDeviceGPIOPCI1762::CLgNetDeviceGPIOPCI1762()
|
|
{
|
|
|
|
}
|
|
|
|
CLgNetDeviceGPIOPCI1762::~CLgNetDeviceGPIOPCI1762()
|
|
{
|
|
// nessesary to do it, because "vtable" will be cleared before
|
|
// parent's destructor will be called
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CLgNetDeviceGPIOPCI1762::Create( INT nDevice )
|
|
{
|
|
if( !CLgDeviceGPIOPCI1762::Create( nDevice ) )
|
|
return FALSE;
|
|
|
|
// CLgNetDevice::SetID( 1 );
|
|
|
|
m_OutMsg.SetSenderID( CLgNetDevice::GetID() );
|
|
|
|
return CLgThread::Start( FALSE );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::Destroy()
|
|
{
|
|
CLgThread::Stop( TRUE );
|
|
}
|
|
|
|
DWORD CLgNetDeviceGPIOPCI1762::ThreadProc()
|
|
{
|
|
BOOL bLoop = TRUE;
|
|
while( bLoop )
|
|
{
|
|
// as fast as possible but without overheating :)
|
|
switch( ::WaitForSingleObject( CLgThread::GetThreadStopEvent(), 0UL ) )
|
|
{
|
|
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 );
|
|
else
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgNetDeviceGPIOPCI1762::ThreadProc"), _T("m_InMsg.GetInput failed") );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::CMD_GET_INPUT_ALL:
|
|
CmdGetInputAll();
|
|
break;
|
|
default:
|
|
OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// call port processing routine
|
|
ReadWriteProc( 1UL );
|
|
}
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtGetOutput( INT nOutput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtGetOutput( nOutput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetOutput", "%d,%d", nOutput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtSetOutput( INT nOutput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtSetOutput( nOutput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtSetOutput", "%d,%d", nOutput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtGetInput( INT nInput, BOOL bOn )
|
|
{
|
|
m_OutMsg.BuildEvtGetInput( nInput, bOn );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetInput", "%d,%d", nInput, bOn );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtInputChange( INT nInput, BOOL bOn )
|
|
{
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtInputChange", "%d,%d", nInput, bOn );
|
|
|
|
m_OutMsg.BuildEvtInputChange( nInput, bOn );
|
|
if( !SendMessageToParent( m_OutMsg ) )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgNetDeviceGPIOPCI1762::OnEvtInputChange", "Cant' send event" );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtGetOutputAll( PGPIO_PINS pPins )
|
|
{
|
|
m_OutMsg.BuildEvtGetOutputAll( pPins );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetOutputAll" );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::OnEvtGetInputAll( PGPIO_PINS pPins )
|
|
{
|
|
m_OutMsg.BuildEvtGetInputAll( pPins );
|
|
SendMessageToParent( m_OutMsg );
|
|
|
|
LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDeviceGPIOPCI1762::OnEvtGetInputAll" );
|
|
}
|
|
|
|
void CLgNetDeviceGPIOPCI1762::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, "CLgNetDeviceGPIOPCI1762::OnEvtCommandError" );
|
|
}
|
|
|