For DOS Protected Mode version of sensor core software
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.
 
 
 
 

239 lines
5.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: LgDevPTZ.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of LgDevPTZ.cpp
//----------------------------------------------------------------------------
#include "..\stdafx.h"
#ifdef __BORLANDC__
#include "..\LgLib\Version.h"
#include "..\LgLib\Device\LgDevPTZ.h"
#else
#include "..\Version.h"
#include "LgDevPTZ.h"
#endif
CLgDevicePTZ::CLgDevicePTZ()
{
// clear commands data
memset( &m_Position, 0, sizeof( m_Position ) );
memset( &t_Position, 0, sizeof( t_Position ) );
memset( &s_Position, 0, sizeof( s_Position ) );
memset( &m_MovePan, 0, sizeof( m_MovePan ) );
memset( &m_MoveTilt, 0, sizeof( m_MoveTilt ) );
memset( &m_MoveZoom, 0, sizeof( m_MoveZoom ) );
memset( &m_MoveFocus, 0, sizeof( m_MoveFocus ) );
memset( &m_Iris, 0, sizeof( m_Iris ) );
memset( &m_Wiper, 0, sizeof( m_Wiper ) );
memset( &m_Focus, 0, sizeof( m_Focus ) );
m_nAddress = 0;
m_lTimeout = 0;
m_bRead = false;
m_dwLastTime = 0;
m_pProtocol = NULL;
}
CLgDevicePTZ::~CLgDevicePTZ()
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// commands
///////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CLgDevicePTZ::CmdGetPTZ()
{
// check availibility
return DoCmd( CMD_GET_PTZ );
}
bool CLgDevicePTZ::CmdSetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
{
// check availability
if( !DoCmd( CMD_SET_PTZ ) )
return false;
// store command data
m_Position.dPan = dPan;
m_Position.dTilt = dTilt;
m_Position.dZoom = dZoom;
return true;
}
bool CLgDevicePTZ::CmdMoveTilt( bool bUp, PTZ_PERCENT dSpeed )
{
// check availability
if( !DoCmd( CMD_MOVE_TILT ) )
return false;
// store command data
m_MoveTilt.bUp = bUp;
m_MoveTilt.dSpeed = dSpeed;
return true;
}
bool CLgDevicePTZ::CmdMovePan( bool bRight, PTZ_PERCENT dSpeed )
{
// check availability
if( !DoCmd( CMD_MOVE_PAN ) )
return false;
// store command data
m_MovePan.bRight = bRight;
m_MovePan.dSpeed = dSpeed;
return true;
}
bool CLgDevicePTZ::CmdMoveZoom( bool bTele, PTZ_PERCENT dSpeed )
{
// check availability
if( !DoCmd( CMD_MOVE_ZOOM ) )
return false;
// store command data
m_MoveZoom.bTele = bTele;
m_MoveZoom.dSpeed = dSpeed;
return true;
}
bool CLgDevicePTZ::CmdMoveFocus( bool bFar, PTZ_PERCENT dSpeed )
{
// check availability
if( !DoCmd( CMD_MOVE_FOCUS ) )
return false;
// store command data
m_MoveFocus.bFar = bFar;
m_MoveFocus.dSpeed = dSpeed;
return true;
}
bool CLgDevicePTZ::CmdSetIris( PTZ_PERCENT dIris )
{
// check availability
if( !DoCmd( CMD_SET_IRIS ) )
return false;
// store command data
m_Iris = dIris;
return true;
}
bool CLgDevicePTZ::CmdSetFocus( PTZ_PERCENT dFocus )
{
// check availability
if( !DoCmd( CMD_SET_FOCUS ) )
return false;
// store command data
m_Focus = dFocus;
return true;
}
bool CLgDevicePTZ::CmdGetFocus()
{
return DoCmd( CMD_GET_FOCUS );
}
bool CLgDevicePTZ::CmdWiper( bool bOn )
{
// check availability
if( !DoCmd( CMD_WIPER ) )
return false;
// store command data
m_Wiper = bOn;
return true;
}
bool CLgDevicePTZ::CmdSetPreset( uint8_t bPresetID ){
if( !DoCmd( CMD_SET_PRESET ) ) return false;
return true;
}
bool CLgDevicePTZ::CmdClearPreset( uint8_t bPresetID ){
if( !DoCmd( CMD_CLEAR_PRESET ) ) return false;
return true;
}
bool CLgDevicePTZ::CmdGotoPreset( uint8_t bPresetID ){
if( !DoCmd( CMD_GOTO_PRESET ) ) return false;
return true;
}
// position's quality determination
bool CLgDevicePTZ::QualifyPosition( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom, PTZ_PERCENT quality )
{
if( dPan < 0 ) dPan = -dPan;
if( dTilt < 0 ) dTilt = -dTilt;
if( dZoom < 0 ) dZoom = -dZoom;
return ( ( dPan < quality || dPan > (360-quality) ) &&
( dTilt < quality || dTilt > (360-quality) ) &&
( dZoom < quality || dZoom > (360-quality) ) );
}
void CLgDevicePTZ::Invalidate( DWORD nSlowTimer, DWORD nFastTimer, bool bFastTimeValid ){
if( bFastTimeValid ){
// update time out
if( m_lTimeout > 0 && m_dwLastTime != nFastTimer ){
if ( nFastTimer > m_dwLastTime )
m_lTimeout -= ( nFastTimer - m_dwLastTime );
else
m_lTimeout -= nFastTimer;
m_dwLastTime = nFastTimer;
};
// write command
if( m_lTimeout <= 0 ){
if( m_bRead ) ReadProc( m_pProtocol, 0, true );
m_bRead = WriteProc( m_pProtocol, &m_lTimeout );
m_lTimeout <<= 3;
};
// read reply
if( m_bRead ){
bool bSuccess = ReadProc( m_pProtocol, 0, false );
// if read successeful
if( bSuccess ) m_lTimeout = 0;
m_bRead = !bSuccess;
};
} else {
// update timeout
if( m_lTimeout > 0 && m_dwLastTime != nSlowTimer ){
//m_lTimeout --;
m_lTimeout -= nSlowTimer - m_dwLastTime;
m_dwLastTime = nSlowTimer;
};
// write command
if( m_lTimeout <= 0 ){
if( m_bRead ) ReadProc( m_pProtocol, 0, true );
m_bRead = WriteProc( m_pProtocol, &m_lTimeout );
// at least one timeout should exist
m_lTimeout = m_lTimeout / 18; // 55 - 1/18 sec of 1000 msec
};
// read reply
if( m_bRead ){
bool bSuccess = ReadProc( m_pProtocol, 0, false );
// if read successeful
if( bSuccess ) m_lTimeout = 0;
m_bRead = !bSuccess;
};
};
};