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.
605 lines
16 KiB
605 lines
16 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: DevicePTZm.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of DevicePTZm.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "DevicePTZm.h"
|
|
#include "..\..\LgLib\Comm\Connect.h"
|
|
#include "SensorArray.h"
|
|
#include "..\..\LgLib\Version.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
/*
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_AUTO_INIT = { 3, 0, FALSE, FALSE, { { STAGE_GET_ADDRESS, 100, 3, 0 }, { STAGE_SET_ADDRESS, 300, 0, 0 }, { STAGE_GET_PTZ, 100, 3, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_INIT = { 2, 0, FALSE, FALSE, { { STAGE_SET_ADDRESS, 500, 0, 0 }, { STAGE_GET_PTZ, 100, 5, 0 } } };
|
|
//const CDevicePTZs::COMMAND CDevicePTZs::CMD_SET_PTZ = { 3, 0, FALSE, FALSE, { { STAGE_SET_PRESET, 0, 0, 0 }, { STAGE_GOTO_PRESET, 50, 0, 0 }, { STAGE_GET_PTZ, 100, 20, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_SET_PTZ = { 3, 0, FALSE, FALSE, { { STAGE_SET_PRESET, 50, 0, 0 }, { STAGE_GOTO_PRESET, 100, 0, 0 }, { STAGE_GET_PTZ, 300, 20, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_GET_PTZ = { 1, 0, FALSE, FALSE, { { STAGE_GET_PTZ, 50, 20, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_PAN = { 1, 0, FALSE, FALSE, { { STAGE_PAN, 0, 1, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_TILT = { 1, 0, FALSE, FALSE, { { STAGE_TILT, 0, 1, 0 } } };
|
|
const CDevicePTZs::COMMAND CDevicePTZs::CMD_ZOOM = { 1, 0, FALSE, FALSE, { { STAGE_ZOOM, 0, 1, 0 } } };
|
|
*/
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_AUTO_INIT = { 3, 10, { { SUBCMD_GET_ADDRESS, 100, 3 }, { SUBCMD_SET_ADDRESS, 500, 0 }, { SUBCMD_GET_PTZ, 100, 3 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_INIT = { 2, 10, { { SUBCMD_SET_ADDRESS, 500, 0 }, { SUBCMD_GET_PTZ, 100, 5 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_SET_PTZ = { 3, 0, { { SUBCMD_SET_PRESET, 0, 0 }, { SUBCMD_GOTO_PRESET, 500, 0 }, { SUBCMD_GET_PTZ, 100, 20 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_GET_PTZ = { 1, 0, { { SUBCMD_GET_PTZ, 100, 20 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_PAN = { 1, 0, { { SUBCMD_PAN, 0, 0 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_TILT = { 1, 0, { { SUBCMD_TILT, 0, 0 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_ZOOM = { 1, 0, { { SUBCMD_ZOOM, 0, 0 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_RESET = { 2, 0, { { SUBCMD_REBOOT, 500, 0 }, { SUBCMD_GET_PTZ, 500, 100 } } };
|
|
const CDevicePTZm::COMMAND CDevicePTZm::CMD_IRIS = { 2, 0, { { SUBCMD_IRIS, 0, 0 }, { SUBCMD_IRIS, 0, 0 } } };
|
|
|
|
CDevicePTZm::CDevicePTZm()
|
|
{
|
|
::ZeroMemory( m_pHardwareID, sizeof( m_pHardwareID ) );
|
|
::ZeroMemory( &m_Command, sizeof( m_Command ) );
|
|
::ZeroMemory( m_pCommand, sizeof( m_pCommand ) );
|
|
m_nAddress = 0;
|
|
m_bAutoInit = FALSE;
|
|
m_nCommandStage = 0;
|
|
m_nCommandRetry = 0;
|
|
m_nCommandStage = 0;
|
|
m_nStageRetry = 0;
|
|
m_bStageResult = FALSE;
|
|
m_bStagePause = FALSE;
|
|
m_bCommandResult = TRUE;
|
|
m_bSetPreset = FALSE;
|
|
m_nPresetCount = 0;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePTZm::CDevicePTZm") );
|
|
}
|
|
|
|
CDevicePTZm::~CDevicePTZm()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDevicePTZm::~CDevicePTZm") );
|
|
}
|
|
|
|
DWORD CDevicePTZm::BuildCheckSum(LPBYTE pBuffer)
|
|
{
|
|
BYTE size = pBuffer[1] + 2;
|
|
pBuffer[size] = 0;
|
|
for (int i = 0; i < size; i++ )
|
|
pBuffer[size] += pBuffer[i];
|
|
return (DWORD)(size + 1);
|
|
}
|
|
|
|
BOOL CDevicePTZm::TestCheckSum(LPBYTE pBuffer, DWORD dwCount)
|
|
{
|
|
if( (DWORD)(pBuffer[1] + 3) == dwCount )
|
|
{
|
|
BYTE cs = 0;
|
|
for( DWORD i = 0; i < dwCount-1; i++ )
|
|
cs += pBuffer[ i ];
|
|
return (BOOL)( cs == pBuffer[ dwCount-1 ] );
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
DWORD CDevicePTZm::CompleteIO( CConnection *pConnection )
|
|
{
|
|
// check for demo mode
|
|
BOOL bDemo = FALSE;
|
|
CSocket *pSocket = CDevice::GetSocket();
|
|
if( pSocket )
|
|
{
|
|
CSensorArray *pSensorArray = pSocket->GetSensorArray();
|
|
if( pSensorArray )
|
|
bDemo = pSensorArray->IsDemo();
|
|
}
|
|
|
|
// if demo mode to do emulation
|
|
if( bDemo )
|
|
{
|
|
// "process" commands
|
|
PTZEVENT event;
|
|
while( m_Queue.Pop( event ) )
|
|
{
|
|
switch( event.id )
|
|
{
|
|
case PTZC_INIT:
|
|
case PTZC_GET_PTZ:
|
|
CDevicePTZ::SetPTZ( 0, 0, 0 );
|
|
break;
|
|
case PTZC_SET_PTZ:
|
|
CDevicePTZ::SetPTZ( event.ptz.pan, event.ptz.tilt, event.ptz.zoom );
|
|
break;
|
|
case PTZC_RESET:
|
|
case PTZC_PAN:
|
|
case PTZC_TILT:
|
|
case PTZC_ZOOM:
|
|
case PTZC_IRIS:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// to prevent processor overheating
|
|
Sleep( 10 );
|
|
|
|
return 0;
|
|
}
|
|
|
|
// to do normal processing
|
|
|
|
// if command performed
|
|
if( m_bCommandResult )
|
|
{
|
|
m_bSetPreset = FALSE;
|
|
|
|
PTZEVENT event;
|
|
while( m_Queue.Pop( event ) )
|
|
{
|
|
m_pCommand[ event.id ] = TRUE;
|
|
switch( event.id )
|
|
{
|
|
case PTZC_INIT:
|
|
case PTZC_GET_PTZ:
|
|
break;
|
|
case PTZC_RESET:
|
|
// if number of performed presets less 256 then skip reset command
|
|
if( m_nPresetCount < 7 )
|
|
m_pCommand[ event.id ] = FALSE;
|
|
else
|
|
m_nPresetCount = 0;
|
|
break;
|
|
case PTZC_SET_PTZ:
|
|
m_DataPtz.pan = ConvertDegreeToPan( event.ptz.pan );
|
|
m_DataPtz.tilt = ConvertDegreeToTilt( event.ptz.tilt );
|
|
m_DataPtz.zoom = ConvertPercentToZoom( event.ptz.zoom );
|
|
break;
|
|
case PTZC_PAN:
|
|
m_DataPan.nDir = event.move.nDir;
|
|
m_DataPan.speed = event.move.speed;
|
|
break;
|
|
case PTZC_TILT:
|
|
m_DataTilt.nDir = event.move.nDir;
|
|
m_DataTilt.speed = event.move.speed;
|
|
break;
|
|
case PTZC_ZOOM:
|
|
m_DataZoom.nDir = event.move.nDir;
|
|
m_DataZoom.speed = event.move.speed;
|
|
break;
|
|
case PTZC_IRIS:
|
|
m_DataIris.value = ConvertValueToIris( event.iris.value );
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( m_pCommand[ PTZC_INIT ] )
|
|
{
|
|
m_pCommand[ PTZC_INIT ] = FALSE;
|
|
if( m_bAutoInit ) m_Command = CMD_AUTO_INIT;
|
|
else m_Command = CMD_INIT;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_RESET ] )
|
|
{
|
|
m_pCommand[ PTZC_RESET ] = FALSE;
|
|
m_Command = CMD_RESET;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_SET_PTZ ] )
|
|
{
|
|
m_pCommand[ PTZC_SET_PTZ ] = FALSE;
|
|
m_Command = CMD_SET_PTZ;
|
|
m_bSetPreset = TRUE;
|
|
// calculate count of performed presets
|
|
m_nPresetCount ++;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_GET_PTZ ] )
|
|
{
|
|
m_pCommand[ PTZC_GET_PTZ ] = FALSE;
|
|
m_Command = CMD_GET_PTZ;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_PAN ] )
|
|
{
|
|
m_pCommand[ PTZC_PAN ] = FALSE;
|
|
m_Command = CMD_PAN;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_TILT ] )
|
|
{
|
|
m_pCommand[ PTZC_TILT ] = FALSE;
|
|
m_Command = CMD_TILT;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_ZOOM ] )
|
|
{
|
|
m_pCommand[ PTZC_ZOOM ] = FALSE;
|
|
m_Command = CMD_ZOOM;
|
|
}
|
|
else
|
|
if( m_pCommand[ PTZC_IRIS ] )
|
|
{
|
|
m_pCommand[ PTZC_IRIS ] = FALSE;
|
|
m_Command = CMD_IRIS;
|
|
}
|
|
else
|
|
{
|
|
return INFINITE; // no command
|
|
}
|
|
|
|
m_nCommandRetry = 0;
|
|
m_nCommandStage = 0;
|
|
m_bCommandResult = FALSE;
|
|
|
|
m_nStageRetry = 0;
|
|
m_bStageResult = FALSE;
|
|
m_bStagePause = FALSE;
|
|
}
|
|
|
|
// check if nesseary to pause
|
|
if( m_bStagePause )
|
|
{
|
|
// perform pause
|
|
::Sleep( m_Command.pStage[ m_nCommandStage ].dwPause );
|
|
|
|
// next stage begin from command
|
|
m_bStagePause = FALSE;
|
|
|
|
// if sequence performed
|
|
if( m_Command.nCount == m_nCommandStage + 1 )
|
|
{
|
|
// if last stage was successeful
|
|
if( m_bStageResult )
|
|
{
|
|
m_bCommandResult = TRUE;
|
|
return INFINITE;
|
|
}
|
|
|
|
// if nessesary to repeat stage sequence
|
|
if( m_Command.pStage[m_nCommandStage].nRetry > m_nStageRetry )
|
|
m_nStageRetry++;
|
|
else
|
|
// if nessesary to repeat command sequence
|
|
if( m_Command.nRetry > m_nCommandRetry )
|
|
{
|
|
m_nCommandRetry++;
|
|
m_nCommandStage = 0;
|
|
m_nStageRetry = 0;
|
|
m_bStageResult = FALSE;
|
|
}
|
|
else
|
|
{
|
|
m_bCommandResult = TRUE;
|
|
return INFINITE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// if last stage was successeful
|
|
if( m_bStageResult )
|
|
{
|
|
// go to next stage
|
|
m_nCommandStage++;
|
|
m_nStageRetry = 0;
|
|
}
|
|
else
|
|
{
|
|
// if nessesary to repeat stage sequence
|
|
if( m_Command.pStage[m_nCommandStage].nRetry > m_nStageRetry )
|
|
{
|
|
m_nStageRetry++;
|
|
m_bStageResult = FALSE;
|
|
}
|
|
else
|
|
{
|
|
// go to next stage
|
|
m_nCommandStage++;
|
|
m_nStageRetry = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
BYTE pBuffer[100];
|
|
DWORD dwWriteCount = 0UL;
|
|
DWORD dwReadCount = 0UL;
|
|
|
|
// perform sub command
|
|
switch( m_Command.pStage[ m_nCommandStage ].nSubCmd )
|
|
{
|
|
case SUBCMD_SET_ADDRESS:
|
|
pBuffer[ 0] = 0; // address
|
|
pBuffer[ 1] = 9; // length
|
|
pBuffer[ 2] = 16; // type
|
|
pBuffer[ 3] = 4; // command
|
|
pBuffer[ 4] = m_pHardwareID[0];
|
|
pBuffer[ 5] = m_pHardwareID[1];
|
|
pBuffer[ 6] = m_pHardwareID[2];
|
|
pBuffer[ 7] = m_pHardwareID[3];
|
|
pBuffer[ 8] = m_pHardwareID[4];
|
|
pBuffer[ 9] = m_nAddress; // new dome address
|
|
pBuffer[10] = 4; // dome type
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_GET_ADDRESS:
|
|
pBuffer[ 0] = 0; // address
|
|
pBuffer[ 1] = 2; // length
|
|
pBuffer[ 2] = 16; // type
|
|
pBuffer[ 3] = 8; // command
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 13;
|
|
break;
|
|
|
|
case SUBCMD_REBOOT:
|
|
pBuffer[ 0] = 0; // address
|
|
pBuffer[ 1] = 2; // length
|
|
pBuffer[ 2] = 16; // type
|
|
pBuffer[ 3] = 16; // command
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_SET_PRESET:
|
|
pBuffer[ 0] = m_nAddress; // address
|
|
pBuffer[ 1] = 11; // length
|
|
pBuffer[ 2] = 4; // type
|
|
pBuffer[ 3] = 4; // command
|
|
pBuffer[ 4] = 1; // preset number
|
|
pBuffer[ 5] = m_DataPtz.pan; // pan pos
|
|
pBuffer[ 6] = m_DataPtz.tilt; // tilt pos
|
|
pBuffer[ 7] = 255; // pan speed
|
|
pBuffer[ 8] = 255; // tilt speed
|
|
pBuffer[ 9] = 0; // wait time L
|
|
pBuffer[10] = 0; // wait time H
|
|
pBuffer[11] = LOBYTE( m_DataPtz.zoom ); // zoom pos L
|
|
pBuffer[12] = HIBYTE( m_DataPtz.zoom ); // zoom pos H
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_GOTO_PRESET:
|
|
pBuffer[0] = m_nAddress; // address
|
|
pBuffer[1] = 3; // length
|
|
pBuffer[2] = 2; // type
|
|
pBuffer[3] = 16; // command
|
|
pBuffer[4] = 1; // preset number
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_GET_PTZ:
|
|
pBuffer[0] = m_nAddress; // address
|
|
pBuffer[1] = 2; // length
|
|
pBuffer[2] = 4; // type
|
|
pBuffer[3] = 8; // command
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 9;
|
|
break;
|
|
|
|
case SUBCMD_PAN:
|
|
pBuffer[0] = m_nAddress; // address
|
|
pBuffer[1] = 3; // length
|
|
pBuffer[2] = 2; // type
|
|
switch( m_DataPan.nDir )
|
|
{
|
|
case PAN_LEFT:
|
|
pBuffer[3] = 129; // command
|
|
pBuffer[4] = ConvertPercentToSpeed( m_DataPan.speed ); // speed
|
|
break;
|
|
case PAN_RIGHT:
|
|
pBuffer[3] = 1; // command
|
|
pBuffer[4] = ConvertPercentToSpeed( m_DataPan.speed ); // speed
|
|
break;
|
|
case PAN_STOP: pBuffer[3] = 1;
|
|
pBuffer[3] = 1; // command
|
|
pBuffer[4] = 0; // speed
|
|
break;
|
|
}
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_TILT:
|
|
pBuffer[0] = m_nAddress; // address
|
|
pBuffer[1] = 3; // length
|
|
pBuffer[2] = 2; // type
|
|
switch( m_DataTilt.nDir )
|
|
{
|
|
case TILT_UP:
|
|
pBuffer[3] = 2; // command
|
|
pBuffer[4] = ConvertPercentToSpeed( m_DataTilt.speed ); // speed
|
|
break;
|
|
case TILT_DOWN:
|
|
pBuffer[3] = 130; // command
|
|
pBuffer[4] = ConvertPercentToSpeed( m_DataTilt.speed ); // speed
|
|
break;
|
|
case TILT_STOP:
|
|
pBuffer[3] = 2; // command
|
|
pBuffer[4] = 0; // speed
|
|
break;
|
|
}
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
|
|
case SUBCMD_ZOOM:
|
|
pBuffer[ 0] = m_nAddress; // address
|
|
pBuffer[ 1] = 9; // length
|
|
pBuffer[ 2] = 1;
|
|
pBuffer[ 3] = ':';
|
|
pBuffer[ 4] = 'W';
|
|
pBuffer[ 5] = 'F';
|
|
pBuffer[ 6] = 'C';
|
|
pBuffer[ 7] = 'B';
|
|
pBuffer[ 8] = 'B';
|
|
switch( m_DataZoom.nDir )
|
|
{
|
|
case ZOOM_TELE:
|
|
pBuffer[ 9] = '9';
|
|
pBuffer[10] = '9';
|
|
break;
|
|
case ZOOM_WIDE:
|
|
pBuffer[ 9] = '9';
|
|
pBuffer[10] = 'B';
|
|
break;
|
|
case ZOOM_STOP:
|
|
pBuffer[ 9] = 'F';
|
|
pBuffer[10] = 'E';
|
|
break;
|
|
}
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
case SUBCMD_IRIS:
|
|
static BYTE hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
|
pBuffer[ 0] = m_nAddress; // address
|
|
pBuffer[ 1] = 9; // length
|
|
pBuffer[ 2] = 1;
|
|
pBuffer[ 3] = ':';
|
|
pBuffer[ 4] = 'W';
|
|
pBuffer[ 5] = 'F';
|
|
pBuffer[ 6] = 'D';
|
|
pBuffer[ 7] = '9';
|
|
pBuffer[ 8] = 'E';
|
|
pBuffer[ 9] = hex[(m_DataIris.value & 0xF0) >> 4];
|
|
pBuffer[10] = hex[ m_DataIris.value & 0x0F ];
|
|
dwWriteCount = BuildCheckSum( pBuffer );
|
|
dwReadCount = 0;
|
|
break;
|
|
}
|
|
|
|
// write command
|
|
BOOL bResult = pConnection->Write( pBuffer, dwWriteCount, 2000UL );
|
|
|
|
// read reply
|
|
if( bResult && dwReadCount )
|
|
{
|
|
// actual reading
|
|
DWORD dwRead = pConnection->Read( pBuffer, dwReadCount, dwReadCount * 10UL );
|
|
// test reply
|
|
bResult = (dwRead == dwReadCount) ? TestCheckSum( pBuffer, dwReadCount ) : FALSE;
|
|
}
|
|
|
|
// apply answer
|
|
if( bResult )
|
|
{
|
|
// assume that reply is incorrect
|
|
bResult = FALSE;
|
|
|
|
switch( m_Command.pStage[ m_nCommandStage ].nSubCmd )
|
|
{
|
|
case SUBCMD_GET_PTZ:
|
|
if( pBuffer[0] == m_nAddress && pBuffer[1] == 6 && pBuffer[2] == 4 && pBuffer[3] == 9 )
|
|
{
|
|
if( m_bSetPreset )
|
|
{
|
|
BYTE pan = pBuffer[4];
|
|
BYTE tilt = pBuffer[5];
|
|
if( abs( pan - m_DataPtz.pan ) > 5 ||
|
|
abs( tilt - m_DataPtz.tilt ) > 5 )
|
|
break;
|
|
}
|
|
// notify itself about position
|
|
CDevicePTZ::SetPTZ( ConvertPanToDegree( pBuffer[4] ),
|
|
ConvertTiltToDegree( pBuffer[5] ),
|
|
ConvertZoomToPercent( MAKEWORD( pBuffer[6], pBuffer[7] ) ) );
|
|
|
|
bResult = TRUE;
|
|
}
|
|
break;
|
|
|
|
case SUBCMD_GET_ADDRESS:
|
|
if( pBuffer[1] == 10 && pBuffer[2] == 16 && pBuffer[3] == 1 )
|
|
{
|
|
// store hardware id
|
|
m_pHardwareID[0] = pBuffer[4];
|
|
m_pHardwareID[1] = pBuffer[5];
|
|
m_pHardwareID[2] = pBuffer[6];
|
|
m_pHardwareID[3] = pBuffer[7];
|
|
m_pHardwareID[4] = pBuffer[8];
|
|
bResult = TRUE;
|
|
}
|
|
break;
|
|
|
|
case SUBCMD_SET_ADDRESS:
|
|
case SUBCMD_SET_PRESET:
|
|
case SUBCMD_GOTO_PRESET:
|
|
case SUBCMD_PAN:
|
|
case SUBCMD_TILT:
|
|
case SUBCMD_ZOOM:
|
|
case SUBCMD_REBOOT:
|
|
case SUBCMD_IRIS:
|
|
bResult = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// remember result of last stage
|
|
m_bStageResult = bResult;
|
|
|
|
// perform pause
|
|
m_bStagePause = TRUE;
|
|
|
|
return 0UL;
|
|
}
|
|
|
|
|
|
double CDevicePTZm::ConvertPanToDegree( BYTE Pan )
|
|
{
|
|
return 360.0 - ((double)Pan) * 360.0 / 256.0;
|
|
}
|
|
|
|
BYTE CDevicePTZm::ConvertDegreeToPan( double Angle )
|
|
{
|
|
return (BYTE)( ( (360.0 - Angle) * 256.0 ) / 360.0 );
|
|
}
|
|
|
|
double CDevicePTZm::ConvertTiltToDegree( BYTE Tilt )
|
|
{
|
|
return 90.0 - ((double)Tilt) * 360.0 / 256.0;
|
|
}
|
|
|
|
BYTE CDevicePTZm::ConvertDegreeToTilt( double Angle )
|
|
{
|
|
return (BYTE)( ( ( 90.0 - Angle ) * 256.0 ) / 360.0 );
|
|
}
|
|
|
|
WORD CDevicePTZm::ConvertPercentToZoom( double percent )
|
|
{
|
|
const int zr = 0x2178;
|
|
int zv = (int)( ((double)zr) * ( 1.0 - percent ) );
|
|
if( zv < 0 ) zv = 0;
|
|
if( zv > zr ) zv = zr;
|
|
return (WORD)(((DWORD)zv) - 0x108C);
|
|
}
|
|
|
|
double CDevicePTZm::ConvertZoomToPercent( WORD zoom )
|
|
{
|
|
const int zr = 0x2170;
|
|
if( HIBYTE(zoom) == 0xFF ) return -1.0;
|
|
return 1.0 - ((double)((WORD)(zoom + (WORD)0x10BC))) / ((double)zr);
|
|
}
|
|
|
|
BYTE CDevicePTZm::ConvertPercentToSpeed( double percent )
|
|
{
|
|
return (BYTE)( percent * 255.0 );
|
|
}
|
|
|
|
BYTE CDevicePTZm::ConvertValueToIris( double value )
|
|
{
|
|
return (BYTE)( value * 255.0 );
|
|
}
|
|
|
|
double CDevicePTZm::ConvertSpeedToPercent( BYTE speed )
|
|
{
|
|
return ((double)speed) / 256.0;
|
|
}
|