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.
388 lines
9.9 KiB
388 lines
9.9 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: PTKS576.h
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Header file of CProtocolPTZTKS576
|
|
//----------------------------------------------------------------------------
|
|
|
|
#ifndef __PROTOCOL__PTZ__TK__S__576__H__INCLUDED__
|
|
#define __PROTOCOL__PTZ__TK__S__576__H__INCLUDED__
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#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 CProtocolPTZTKS576 :
|
|
public CProtocol
|
|
{
|
|
public:
|
|
CProtocolPTZTKS576();
|
|
virtual ~CProtocolPTZTKS576();
|
|
|
|
public:
|
|
BOOL Create( CConnection *pConnection );
|
|
void Destroy();
|
|
|
|
public:
|
|
void SetAddress( BYTE bAddress );
|
|
void SetReadAnyAddress( BOOL bReadAnyAddress ) { m_bReadAnyAddress = bReadAnyAddress; }
|
|
void SetReadOnlyHeaderMode( BOOL bReadOnlyHeader ) { m_bReadOnlyHeader = bReadOnlyHeader; }
|
|
|
|
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
|
|
{
|
|
MAX_COMMAND_SIZE = 31,
|
|
};
|
|
|
|
private:
|
|
CConnection*m_pConnection;
|
|
BYTE m_pBuffer[MAX_COMMAND_SIZE];
|
|
PBYTE m_pBufferPtr;
|
|
INT m_nCount;
|
|
|
|
private:
|
|
BYTE m_bAddress;
|
|
|
|
private:
|
|
BOOL m_bReadAnyAddress;
|
|
BOOL m_bReadOnlyHeader;
|
|
};
|
|
|
|
#ifdef __BCPLUSPLUS__
|
|
#pragma warn -inl
|
|
#endif
|
|
|
|
struct PTZ_JVC_TK_S576
|
|
{
|
|
// commands
|
|
public:
|
|
static INT BuildSetPanPosition( LPBYTE pBuffer, BYTE bAddress, WORD wPan )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x84; // ???
|
|
pBuffer[ 4] = 0x43; // ???
|
|
pBuffer[ 5] = 0x04; //
|
|
pBuffer[ 6] = ToByte1( wPan ); // pan hi part
|
|
pBuffer[ 7] = ToByte2( wPan ); // pan low part
|
|
return 8;
|
|
}
|
|
|
|
static INT BuildSetTiltPosition( LPBYTE pBuffer, BYTE bAddress, WORD wTilt )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x84; // ???
|
|
pBuffer[ 4] = 0x43; // ???
|
|
pBuffer[ 5] = 0x05; // command code
|
|
pBuffer[ 6] = ToByte1( wTilt ); // tilt hi part
|
|
pBuffer[ 7] = ToByte2( wTilt ); // tilt low part
|
|
return 8;
|
|
}
|
|
|
|
static INT BuildSetZoomPosition( LPBYTE pBuffer, BYTE bAddress, WORD wZoom )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x84; // ???
|
|
pBuffer[ 4] = 0x43; // ???
|
|
pBuffer[ 5] = 0x02; // command code
|
|
pBuffer[ 6] = ToByte1( wZoom ); // zoom hi part
|
|
pBuffer[ 7] = ToByte2( wZoom ); // zoom low part
|
|
return 8;
|
|
}
|
|
|
|
static INT BuildSetFocusPosition( LPBYTE pBuffer, BYTE bAddress, WORD wFocus )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x84; // ???
|
|
pBuffer[ 4] = 0x43; // ???
|
|
pBuffer[ 5] = 0x03; // command code
|
|
pBuffer[ 6] = ToByte1( wFocus ); // zoom hi part
|
|
pBuffer[ 7] = ToByte2( wFocus ); // zoom low part
|
|
return 8;
|
|
}
|
|
|
|
static INT BuildGetPanPosition( LPBYTE pBuffer, BYTE bAddress )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x82; // ???
|
|
pBuffer[ 4] = 0x03; // ???
|
|
pBuffer[ 5] = 0x04; //
|
|
return 6;
|
|
}
|
|
|
|
static INT BuildGetTiltPosition( LPBYTE pBuffer, BYTE bAddress )
|
|
{
|
|
pBuffer[ 0] = 0xB1; // ???
|
|
pBuffer[ 1] = 0x01; // group
|
|
pBuffer[ 2] = bAddress; // address
|
|
pBuffer[ 3] = 0x82; // ???
|
|
pBuffer[ 4] = 0x03; // ???
|
|
pBuffer[ 5] = 0x05; // command code
|
|
return 6;
|
|
}
|
|
|
|
static INT BuildGetZoomPosition( LPBYTE pBuffer, BYTE bAddress )
|
|
{
|
|
pBuffer[0] = 0xB1; // ???
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = 0x82; // ???
|
|
pBuffer[4] = 0x03; // ???
|
|
pBuffer[5] = 0x02; // command code
|
|
return 6;
|
|
}
|
|
|
|
static INT BuildGetFocusPosition( LPBYTE pBuffer, BYTE bAddress )
|
|
{
|
|
pBuffer[0] = 0xB1; // ???
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = 0x82; // ???
|
|
pBuffer[4] = 0x03; // ???
|
|
pBuffer[5] = 0x03; // command code
|
|
return 6;
|
|
}
|
|
|
|
enum { PAN_STOP = 0x00, PAN_RIGHT = 0x01, PAN_LEFT = 0x03 };
|
|
static INT BuildPan( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
|
|
{
|
|
pBuffer[0] = 0xB1; // header
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = (bDirection == PAN_STOP) ? 0x82 : 0x83;
|
|
pBuffer[4] = 0x45; // ???
|
|
switch( bDirection )
|
|
{
|
|
case PAN_RIGHT:
|
|
pBuffer[5] = 0x00;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case PAN_LEFT:
|
|
pBuffer[5] = 0x01;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case PAN_STOP:
|
|
pBuffer[5] = 0x02;
|
|
return 6;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
enum { TILT_STOP = 0x00, TILT_UP = 0x04, TILT_DOWN = 0x0C };
|
|
static INT BuildTilt( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
|
|
{
|
|
pBuffer[0] = 0xB1; // header
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = (bDirection == TILT_STOP) ? 0x82 : 0x83;
|
|
pBuffer[4] = 0x45;
|
|
switch( bDirection )
|
|
{
|
|
case TILT_UP:
|
|
pBuffer[5] = 0x03;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case TILT_DOWN:
|
|
pBuffer[5] = 0x04;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case TILT_STOP:
|
|
pBuffer[5] = 0x05;
|
|
return 6;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
enum { ZOOM_STOP = 0x00, ZOOM_WIDE = 0x10, ZOOM_TELE = 0x30 };
|
|
static INT BuildZoom( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
|
|
{
|
|
pBuffer[0] = 0xB1; // header
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = (bDirection == ZOOM_STOP) ? 0x82 : 0x83;
|
|
pBuffer[4] = 0x45; // ???
|
|
switch( bDirection )
|
|
{
|
|
case ZOOM_TELE:
|
|
pBuffer[5] = 0x0C;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case ZOOM_WIDE:
|
|
pBuffer[5] = 0x0D;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case ZOOM_STOP:
|
|
pBuffer[5] = 0x0E;
|
|
return 6;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
enum { FOCUS_STOP = 0x00, FOCUS_FAR = 0x40, FOCUS_NEAR = 0xC0 };
|
|
static INT BuildMoveFocus( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
|
|
{
|
|
pBuffer[0] = 0xB1; // header
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = (bDirection == FOCUS_STOP) ? 0x82 : 0x83;
|
|
pBuffer[4] = 0x45; // ???
|
|
switch( bDirection )
|
|
{
|
|
case FOCUS_FAR:
|
|
pBuffer[5] = 0x09;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case FOCUS_NEAR:
|
|
pBuffer[5] = 0x0A;
|
|
pBuffer[6] = bSpeed;
|
|
return 7;
|
|
case FOCUS_STOP:
|
|
pBuffer[5] = 0x0B;
|
|
return 6;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static INT BuildSetAutoFocus( LPBYTE pBuffer, BYTE bAddress )
|
|
{
|
|
pBuffer[0] = 0xB1; // ???
|
|
pBuffer[1] = 0x01; // group
|
|
pBuffer[2] = bAddress; // address
|
|
pBuffer[3] = 0x81; // ???
|
|
pBuffer[4] = 0x1F; // ???
|
|
return 5;
|
|
}
|
|
|
|
// conversion
|
|
public:
|
|
// pan
|
|
static CLgDevicePTZ::PTZ_DEGREE Pan2Degree( WORD wPan )
|
|
{
|
|
return wPan * 360L / 0x18FFL;
|
|
}
|
|
static WORD Degree2Pan( CLgDevicePTZ::PTZ_DEGREE Angle )
|
|
{
|
|
return (WORD)( ( Angle * 0x18FFL ) / 360L );
|
|
}
|
|
|
|
// tilt
|
|
static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree( WORD wTilt )
|
|
{
|
|
return wTilt * 180L / 0x1900L;
|
|
}
|
|
static WORD Degree2Tilt( CLgDevicePTZ::PTZ_DEGREE dAngle )
|
|
{
|
|
return (WORD)( dAngle * 0x1900L / 180L );
|
|
}
|
|
|
|
// zoom
|
|
static WORD Percent2Zoom( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (WORD)( ( dPercent * ( 0x17E8L - 0x20L ) ) / 100L + 0x20L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent( WORD wZoom )
|
|
{
|
|
return ( wZoom - 0x20L ) * 100L / ( 0x17E8L - 0x20L );
|
|
}
|
|
|
|
// focus
|
|
static WORD Percent2Focus( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (WORD)( ( (100L - dPercent) * ( 0x0580L - 0x20L ) ) / 100L + 0x20L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT Focus2Percent( WORD wFocus )
|
|
{
|
|
return 100L - ( ( wFocus - 0x20L ) * 100L / ( 0x0580L - 0x20L ) );
|
|
}
|
|
|
|
// pan speed
|
|
static BYTE Percent2PanSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 15L / 100L + 0x10L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT PanSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return ( bSpeed - 0x10L ) * 100L / 15L;
|
|
}
|
|
|
|
// tilt speed
|
|
static BYTE Percent2TiltSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 15L / 100L + 0x10L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT TiltSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return (bSpeed - 0x10L ) * 100L / 15L;
|
|
}
|
|
|
|
// zoom speed
|
|
static BYTE Percent2ZoomSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x03L / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT ZoomSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return bSpeed * 100L / 0x03L;
|
|
}
|
|
|
|
// focus speed
|
|
static BYTE Percent2FocusSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
|
|
{
|
|
return (BYTE)( dPercent * 0x03L / 100L );
|
|
}
|
|
static CLgDevicePTZ::PTZ_PERCENT FocusSpeed2Percent( BYTE bSpeed )
|
|
{
|
|
return bSpeed * 100L / 0x03L;
|
|
}
|
|
|
|
// value conversion
|
|
static WORD ToValue( BYTE bTag, BYTE b1, BYTE b2 )
|
|
{
|
|
return ( (bTag & 0x0F) == 4 ) ? ( b1 * (WORD)0x80 + b2 ) : b1;
|
|
}
|
|
static BYTE ToByte1( WORD wValue )
|
|
{
|
|
return wValue / 0x80;
|
|
}
|
|
static BYTE ToByte2( WORD wValue )
|
|
{
|
|
return wValue % 0x80;
|
|
}
|
|
};
|
|
|
|
#ifdef __BCPLUSPLUS__
|
|
#pragma warn .inl
|
|
#endif
|
|
|
|
#endif
|
|
|