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.
441 lines
13 KiB
441 lines
13 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT: Laserguard libraries
|
|
// SUBSYSTEM: Communication support library
|
|
// FILE: PTZPG3AD.h
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Header file of CProtocolPTZPG3AD
|
|
//----------------------------------------------------------------------------
|
|
|
|
#ifndef __PTZ__PHILIPS__G3__AUTO__DOME__INCLUDED__
|
|
#define __PTZ__PHILIPS__G3__AUTO__DOME__INCLUDED__
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif
|
|
|
|
#ifdef __BORLANDC__
|
|
#include "..\LgLib\Comm\Connect.h"
|
|
#include "..\LgLib\Comm\Protocol.h"
|
|
#include "..\LgLib\Device\LgDevPTZ.h"
|
|
#else
|
|
#include "Connect.h"
|
|
#include "Protocol.h"
|
|
#include "..\Device\LgDevPTZ.h"
|
|
#endif
|
|
|
|
class CProtocolPTZPG3AD :
|
|
public CProtocol
|
|
{
|
|
public:
|
|
CProtocolPTZPG3AD();
|
|
virtual ~CProtocolPTZPG3AD();
|
|
|
|
public:
|
|
BOOL Create( CConnection *pConnection );
|
|
void Destroy();
|
|
void SetAddress( WORD bAddress );
|
|
|
|
public:
|
|
virtual BOOL Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost );
|
|
virtual BOOL Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost );
|
|
|
|
public:
|
|
enum {
|
|
HEADER_SIZE = 1U, // header + address(2) + length(2)
|
|
HEADER_TAG = 0x80U,
|
|
LENGTH_POS = 0U,
|
|
ADDRESS_POS_0 = 1U,
|
|
ADDRESS_POS_1 = 2U,
|
|
MIN_COMMAND_SIZE = 5U,
|
|
MAX_DATA_LENGTH = 15U, // maximun data size
|
|
MAX_COMMAND_SIZE = (MAX_DATA_LENGTH + MIN_COMMAND_SIZE), // header + address(2) + length(2) + ctrlflag + ctrlcode + data(N) + checksumm
|
|
};
|
|
|
|
private:
|
|
CConnection*m_pConnection;
|
|
BYTE m_pBuffer[MAX_COMMAND_SIZE];
|
|
PBYTE m_pBufferPtr;
|
|
INT m_nCount;
|
|
|
|
private:
|
|
BYTE m_pAddress[2];
|
|
|
|
private:
|
|
BOOL m_bReadAnyAddress;
|
|
};
|
|
|
|
#ifdef __BCPLUSPLUS__
|
|
#pragma warn -inl
|
|
#endif
|
|
|
|
typedef struct PTZ_PHILIPS_G3_AUTODOME
|
|
{
|
|
typedef enum { PAN_RIGHT = 0x0001, PAN_LEFT = 0x0003, PAN_STOP = 0 } E_PAN_DIR;
|
|
typedef enum { TILT_UP = 0x000C, TILT_DOWN = 0x0004, TILT_STOP = 0 } E_TILT_DIR;
|
|
typedef enum { ZOOM_TELE = 0x0010, ZOOM_WIDE = 0x0030, ZOOM_STOP = 0 } E_ZOOM_DIR;
|
|
typedef enum { IRIS_OPEN = 0x00C0, IRIS_CLOSE = 0x0040, IRIS_STOP = 0 } E_IRIS_DIR;
|
|
typedef enum { FOCUS_FAR = 0x0100, FOCUS_NEAR = 0x0300, FOCUS_STOP = 0 } E_FOCUS_DIR;
|
|
typedef struct PTZ_STATE
|
|
{
|
|
BYTE bZoomSpeed;
|
|
BYTE bTiltSpeed;
|
|
BYTE bPanSpeed;
|
|
E_PAN_DIR ePanState;
|
|
E_TILT_DIR eTiltState;
|
|
E_ZOOM_DIR eZoomState;
|
|
E_IRIS_DIR eIrisState;
|
|
E_FOCUS_DIR eFocusState;
|
|
}PTZ_STATE, *PPTZ_STATE;
|
|
|
|
static INT BuildGetPosition( LPBYTE pBuffer, WORD bAddress )
|
|
{
|
|
pBuffer[ 0] = 0x86; // length
|
|
pBuffer[ 1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[ 2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[ 3] = 0x0C; // opcode
|
|
pBuffer[ 4] = 0x01; // ping type
|
|
// pBuffer[ 5] = 0x3F; // requested data type
|
|
pBuffer[ 5] = 0x27; // requested data type
|
|
return CheckSum( pBuffer, 7 );
|
|
}
|
|
|
|
static INT BuildGotoPosition( LPBYTE pBuffer, WORD bAddress, DWORD dwPan, DWORD dwTilt, BYTE bZoom )
|
|
{
|
|
pBuffer[ 0] = 0x90; // length
|
|
pBuffer[ 1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[ 2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[ 3] = 10; // opcode
|
|
pBuffer[ 4] = (BYTE)( dwPan >> 14 ) & 0x07;
|
|
pBuffer[ 5] = (BYTE)( dwPan >> 7 ) & 0x7F;
|
|
pBuffer[ 6] = (BYTE)( dwPan >> 0 ) & 0x7F;
|
|
pBuffer[ 7] = (BYTE)( dwTilt >> 14 ) & 0x01;
|
|
pBuffer[ 8] = (BYTE)( dwTilt >> 7 ) & 0x7F;
|
|
pBuffer[ 9] = (BYTE)( dwTilt >> 0 ) & 0x7F;
|
|
pBuffer[10] = 0x40; // ignore pan velocity & acceleration
|
|
pBuffer[11] = 0x40; // ignore tilt velocity & acceleration
|
|
pBuffer[12] = 0x10 | 0x01 | ( ( bZoom & 0x01 ) << 2 ); // autofocus + zoom 0 bit + ignore iris
|
|
pBuffer[13] = (bZoom >> 1) & 0x7F; // zoom 1..7 bits
|
|
pBuffer[14] = 0; // autofocus
|
|
pBuffer[15] = 0x7F; // ignore iris
|
|
return CheckSum( pBuffer, 17 );
|
|
}
|
|
static INT BuildPan( LPBYTE pBuffer, WORD bAddress, E_PAN_DIR ePanDir, BYTE bSpeed, PTZ_STATE &PtzState )
|
|
{
|
|
PtzState.bPanSpeed = bSpeed;
|
|
PtzState.ePanState = ePanDir;
|
|
return BuildMove( pBuffer, bAddress, PtzState );
|
|
}
|
|
static INT BuildTilt( LPBYTE pBuffer, WORD bAddress, E_TILT_DIR eTiltDir, BYTE bSpeed, PTZ_STATE &PtzState )
|
|
{
|
|
PtzState.bTiltSpeed = bSpeed;
|
|
PtzState.eTiltState = eTiltDir;
|
|
return BuildMove( pBuffer, bAddress, PtzState );
|
|
}
|
|
static INT BuildZoom( LPBYTE pBuffer, WORD bAddress, E_ZOOM_DIR eZoomDir, BYTE bSpeed, PTZ_STATE &PtzState )
|
|
{
|
|
PtzState.bZoomSpeed = bSpeed;
|
|
PtzState.eZoomState = eZoomDir;
|
|
return BuildMove( pBuffer, bAddress, PtzState );
|
|
}
|
|
|
|
static INT BuildMove( LPBYTE pBuffer, WORD bAddress, PTZ_STATE &PtzState )
|
|
{
|
|
pBuffer[0] = 0x87; // length
|
|
pBuffer[1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[3] = 5; // opcode
|
|
pBuffer[4] = (PtzState.bZoomSpeed << 4) | PtzState.bTiltSpeed;
|
|
BYTE bData2 = 0;
|
|
BYTE bData3 = 0;
|
|
switch( PtzState.eIrisState )
|
|
{
|
|
case IRIS_OPEN: bData2 = 0x04; break;
|
|
case IRIS_CLOSE: bData2 = 0x02; break;
|
|
case IRIS_STOP: break;
|
|
}
|
|
switch( PtzState.eFocusState )
|
|
{
|
|
case FOCUS_FAR: bData2 |= 0x01; break;
|
|
case FOCUS_NEAR: bData3 = 0x40; break;
|
|
case FOCUS_STOP: break;
|
|
}
|
|
switch( PtzState.eZoomState )
|
|
{
|
|
case ZOOM_TELE: bData3 |= 0x20; break;
|
|
case ZOOM_WIDE: bData3 |= 0x10; break;
|
|
case ZOOM_STOP: break;
|
|
}
|
|
switch( PtzState.eTiltState )
|
|
{
|
|
case TILT_UP: bData3 |= 0x08; break;
|
|
case TILT_DOWN: bData3 |= 0x04; break;
|
|
case TILT_STOP: break;
|
|
}
|
|
switch( PtzState.ePanState )
|
|
{
|
|
case PAN_LEFT: bData3 |= 0x02; break;
|
|
case PAN_RIGHT: bData3 |= 0x01; break;
|
|
case PAN_STOP: break;
|
|
}
|
|
pBuffer[5] = (PtzState.bPanSpeed << 3) | bData2;
|
|
pBuffer[6] = bData3;
|
|
|
|
return CheckSum( pBuffer, 8 );
|
|
}
|
|
|
|
static INT BuildIris( LPBYTE pBuffer, WORD bAddress, BYTE bIris )
|
|
{
|
|
pBuffer[ 0] = 0x91; // length
|
|
pBuffer[ 1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[ 2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[ 3] = 10; // opcode
|
|
pBuffer[ 4] = 0x40; // ignore pan
|
|
pBuffer[ 5] = 0;
|
|
pBuffer[ 6] = 0;
|
|
pBuffer[ 7] = 0x40; // ignore tilt
|
|
pBuffer[ 8] = 0;
|
|
pBuffer[ 9] = 0;
|
|
pBuffer[10] = 0x40; // ignore pan velocity & acceleration
|
|
pBuffer[11] = 0x40; // ignore tilt velocity & acceleration
|
|
pBuffer[12] = 0x10 | ( bIris & 0x01 ) | 0x04; // autofocus + iris 0 bit + ignore zoom bit 0
|
|
pBuffer[13] = 0x7F; // zoom
|
|
pBuffer[14] = 0; // auto focus
|
|
pBuffer[15] = (bIris >> 1) & 0x7F; // iris
|
|
pBuffer[16] = 0x0E;//0x0C; // Backlight Comp. Bit & AGC Bit & AutoWhiteBalance
|
|
return CheckSum( pBuffer, 18 );
|
|
}
|
|
|
|
static INT CheckSum( LPBYTE pBuffer, INT nLength )
|
|
{
|
|
INT nCount = nLength - 1;
|
|
PBYTE pCheckSum = pBuffer + nCount;
|
|
// SUM all bytes in packet
|
|
*pCheckSum = *pBuffer++;
|
|
while( --nCount )
|
|
*pCheckSum += *pBuffer++;
|
|
// clear top bit
|
|
*pCheckSum &= 0x7F;
|
|
return nLength;
|
|
}
|
|
|
|
// conversion
|
|
public:
|
|
// pan
|
|
|
|
#define PAN_VALUE_MAX_NEW 128000L // new version
|
|
#define PAN_VALUE_MAX_OLD 102400L // old version
|
|
|
|
static CLgDevicePTZ::PTZ_DEGREE Pan2DegreeNew( DWORD dwPan )
|
|
{
|
|
return 360L - dwPan * 360L / PAN_VALUE_MAX_NEW;
|
|
}
|
|
static DWORD Degree2PanNew( CLgDevicePTZ::PTZ_DEGREE Angle )
|
|
{
|
|
return (DWORD)( ( ( 360L - Angle ) * (PAN_VALUE_MAX_NEW-1) ) / 360L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_DEGREE Pan2DegreeOld( DWORD dwPan )
|
|
{
|
|
return 360L - dwPan * 360L / PAN_VALUE_MAX_OLD;
|
|
}
|
|
static DWORD Degree2PanOld( CLgDevicePTZ::PTZ_DEGREE Angle )
|
|
{
|
|
return (DWORD)( ( ( 360L - Angle ) * (PAN_VALUE_MAX_OLD-1) ) / 360L );
|
|
}
|
|
|
|
// tilt
|
|
static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree( DWORD wTilt )
|
|
{
|
|
return wTilt * 95L / 27075L - 5L;
|
|
}
|
|
static DWORD Degree2Tilt( CLgDevicePTZ::PTZ_DEGREE dAngle )
|
|
{
|
|
return (DWORD)( ( dAngle + 5L ) * 27075L / 95L );
|
|
}
|
|
|
|
// zoom
|
|
static BYTE Percent2Zoom( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( ( (100L - dPercent) * 0xFE ) / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent( BYTE bZoom )
|
|
{
|
|
return 100L - ( bZoom * 100L / 0xFE );
|
|
}
|
|
|
|
// restrict value
|
|
static BOOL ValidatePan( CLgDevicePTZ::PTZ_DEGREE& pan )
|
|
{
|
|
while( pan < 0 ) pan += 360;
|
|
while( pan >= 360 ) pan -= 360;
|
|
return TRUE;
|
|
}
|
|
static BOOL ValidateTilt( CLgDevicePTZ::PTZ_DEGREE& tilt )
|
|
{
|
|
// restrict tilt within one period
|
|
while( tilt < 0 ) tilt += 360;
|
|
while( tilt >= 360 ) tilt -= 360;
|
|
|
|
if( tilt > 90 && tilt < (360-5) )
|
|
tilt = ( (tilt-90) < ((360-5)-tilt) ) ? 90 : -5;
|
|
else
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
}
|
|
static BOOL ValidateZoom( CLgDevicePTZ::PTZ_PERCENT& zoom )
|
|
{
|
|
if( zoom >= 0 )
|
|
{
|
|
if( zoom <= 100 ) return TRUE;
|
|
else zoom = 100;
|
|
}
|
|
else zoom = 0;
|
|
return FALSE;
|
|
}
|
|
|
|
// iris
|
|
static BYTE Percent2Iris( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x11L / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT Iris2Percent( BYTE bIris )
|
|
{
|
|
return bIris * 100L / 0x11L;
|
|
}
|
|
|
|
// focus
|
|
static BYTE Percent2Focus( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0xFEL / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT Focus2Percent( BYTE bIris )
|
|
{
|
|
return bIris * 100L / 0xFEL;
|
|
}
|
|
|
|
// pan speed
|
|
static BYTE Percent2PanSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x0FL / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT PanSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return bSpeed * 100L / 0x0FL;
|
|
}
|
|
|
|
// tilt speed
|
|
static BYTE Percent2TiltSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x0FL / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT TiltSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return bSpeed * 100L / 0x0FL;
|
|
}
|
|
|
|
// zoom speed
|
|
static BYTE Percent2ZoomSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x07L / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT ZoomSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return bSpeed * 100L / 0x07L;
|
|
}
|
|
|
|
// values conversion
|
|
static BYTE To14bit( WORD wValue, BYTE nDigit )
|
|
{
|
|
if( nDigit ) return (wValue >> 7) & 0x7F;
|
|
return wValue & 0x7F;
|
|
}
|
|
static DWORD Pan2Value( BYTE b1, BYTE b2, BYTE b3 )
|
|
{
|
|
return (((DWORD)b1 & 0x07) << 14) | (((DWORD)b2) << 7) | (DWORD)b3;
|
|
}
|
|
static DWORD Tilt2Value( BYTE b1, BYTE b2, BYTE b3 )
|
|
{
|
|
return (((DWORD)b1 & 0x01) << 14) | (((DWORD)b2) << 7) | (DWORD)b3;
|
|
}
|
|
static BYTE Zoom2Value( BYTE b1, BYTE b2 )
|
|
{
|
|
return ( (b1 >> 2) & 0x01 ) | (b2 << 1);
|
|
}
|
|
|
|
/////////////////////////////////////////// new command ///////////////////////////////////////////////
|
|
/*
|
|
static INT BuildGetPosition2( LPBYTE pBuffer, WORD bAddress )
|
|
{
|
|
pBuffer[ 0] = 0x84; // length
|
|
pBuffer[ 1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[ 2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[ 3] = 0x13; // opcode
|
|
return CheckSum( pBuffer, 5 );
|
|
}
|
|
static INT BuildGotoPosition2( LPBYTE pBuffer, WORD bAddress, WORD wPan, WORD wTilt, WORD wZoom )
|
|
{
|
|
pBuffer[ 0] = 0x8B; // length
|
|
pBuffer[ 1] = To14bit( bAddress, 1 ); // address high byte
|
|
pBuffer[ 2] = To14bit( bAddress, 0 ); // address low byte
|
|
pBuffer[ 3] = 0x13; // opcode
|
|
pBuffer[ 4] = (BYTE)( wPan >> 7 ) & 0x3F;
|
|
pBuffer[ 5] = (BYTE)( wPan ) & 0x7F;
|
|
pBuffer[ 6] = (BYTE)( wTilt >> 7 ) & 0x3F;
|
|
pBuffer[ 7] = (BYTE)( wTilt ) & 0x7F;
|
|
pBuffer[ 8] = (BYTE)( wZoom >> 7 ) & 0x7F;
|
|
pBuffer[ 9] = (BYTE)( wZoom ) & 0x7F;
|
|
return CheckSum( pBuffer, 11 );
|
|
}
|
|
static CLgDevicePTZ::PTZ_DEGREE Pan2Degree2( WORD wPan )
|
|
{
|
|
return 360L - wPan * 360L / 6283L;
|
|
}
|
|
static WORD Degree2Pan2( CLgDevicePTZ::PTZ_DEGREE dAngle )
|
|
{
|
|
return ( dAngle * 6283L / 360L ) % 6283;
|
|
}
|
|
|
|
static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree2( WORD wTilt )
|
|
{
|
|
return 360L - wTilt * 360L / 6283L;
|
|
}
|
|
static WORD Degree2Tilt2( CLgDevicePTZ::PTZ_DEGREE dAngle )
|
|
{
|
|
return ( dAngle * 6283L / 360L ) % 6283;
|
|
}
|
|
|
|
static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent2( WORD wZoom )
|
|
{
|
|
return 50;
|
|
}
|
|
static WORD Percent2Zoom2( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return 56;
|
|
}
|
|
|
|
static WORD Pan2Value2( BYTE b1, BYTE b2 )
|
|
{
|
|
return (((WORD)b1 & 0x3F) << 7) | (WORD)b2;
|
|
}
|
|
static WORD Tilt2Value2( BYTE b1, BYTE b2 )
|
|
{
|
|
return (((WORD)b1 & 0x3F) << 7) | (WORD)b2;
|
|
}
|
|
static WORD Zoom2Value2( BYTE b1, BYTE b2 )
|
|
{
|
|
return (((WORD)b1 & 0x7F) << 7) | (WORD)b2;
|
|
}
|
|
*/
|
|
}PTZ_PHILIPS_G3_AUTODOME;
|
|
|
|
#ifdef __BCPLUSPLUS__
|
|
#pragma warn .inl
|
|
#endif
|
|
|
|
#endif
|