//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: LgNetDevicePTZTKS576.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of LgNetDevicePTZTKS576.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "..\Version.h" #include "LgNetDevicePTZTKS576.h" #include "LgNetSocketPTZTKS576.h" #define POSITION_QUALYTY 2 #define MAX_NO_REPLY_COUNT 20 #define MAX_NOT_IN_POSITION_COUNT 10 CLgNetDevicePTZTKS576::CLgNetDevicePTZTKS576() { } CLgNetDevicePTZTKS576::~CLgNetDevicePTZTKS576() { // nessesary to do it, because "vtable" will be cleared before // parent's destructor will be called CLgLinkSP::Unlink(); } void CLgNetDevicePTZTKS576::OnEvtGetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom ) { m_OutMsg.BuildEvtGetPTZ( dPan, dTilt, dZoom ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtSetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom ) { m_OutMsg.BuildEvtSetPTZ( dPan, dTilt, dZoom ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtMoveTilt( BOOL bUp, PTZ_PERCENT dSpeed ) { m_OutMsg.BuildEvtMoveTilt( bUp, dSpeed ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtMovePan( BOOL bRight, PTZ_PERCENT dSpeed ) { m_OutMsg.BuildEvtMovePan( bRight, dSpeed ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtMoveZoom( BOOL bTele, PTZ_PERCENT dSpeed ) { m_OutMsg.BuildEvtMoveZoom( bTele, dSpeed ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtMoveFocus( BOOL bFar, PTZ_PERCENT dSpeed ) { m_OutMsg.BuildEvtMoveFocus( bFar, dSpeed ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtSetIris( PTZ_PERCENT dIris ) { m_OutMsg.BuildEvtSetIris( dIris ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtSetFocus( PTZ_PERCENT dFocus ) { m_OutMsg.BuildEvtSetFocus( dFocus ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtGetFocus( PTZ_PERCENT dFocus ) { m_OutMsg.BuildEvtGetFocus( dFocus ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtInit() { m_OutMsg.BuildEvtInit(); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::OnEvtWiper( BOOL bOn ) { m_OutMsg.BuildEvtWiper( bOn ); SendMessageToParent( m_OutMsg ); } void CLgNetDevicePTZTKS576::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, "CLgNetDevicePTZTKS576::OnEvtCommandError" ); } BOOL CLgNetDevicePTZTKS576::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol ) { // cast to related protocol CProtocolPTZTKS576 *pProtocolPTZ = (CProtocolPTZTKS576*) pProtocol; // check input command if( CLgDevicePTZTKS576::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; switch( bCommand ) { case CLgDevicePTZTKS576::CMD_INIT: CmdInit(); break; case CLgDevicePTZTKS576::CMD_GET_PTZ: CmdGetPTZ(); break; case CLgDevicePTZTKS576::CMD_SET_PTZ: if( m_InMsg.GetPTZ( &pos ) ) CmdSetPTZ( pos.dPan, pos.dTilt, pos.dZoom ); break; case CLgDevicePTZTKS576::CMD_MOVE_TILT: if( m_InMsg.GetTilt( &tilt ) ) CmdMoveTilt( tilt.bUp, tilt.dSpeed ); break; case CLgDevicePTZTKS576::CMD_MOVE_PAN: if( m_InMsg.GetPan( &pan ) ) CmdMovePan( pan.bRight, pan.dSpeed ); break; case CLgDevicePTZTKS576::CMD_MOVE_ZOOM: if( m_InMsg.GetZoom( &zoom ) ) CmdMoveZoom( zoom.bTele, zoom.dSpeed ); break; case CLgDevicePTZTKS576::CMD_SET_IRIS: if( m_InMsg.GetIris( &iris ) ) CmdSetIris( iris ); break; case CLgDevicePTZTKS576::CMD_SET_FOCUS: if( m_InMsg.GetFocus( &focus ) ) CmdSetFocus( focus ); break; case CLgDevicePTZTKS576::CMD_GET_FOCUS: CmdGetFocus(); break; // case CLgDevicePTZTKS576::CMD_INIT: // CmdInit(); // break; default: OnEvtCommandError( -1, _T("UNKNOWN COMMAND") ); break; } } } // write command LONG lTimeout = 0L; BOOL bRead = WriteProc( pProtocolPTZ, &lTimeout ); // read responce if nessessary if( bRead ) bRead = ReadProc( pProtocolPTZ, lTimeout, TRUE ); else { bRead = TRUE; ::Sleep( lTimeout ); } return bRead; }