Old fashion design for PC-104
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.
 
 
 
 
 

267 lines
7.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: LgNetDevicePTZHebron.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of LgNetDevicePTZHebron.cpp
//----------------------------------------------------------------------------
#include "stdafx.h"
#include "LgNetDevicePTZHebron.h"
#include "LgNetDeviceMD.h"
#include "LgNetSocketMD.h"
CLgNetDevicePTZHebron::CLgNetDevicePTZHebron()
{
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::CLgNetDevicePTZHebron") );
}
CLgNetDevicePTZHebron::~CLgNetDevicePTZHebron()
{
// nessesary to do it, because "vtable" will be cleared before
// parent's destructor will be called
CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::Unlink();
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::~CLgNetDevicePTZHebron") );
}
BOOL CLgNetDevicePTZHebron::Link( CLgLink<CLgNetObject,CLgNetObject,CLgNetObjectChild> *pLink )
{
if( !CLgNetDevice::Link( pLink ) )
return FALSE;
m_OutMsg.SetDistinationID( pLink->GetThis()->GetID() );
return TRUE;
}
void CLgNetDevicePTZHebron::OnEvtGetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
{
m_OutMsg.BuildEvtGetPTZ( dPan, dTilt, dZoom );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtSetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
{
m_OutMsg.BuildEvtSetPTZ( dPan, dTilt, dZoom );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtMoveTilt( BOOL bUp, PTZ_PERCENT dSpeed )
{
m_OutMsg.BuildEvtMoveTilt( bUp, dSpeed );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtMovePan( BOOL bRight, PTZ_PERCENT dSpeed )
{
m_OutMsg.BuildEvtMovePan( bRight, dSpeed );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtMoveZoom( BOOL bTele, PTZ_PERCENT dSpeed )
{
m_OutMsg.BuildEvtMoveZoom( bTele, dSpeed );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtMoveFocus( BOOL bFar, PTZ_PERCENT dSpeed )
{
m_OutMsg.BuildEvtMoveFocus( bFar, dSpeed );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtSetIris( PTZ_PERCENT dIris )
{
m_OutMsg.BuildEvtSetIris( dIris );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtSetFocus( PTZ_PERCENT dFocus )
{
m_OutMsg.BuildEvtSetFocus( dFocus );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtGetFocus( PTZ_PERCENT dFocus )
{
m_OutMsg.BuildEvtGetFocus( dFocus );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtWiper( BOOL bOn )
{
m_OutMsg.BuildEvtWiper( bOn );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtInit()
{
m_OutMsg.BuildEvtInit();
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtSetDopler( BOOL bEnable, PTZ_DEGREE dPanStep, DWORD dwTimeout )
{
m_OutMsg.BuildEvtSetDopler( bEnable, dPanStep, dwTimeout );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtGetDopler( BOOL bEnable, PTZ_DEGREE dPanStep, DWORD dwTimeout )
{
m_OutMsg.BuildEvtGetDopler( bEnable, dPanStep, dwTimeout );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtDoplerAlarm( BOOL bAlarm, PTZ_DEGREE dPan )
{
m_OutMsg.BuildEvtDoplerAlarm( bAlarm, dPan );
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtSetDoplerMask( PDOPLER_MASK_ARRAY pMask )
{
m_OutMsg.BuildEvtSetDoplerMask( pMask);
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::OnEvtGetDoplerMask( PDOPLER_MASK_ARRAY pMask )
{
m_OutMsg.BuildEvtGetDoplerMask( pMask);
SendMessageToParent( m_OutMsg );
}
void CLgNetDevicePTZHebron::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, "CLgNetDevicePTZHebron::OnEvtCommandError" );
}
BOOL CLgNetDevicePTZHebron::SetBaudrate( DWORD nBaudRate )
{
// protect link
CLgLocker Lock( &CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::GetLock() );
// if no socket it is an error!!!
CLgNetSocketMD *pSocket = static_cast<CLgNetSocketMD*>(CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::GetLinkThis());
if( !pSocket )
return FALSE;
return pSocket->SetBaudrate( nBaudRate );
}
BOOL CLgNetDevicePTZHebron::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
{
BOOL bResult = FALSE;
__try
{
bResult = DeviceProc_( pSocket, pProtocol );
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::DeviceProc"), _T("Exception 0x%08X"), _exception_code() );
}
return bResult;
}
BOOL CLgNetDevicePTZHebron::DeviceProc_( CLgNetSocket *pSocket, CProtocol *pProtocol )
{
// cast to related protocol
CProtocolLGS *pProtocolLGS = (CProtocolLGS*) pProtocol;
// check input command
if( CLgDevicePTZHebron::IsReadyForCmd() && CLgNetObject::PopMessage( m_InMsg ) )
{
m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
m_OutMsg.SetSenderID( GetID() );
// depend on command
BYTE bCommand;
if( m_InMsg.GetCommand( &bCommand ) )
{
PTZ_POSITION pos;
PTZ_PAN pan;
PTZ_TILT tilt;
PTZ_ZOOM zoom;
PTZ_PERCENT iris;
PTZ_PERCENT focus;
DOPLER dopler;
DOPLER_MASK_ARRAY mask;
switch( bCommand )
{
case CLgDevicePTZHebron::CMD_GET_PTZ:
CmdGetPTZ();
break;
case CLgDevicePTZHebron::CMD_SET_PTZ:
if( m_InMsg.GetPTZ( &pos ) )
CmdSetPTZ( pos.dPan, pos.dTilt, pos.dZoom );
break;
case CLgDevicePTZHebron::CMD_MOVE_TILT:
if( m_InMsg.GetTilt( &tilt ) )
CmdMoveTilt( tilt.bUp, tilt.dSpeed );
break;
case CLgDevicePTZHebron::CMD_MOVE_PAN:
if( m_InMsg.GetPan( &pan ) )
CmdMovePan( pan.bRight, pan.dSpeed );
break;
case CLgDevicePTZHebron::CMD_MOVE_ZOOM:
if( m_InMsg.GetZoom( &zoom ) )
CmdMoveZoom( zoom.bTele, zoom.dSpeed );
break;
case CLgDevicePTZHebron::CMD_SET_IRIS:
if( m_InMsg.GetIris( &iris ) )
CmdSetIris( iris );
break;
case CLgDevicePTZHebron::CMD_SET_FOCUS:
if( m_InMsg.GetFocus( &focus ) )
CmdSetFocus( focus );
break;
case CLgDevicePTZHebron::CMD_GET_FOCUS:
CmdGetFocus();
break;
case CLgDevicePTZHebron::CMD_SET_DOPLER:
if( m_InMsg.GetDopler( &dopler ) )
CmdSetDopler( dopler.bEnable, dopler.dPanStep, dopler.dwTimeout );
break;
case CLgDevicePTZHebron::CMD_SET_DOPLER_MASK:
if( m_InMsg.GetDoplerMask( &mask ) )
CmdSetDoplerMask( &mask );
break;
case CLgDevicePTZHebron::CMD_GET_DOPLER_MASK:
CmdGetDoplerMask();
break;
case CLgDevicePTZHebron::CMD_GET_DOPLER:
CmdGetDopler();
break;
default:
OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
break;
}
}
}
// write command
LONG lTimeout = 0L;
BOOL bRead = WriteProc( pProtocolLGS, &lTimeout );
// read responce if nessessary
if( bRead )
bRead = ReadProc( pProtocolLGS, lTimeout, TRUE );
else
{
bRead = TRUE;
::Sleep( lTimeout );
}
return bRead;
}