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.
180 lines
5.5 KiB
180 lines
5.5 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: DevicePCI1762.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of DevicePCI1762.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ObjectFactory.h"
|
|
#include "DevicePCI1762.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
CDevicePCI1762::CDevicePCI1762()
|
|
{
|
|
SetDeviceType( OFNS::DT_PCI_1762 );
|
|
|
|
CDeviceDI::SetCount( 16 );
|
|
CDeviceDO::SetCount( 16 );
|
|
|
|
for( INT i = 0; i < 16; i++ )
|
|
{
|
|
OUTPUT_STATE state;
|
|
state.bOn = FALSE;
|
|
state.bFirstTime = TRUE;
|
|
if( !m_OutputState.Add( state ) )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::CDevicePCI1762"), _T("Can't add output state") );
|
|
}
|
|
|
|
ObjectToParentLinkSP::Link( &m_MsgSink );
|
|
m_MsgSink.ObjectToChildLinkP::Link( this );
|
|
|
|
m_Msg.SetDistinationID( GetID() );
|
|
m_Msg.SetSenderID( m_MsgSink.GetID() );
|
|
m_Msg.BuildCmdGetInputAll();
|
|
PushMessage( m_Msg );
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::CDevicePCI1762") );
|
|
}
|
|
|
|
CDevicePCI1762::~CDevicePCI1762()
|
|
{
|
|
ObjectToParentLinkSP::Unlink();
|
|
|
|
CLgNetDeviceGPIOPCI1762::Destroy();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::~CDevicePCI1762") );
|
|
}
|
|
|
|
BOOL CDevicePCI1762::ReadWriteProc( DWORD dwTimeout )
|
|
{
|
|
BOOL bResult = CLgNetDeviceGPIOPCI1762::ReadWriteProc( dwTimeout );
|
|
|
|
LGLOG( LOG_LEVEL_REALTIME, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc") );
|
|
|
|
CLgNetMessageGPIO InMsg;
|
|
while( m_MsgSink.PopMessage( InMsg ) )
|
|
{
|
|
BYTE bCommand;
|
|
if( !InMsg.GetCommand( &bCommand ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("InMsg.GetCommand failed") );
|
|
continue;
|
|
}
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received event") );
|
|
|
|
CLgDeviceGPIO::GPIO_PIN pinDI;
|
|
CLgDeviceGPIO::PGPIO_PINS pPinsDI;
|
|
CLgDeviceGPIO::GPIO_PIN pin;
|
|
|
|
switch( bCommand )
|
|
{
|
|
case CLgDeviceGPIO::EVT_SET_OUTPUT:
|
|
if( !InMsg.GetOutput( &pin ) )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("InMsg.GetOutput failed") );
|
|
else
|
|
{
|
|
if( pin.nIndex < 0 || pin.nIndex >= m_OutputState.GetCount() )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("CLgDeviceGPIO::EVT_SET_OUTPUT: pin index is %d"), pin.nIndex );
|
|
else
|
|
{
|
|
m_OutputState[pin.nIndex].bOn = pin.bOn;
|
|
m_OutputState[pin.nIndex].bFirstTime = FALSE;
|
|
}
|
|
}
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_SET_OUTPUT") );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::EVT_GET_OUTPUT:
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_GET_OUTPUT") );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::EVT_GET_OUTPUT_ALL:
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received EVT_GET_OUTPUT_ALL") );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::EVT_GET_INPUT:
|
|
if( InMsg.GetInput( &pinDI ) )
|
|
CDeviceDI::SetBit( pinDI.nIndex, pinDI.bOn );
|
|
break;
|
|
|
|
case CLgDeviceGPIO::EVT_GET_INPUT_ALL:
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received CLgDeviceGPIO::EVT_GET_INPUT_ALL") );
|
|
if( ( pPinsDI = InMsg.GetInputPins() ) )
|
|
for( INT i = 0; i < pPinsDI->nCount; i++ )
|
|
CDeviceDI::SetBit( pPinsDI->pPin[i].nIndex, pPinsDI->pPin[i].bOn );
|
|
}
|
|
|
|
break;
|
|
|
|
case CLgDeviceGPIO::EVT_INPUT_CHANGE:
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received CLgDeviceGPIO::EVT_INPUT_CHANGE") );
|
|
if( InMsg.GetInput( &pinDI ) )
|
|
CDeviceDI::SetBit( pinDI.nIndex, pinDI.bOn );
|
|
}
|
|
break;
|
|
|
|
default:
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("received unknown command") );
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
m_Msg.SetDistinationID( GetID() );
|
|
m_Msg.SetSenderID( m_MsgSink.GetID() );
|
|
|
|
DDOEVENT ddoe;
|
|
while( CDeviceDO::m_Queue.Pop( ddoe ) )
|
|
{
|
|
switch( ddoe.id )
|
|
{
|
|
case DDOC_GET_STATE:
|
|
if( !m_Msg.BuildCmdGetOutputAll() )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdGetOutputAll failed") );
|
|
else
|
|
PushMessage( m_Msg );
|
|
break;
|
|
|
|
case DDOC_SET_SWITCH:
|
|
if( ddoe.nBit < 0 || ddoe.nBit >= m_OutputState.GetCount() )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("DDOC_SET_SWITCH: pin index is %d"), ddoe.nBit );
|
|
else
|
|
if( m_OutputState[ddoe.nBit].bFirstTime || m_OutputState[ddoe.nBit].bOn != ddoe.bOn )
|
|
{
|
|
if( !m_Msg.BuildCmdSetOutput( ddoe.nBit, ddoe.bOn ) )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdSetOutput failed") );
|
|
else
|
|
PushMessage( m_Msg );
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
DDIEVENT ddie;
|
|
while( CDeviceDI::m_Queue.Pop( ddie ) )
|
|
{
|
|
switch( ddie.id )
|
|
{
|
|
case DDIC_GET_STATE:
|
|
if( !m_Msg.BuildCmdGetInputAll() )
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CDevicePCI1762::ReadWriteProc"), _T("m_Msg.BuildCmdGetInputAll failed") );
|
|
else
|
|
PushMessage( m_Msg );
|
|
break;
|
|
case DDIC_ENABLE:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return bResult;
|
|
}
|