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.
 
 
 
 

470 lines
16 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: MIC1300m.h
// AUTHOR: Chizhevskiy Sergey
// OVERVIEW
// ~~~~~~~~
// Header file of PTZ_MIC_1_300
//----------------------------------------------------------------------------
#ifdef __BCPLUSPLUS__
#pragma warn -inl
#endif
#ifndef __MIC_1_300__PTZ__H__INCLUDED__
#define __MIC_1_300__PTZ__H__INCLUDED__
#ifdef __BORLANDC__
#include "..\LgLib\Device\LgDevPTZ.h"
#else
#include "..\Device\LgDevPTZ.h"
#endif
//#define MIC_TILT_DEAD_ZONE 0x484L
#define MIC_TILT_DEAD_ZONE 0x4C4L
#define BASIS_SHIFT 104.0 // 90.0 + 42.0/2 degrees
struct PTZ_MIC_1_300
{
// types
public:
typedef struct
{
BOOL bZoomOn;
BOOL bZoomWide;
BOOL bTiltOn;
BOOL bTiltDown;
BOOL bPanOn;
BOOL bPanRight;
BYTE bPanSpeed;
BYTE bTiltSpeed;
BOOL bLampsOn;
BOOL bWiperOn;
}CONTROL_STATUS, *PCONTROL_STATUS;
// constants
public:
enum { CF_FULL_DUPLEX = '6', CF_HALF_DUPLEX = '4', CF_SIMPLEX = '2' };
// commands
public:
static INT BuildGotoPosition( LPBYTE pBuffer, BYTE bAddress, WORD wPan, WORD wTilt, WORD wZoom )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 20, 1 ); // length
pBuffer[ 4] = ToAscii( 20, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'N'; // control code (command)
pBuffer[ 7] = ToAscii( wPan, 2 ); // pan
pBuffer[ 8] = ToAscii( wPan, 1 ); // --||--
pBuffer[ 9] = ToAscii( wPan, 0 ); // --||--
pBuffer[10] = ToAscii( wTilt, 2 ); // tilt
pBuffer[11] = ToAscii( wTilt, 1 ); // --||--
pBuffer[12] = ToAscii( wTilt, 0 ); // --||--
pBuffer[13] = ToAscii( wZoom, 2 ); // zoom
pBuffer[14] = ToAscii( wZoom, 1 ); // --||--
pBuffer[15] = ToAscii( wZoom, 0 ); // --||--
pBuffer[16] = '0'; // unsupported
pBuffer[17] = '0'; // --||--
pBuffer[18] = '0'; // --||--
return CheckSum( pBuffer, 20 );
}
static INT BuildGetPosition( LPBYTE pBuffer, BYTE bAddress )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 8, 1 ); // length
pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'O'; // control code (command)
return CheckSum( pBuffer, 8 );
}
static INT BuildGetConfig( LPBYTE pBuffer, BYTE bAddress )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 8, 1 ); // length
pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'a'; // control code (command)
return CheckSum( pBuffer, 8 );
}
static INT BuildSetConfig( LPBYTE pBuffer, BYTE bAddress, BYTE bConfig )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 10, 1 ); // length
pBuffer[ 4] = ToAscii( 10, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'q'; // control code (command)
pBuffer[ 7] = ToAscii( bConfig, 1 ); // config
pBuffer[ 8] = ToAscii( bConfig, 0 ); // --||--
return CheckSum( pBuffer, 10 );
}
static INT BuildSetAddress( LPBYTE pBuffer, BYTE bAddress, BYTE bNewAddress )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 10, 1 ); // length
pBuffer[ 4] = ToAscii( 10, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 's'; // control code (command)
pBuffer[ 7] = ToAscii( bNewAddress, 1 );// new address
pBuffer[ 8] = ToAscii( bNewAddress, 0 );// --||--
return CheckSum( pBuffer, 10 );
}
static INT BuildGetStatus( LPBYTE pBuffer, BYTE bAddress )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 8, 1 ); // length
pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'H'; // control code (command)
return CheckSum( pBuffer, 8 );
}
static INT BuildSetManualControl( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 18, 1 ); // length
pBuffer[ 4] = ToAscii( 18, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'G'; // control code (command)
BYTE bCmd = 0;
if( pStatus->bPanRight ) bCmd |= 0x01;
if( pStatus->bPanOn ) bCmd |= 0x02;
if( pStatus->bTiltDown ) bCmd |= 0x04;
if( pStatus->bTiltOn ) bCmd |= 0x08;
if( pStatus->bZoomWide ) bCmd |= 0x10;
if( pStatus->bZoomOn ) bCmd |= 0x20;
pBuffer[ 7] = ToAscii( bCmd, 1 ); // command
pBuffer[ 8] = ToAscii( bCmd, 0 ); // --||--
pBuffer[ 9] = ToAscii( 0xB2, 1 ); // auto iris + fast zoom
pBuffer[10] = ToAscii( 0xB2, 0 ); // --||--
bCmd = 0x02;
if( pStatus->bLampsOn ) bCmd |= 0x18;
if( pStatus->bWiperOn ) bCmd |= 0x40;
pBuffer[11] = ToAscii( bCmd, 1 ); // digital zoom
pBuffer[12] = ToAscii( bCmd, 0 ); // --||--
pBuffer[13] = ToAscii( pStatus->bPanSpeed, 1 ); // pan speed
pBuffer[14] = ToAscii( pStatus->bPanSpeed, 0 ); // --||--
pBuffer[15] = ToAscii( pStatus->bTiltSpeed, 1 ); // unused
pBuffer[16] = ToAscii( pStatus->bTiltSpeed, 0 ); // --||--
return CheckSum( pBuffer, 18 );
}
static INT BuildSetManualControlPZ( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus, WORD wZoom )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
pBuffer[ 3] = ToAscii( 24, 1 ); // length
pBuffer[ 4] = ToAscii( 24, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'w'; // control code (command)
BYTE bCmd = 0;
if( pStatus->bPanRight ) bCmd |= 0x01;
if( pStatus->bPanOn ) bCmd |= 0x02;
if( pStatus->bTiltDown ) bCmd |= 0x04;
if( pStatus->bTiltOn ) bCmd |= 0x08;
if( pStatus->bZoomWide ) bCmd |= 0x10;
if( pStatus->bZoomOn ) bCmd |= 0x20;
pBuffer[ 7] = ToAscii( bCmd, 1 ); // command
pBuffer[ 8] = ToAscii( bCmd, 0 ); // --||--
pBuffer[ 9] = ToAscii( 0x32, 1 ); // auto iris + fast zoom
pBuffer[10] = ToAscii( 0x32, 0 ); // --||--
bCmd = 0x02;
if( pStatus->bLampsOn ) bCmd |= 0x18;
if( pStatus->bWiperOn ) bCmd |= 0x40;
pBuffer[11] = ToAscii( bCmd, 1 ); // digital zoom
pBuffer[12] = ToAscii( bCmd, 0 ); // --||--
pBuffer[13] = ToAscii( pStatus->bPanSpeed, 1 ); // pan speed
pBuffer[14] = ToAscii( pStatus->bPanSpeed, 0 ); // --||--
pBuffer[15] = ToAscii( pStatus->bTiltSpeed, 1 ); // unused
pBuffer[16] = ToAscii( pStatus->bTiltSpeed, 0 ); // --||--
pBuffer[17] = ToAscii( wZoom, 2 ); // absolute zoom position
pBuffer[18] = ToAscii( wZoom, 1 ); // --||--
pBuffer[19] = ToAscii( wZoom, 0 ); // --||--
pBuffer[20] = ToAscii( 0x000, 2 ); // focus position (unsupported)
pBuffer[21] = ToAscii( 0x000, 1 ); // --||--
pBuffer[22] = ToAscii( 0x000, 0 ); // --||--
return CheckSum( pBuffer, 24 );
}
static INT BuildPan( LPBYTE pBuffer, BYTE bAddress, BOOL bRight, BYTE bSpeed, PCONTROL_STATUS pStatus )
{
pStatus->bPanOn = bSpeed ? TRUE : FALSE;
pStatus->bPanRight = bRight;
pStatus->bPanSpeed = bSpeed;
return BuildSetManualControl( pBuffer, bAddress, pStatus );
}
static INT BuildTilt( LPBYTE pBuffer, BYTE bAddress, BOOL bUp, BYTE bSpeed, PCONTROL_STATUS pStatus )
{
pStatus->bTiltOn = bSpeed ? TRUE : FALSE;
pStatus->bTiltDown = !bUp;
pStatus->bTiltSpeed = bSpeed;
return BuildSetManualControl( pBuffer, bAddress, pStatus );
}
static INT BuildZoom( LPBYTE pBuffer, BYTE bAddress, BOOL bTele, BYTE bSpeed, PCONTROL_STATUS pStatus )
{
pStatus->bZoomOn = bSpeed ? TRUE : FALSE;
pStatus->bZoomWide = !bTele;
return BuildSetManualControl( pBuffer, bAddress, pStatus );
}
static INT BuildSetDefaultSettings( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus )
{
memset( pStatus, 0, sizeof(CONTROL_STATUS) );
return BuildSetManualControl( pBuffer, bAddress, pStatus );
}
static INT BuildVisca( LPBYTE pBuffer, BYTE bAddress, PBYTE pCommand, INT nCount )
{
pBuffer[ 0] = 0x0A; // line feed (header)
pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
nCount <<= 1;
pBuffer[ 3] = ToAscii( 8 + nCount, 1 ); // length
pBuffer[ 4] = ToAscii( 8 + nCount, 0 ); // --||--
pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
pBuffer[ 6] = 'r'; // control code (command)
for( INT i = 0; i < nCount; i += 2 )
{
pBuffer[ i + 7 ] = ToAscii( *pCommand , 1 );
pBuffer[ i + 8 ] = ToAscii( *pCommand++, 0 );
}
return CheckSum( pBuffer, 8 + nCount );
}
static INT BuildSetSlowShutter( LPBYTE pBuffer, BYTE bAddress, BOOL bAuto )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x5A, (uint8_t)(bAuto ? 0x02 : 0x03), 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetBackLight( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x33, (uint8_t)(bOn ? 0x02 : 0x03), 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetLowLux( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x01, (uint8_t)(bOn ? 0x02 : 0x03), 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetIRled( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x31, (uint8_t)(bOn ? 0x02 : 0x03), 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
/*
static BYTE SonyChar( BYTE bAscii )
{
return bAscii - 'A';
}
static INT BuildSetTitleClear( LPBYTE pBuffer, BYTE bAddress )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x74, 0x00, 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetTitleLowLight( LPBYTE pBuffer, BYTE bAddress )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x01, SonyChar( 'L' ), SonyChar( 'O' ), SonyChar( 'W' ),
0x1B, SonyChar( 'L' ), SonyChar( 'I' ),
SonyChar( 'G' ), SonyChar( 'H' ), SonyChar( 'T' ),
0x1B, 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetTitleNormalLight1( LPBYTE pBuffer, BYTE bAddress )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x01, SonyChar( 'N' ), SonyChar( 'O' ), SonyChar( 'R' ),
SonyChar( 'M' ), SonyChar( 'A' ), SonyChar( 'L' ),
0x1B, 0x1B, 0x1B,
0x1B, 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetTitleNormalLight2( LPBYTE pBuffer, BYTE bAddress )
{
BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x02, SonyChar( 'L' ), SonyChar( 'I' ), SonyChar( 'G' ),
SonyChar( 'H' ), SonyChar( 'T' ), 0x1B,
0x1B, 0x1B, 0x1B,
0x1B, 0xFF };
return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
}
static INT BuildSetLowLight( LPBYTE pBuffer, BYTE bAddress, BOOL bLowLight, PCONTROL_STATUS pStatus )
{
pStatus->bLampsOn = bLowLight;
if( bLowLight )
{
INT nCount = 0;
nCount += BuildSetSlowShutter( pBuffer + nCount, bAddress, TRUE );
nCount += BuildSetBackLight( pBuffer + nCount, bAddress, TRUE );
nCount += BuildSetLowLux( pBuffer + nCount, bAddress, TRUE );
nCount += BuildSetIRled( pBuffer + nCount, bAddress, TRUE );
// nCount += BuildSetTitleClear( pBuffer + nCount, bAddress );
// nCount += BuildSetTitleLowLight( pBuffer + nCount, bAddress );
return nCount;
}
INT nCount = 0;
nCount += BuildSetSlowShutter( pBuffer + nCount, bAddress, FALSE );
nCount += BuildSetBackLight( pBuffer + nCount, bAddress, FALSE );
nCount += BuildSetLowLux( pBuffer + nCount, bAddress, FALSE );
nCount += BuildSetIRled( pBuffer + nCount, bAddress, FALSE );
// nCount += BuildSetTitleClear( pBuffer + nCount, bAddress );
// nCount += BuildSetTitleNormalLight1( pBuffer + nCount, bAddress );
// nCount += BuildSetTitleNormalLight2( pBuffer + nCount, bAddress );
return nCount;
}
*/
static INT BuildSetPictureEffect( LPBYTE pBuffer, BYTE bAddress, INT nEffect )
{
// picture effects
BYTE pCommand[][6] =
{
{ 0x81, 0x01, 0x04, 0x63, 0x00, 0xFF }, // no effect
{ 0x81, 0x01, 0x04, 0x63, 0x01, 0xFF }, // pastel effect
{ 0x81, 0x01, 0x04, 0x63, 0x02, 0xFF }, // negative effect
{ 0x81, 0x01, 0x04, 0x63, 0x03, 0xFF }, // sepia effect
{ 0x81, 0x01, 0x04, 0x63, 0x04, 0xFF }, // B/W effect
{ 0x81, 0x01, 0x04, 0x63, 0x05, 0xFF }, // solarize effect
{ 0x81, 0x01, 0x04, 0x63, 0x06, 0xFF }, // mosaic effect
{ 0x81, 0x01, 0x04, 0x63, 0x07, 0xFF }, // slim effect
{ 0x81, 0x01, 0x04, 0x63, 0x08, 0xFF } // stretch effect
};
return BuildVisca( pBuffer, bAddress, pCommand[nEffect], sizeof(pCommand[0]) );
}
// conversion
public:
// pan
static CLgDevicePTZ::PTZ_DEGREE Pan2Degree( WORD wPan )
{
return (wPan - 0x001L) * 360L / ( 0x0FFFL - 0x001 );
}
static WORD Degree2Pan( CLgDevicePTZ::PTZ_DEGREE Angle )
{
return (WORD)( Angle * ( 0xFFFL - 0x001L ) / 360L + 0x001L );
}
// tilt
static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree( WORD wTilt )
{
// return ((double)wTilt - 0x484) * 360.0 / 0xFFF;
// NP return 360L - ( wTilt - MIC_TILT_DEAD_ZONE ) * 360L / 0xFFFL;
#ifdef __BORLANDC__
return 360L - ( wTilt - 0x484L ) * 360L / 0xFFFL;
#else
return (INT)(BASIS_SHIFT - ( wTilt * 360.0 / 4095.0 ));
#endif
}
static WORD Degree2Tilt( CLgDevicePTZ::PTZ_DEGREE dAngle )
{
// return (WORD)(dAngle * 0xFFF / 360.0 + 0x484);
// NP return (WORD)( (360L - dAngle) * 0xFFFL / 360L + MIC_TILT_DEAD_ZONE );
#ifdef __BORLANDC__
return (WORD)( (360L - dAngle) * 0xFFFL / 360L + 0x484L );
#else
return (WORD)( (( dAngle > BASIS_SHIFT )?(360.0+BASIS_SHIFT-dAngle):(BASIS_SHIFT-dAngle))*4095.0/360.0);
#endif
}
// zoom
static WORD Percent2Zoom( CLgDevicePTZ::PTZ_PERCENT dPercent )
{
return (WORD)( dPercent * 0x0923L / 100L );
}
static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent( WORD wZoom )
{
return ( wZoom * 100L ) / 0x0923L;
}
// speed
static BYTE Percent2Speed( CLgDevicePTZ::PTZ_PERCENT dPercent )
{
return (BYTE)( dPercent * 255L / 100L );
}
static CLgDevicePTZ::PTZ_PERCENT Speed2Percent( BYTE bSpeed )
{
return bSpeed * 100L / 255L;
}
// helpers
public:
static BYTE ToAscii( WORD wValue, BYTE nDigit )
{
static BYTE pHexTable[] = "0123456789ABCDEF";
return pHexTable[ ( wValue >> (nDigit << 2) ) & 0x0F ];
}
static WORD ToValue( PBYTE pAscii, INT nCount )
{
WORD bValue = 0;
for( INT i = 0; i < nCount; i++ )
{
bValue <<= 4;
if( pAscii[i] >= '0' && pAscii[i] <= '9' ) bValue += (pAscii[i] - '0');
else
if( pAscii[i] >= 'A' && pAscii[i] <= 'F' ) bValue += (pAscii[i] - 'A' + 10);
else
if( pAscii[i] >= 'a' && pAscii[i] <= 'f' ) bValue += (pAscii[i] - 'a' + 10);
}
return bValue;
}
private:
static INT CheckSum( LPBYTE pBuffer, INT nLength )
{
INT nCount = nLength - 1;
PBYTE pCheckSum = pBuffer + nCount;
// XOR all bytes in packet
*pCheckSum = *pBuffer++;
while( --nCount )
*pCheckSum ^= *pBuffer++;
// set top bit into '1'
*pCheckSum |= 0x80;
return nLength;
}
};
#endif
#ifdef __BCPLUSPLUS__
#pragma warn .inl
#endif