|
|
|
@ -3,8 +3,8 @@ |
|
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
|
|
// Version 1.0 01/01/2000
|
|
|
|
// Last modification: 08/10/2003
|
|
|
|
// PROJECT:
|
|
|
|
// SUBSYSTEM:
|
|
|
|
// PROJECT:
|
|
|
|
// SUBSYSTEM:
|
|
|
|
// FILE: DPelco.cpp
|
|
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
|
|
// OVERVIEW
|
|
|
|
@ -24,6 +24,66 @@ |
|
|
|
#define MAX_NOT_IN_POSITION_COUNT 1
|
|
|
|
#define DELAY_BEFORE_GET_POSITION 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum PELCO_SETTING_TYPE |
|
|
|
{ |
|
|
|
P_ST_NONE = -1, |
|
|
|
P_ST_MAX_NO_REPLY_COUNT = 0, |
|
|
|
P_ST_DELAY_BEFORE_GET_POSITION, |
|
|
|
P_ST_MAX_OPTICAL_ZOOM |
|
|
|
}PELCO_SETTING_TYPE; |
|
|
|
|
|
|
|
LPCTSTR m_pPelco_Setting[] = |
|
|
|
{ |
|
|
|
{ "MAX_NO_REPLY_COUNT" }, |
|
|
|
{ "DELAY_BEFORE_GET_POSITION" }, |
|
|
|
( "MAX_OPTICAL_ZOOM" ) |
|
|
|
}; |
|
|
|
|
|
|
|
BOOL CLgDevicePTZPelco::LoadUserSettings( void ) { |
|
|
|
// read delay number
|
|
|
|
FILE *pFile = fopen( "PELCO.INI", "rt" ); |
|
|
|
if( !pFile ) return FALSE; |
|
|
|
|
|
|
|
CHAR pLine[MAX_PATH]; |
|
|
|
while( fgets( pLine, MAX_PATH, pFile ) ) |
|
|
|
{ |
|
|
|
PELCO_SETTING_TYPE eType = P_ST_NONE; |
|
|
|
PCHAR pTemp = NULL; |
|
|
|
for( INT i = 0; i < 3; i++ ) |
|
|
|
{ |
|
|
|
pTemp = strstr( pLine, m_pPelco_Setting[i] ); |
|
|
|
if( pTemp ) |
|
|
|
{ |
|
|
|
eType = (PELCO_SETTING_TYPE)i; |
|
|
|
pTemp = strstr( pTemp, "=" ); |
|
|
|
if( pTemp ) |
|
|
|
pTemp = strtok( pTemp + 1, " \t\n\r" ); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if( eType == P_ST_NONE || !pTemp ) |
|
|
|
continue; |
|
|
|
|
|
|
|
switch( eType ) |
|
|
|
{ |
|
|
|
case P_ST_MAX_NO_REPLY_COUNT: { |
|
|
|
PELCO_MAX_NO_REPLY_COUNT = atoi( pTemp ); break; |
|
|
|
}; |
|
|
|
case P_ST_MAX_OPTICAL_ZOOM: { |
|
|
|
PELCO_MAX_OPTICAL_ZOOM = atoi( pTemp ); break; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fclose( pFile ); |
|
|
|
return TRUE; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CLgDevicePTZPelco::CLgDevicePTZPelco() |
|
|
|
{ |
|
|
|
m_nMode = CMD_INIT; |
|
|
|
@ -32,6 +92,10 @@ CLgDevicePTZPelco::CLgDevicePTZPelco() |
|
|
|
m_nNotInPositionCount = 0; |
|
|
|
memset( &m_PtzState, 0, sizeof(m_PtzState) ); |
|
|
|
m_bPause = FALSE; |
|
|
|
PELCO_MAX_NO_REPLY_COUNT = 20; // Default for Replaying Camera
|
|
|
|
PELCO_DELAY_BEFORE_GET_POSITION = 500; // Default for Replaying Camera
|
|
|
|
PELCO_MAX_OPTICAL_ZOOM = 0x2C85; |
|
|
|
LoadUserSettings(); |
|
|
|
} |
|
|
|
|
|
|
|
CLgDevicePTZPelco::~CLgDevicePTZPelco() |
|
|
|
@ -50,7 +114,7 @@ void CLgDevicePTZPelco::OnPerformCmd() |
|
|
|
// ready for new message
|
|
|
|
ReleaseCmd(); |
|
|
|
// ready to process new message
|
|
|
|
m_nMode = CMD_NONE; |
|
|
|
m_nMode = CMD_NONE; |
|
|
|
} |
|
|
|
|
|
|
|
BOOL CLgDevicePTZPelco::WriteProc( void *pProtocol, PLONG pTimeout ) |
|
|
|
@ -128,23 +192,23 @@ BOOL CLgDevicePTZPelco::WriteProc( void *pProtocol, PLONG pTimeout ) |
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
case STAGE_INIT_AUTO_FOCUS: |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoFocus( pSendBuffer, GetAddress(), 1 ); |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoFocus( pSendBuffer, GetAddress(), 0 ); // 0 - On , 1 - Off
|
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
case STAGE_INIT_AUTO_IRIS: |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoIris( pSendBuffer, GetAddress(), 1 ); |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoIris( pSendBuffer, GetAddress(), 0 ); |
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
case STAGE_INIT_AUTO_GAIN_CONTROL: |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoGainControl( pSendBuffer, GetAddress(), 1 ); |
|
|
|
nSendCount += PTZ_PELCO::BuildAutoGainControl( pSendBuffer, GetAddress(), 0 ); |
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
case STAGE_INIT_BACKLIGHT_COMPENSATION: |
|
|
|
nSendCount += PTZ_PELCO::BuildBacklightCompensation( pSendBuffer, GetAddress(), 1 ); |
|
|
|
nSendCount += PTZ_PELCO::BuildBacklightCompensation( pSendBuffer, GetAddress(), 0 ); |
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
case STAGE_INIT_WHITE_BALANCE: |
|
|
|
nSendCount += PTZ_PELCO::BuildWhiteBalance( pSendBuffer, GetAddress(), 1 ); |
|
|
|
nSendCount += PTZ_PELCO::BuildWhiteBalance( pSendBuffer, GetAddress(), 2 ); // 0 - On, 1 - Off, 2 - Auto
|
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -154,7 +218,7 @@ BOOL CLgDevicePTZPelco::WriteProc( void *pProtocol, PLONG pTimeout ) |
|
|
|
{ |
|
|
|
case STAGE_SET_PAN_POSITION: |
|
|
|
// ask for pan position
|
|
|
|
nSendCount += PTZ_PELCO::BuildSetPan( pSendBuffer, GetAddress(), PTZ_PELCO::Degree2Pan( m_Position.dPan ) ); |
|
|
|
nSendCount += PTZ_PELCO::BuildSetPan( pSendBuffer, GetAddress(), PTZ_PELCO::Degree2Pan( m_Position.dPan ) ); |
|
|
|
// set reply size
|
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
@ -166,7 +230,7 @@ BOOL CLgDevicePTZPelco::WriteProc( void *pProtocol, PLONG pTimeout ) |
|
|
|
break; |
|
|
|
case STAGE_SET_ZOOM_POSITION: |
|
|
|
// ask for pan position
|
|
|
|
nSendCount += PTZ_PELCO::BuildSetZoom( pSendBuffer, GetAddress(), PTZ_PELCO::Percent2Zoom( m_Position.dZoom ) ); |
|
|
|
nSendCount += PTZ_PELCO::BuildSetZoom( pSendBuffer, GetAddress(), PTZ_PELCO::Percent2Zoom( m_Position.dZoom, PELCO_MAX_OPTICAL_ZOOM ) ); |
|
|
|
// set reply size
|
|
|
|
pProtocolPTZ->SetResponseSize( 4 ); |
|
|
|
break; |
|
|
|
@ -196,7 +260,7 @@ BOOL CLgDevicePTZPelco::WriteProc( void *pProtocol, PLONG pTimeout ) |
|
|
|
{ |
|
|
|
case STAGE_GET_PAN_POSITION: |
|
|
|
// ask for pan position
|
|
|
|
nSendCount += PTZ_PELCO::BuildGetPan( pSendBuffer, GetAddress() ); |
|
|
|
nSendCount += PTZ_PELCO::BuildGetPan( pSendBuffer, GetAddress() ); |
|
|
|
// set reply size
|
|
|
|
pProtocolPTZ->SetResponseSize( 7 ); |
|
|
|
break; |
|
|
|
@ -261,17 +325,20 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
|
|
|
|
// read reply
|
|
|
|
PBYTE pReadBuffer = NULL; |
|
|
|
INT nReadCount = 0; |
|
|
|
INT nReadCount = 0; |
|
|
|
|
|
|
|
//if( !pProtocolPTZ->Read( &pReadBuffer, &nReadCount, lTimeout, TRUE ) || !pReadBuffer || !nReadCount )
|
|
|
|
if( !pProtocolPTZ->Read( &pReadBuffer, &nReadCount, lTimeout, TRUE ) || !pReadBuffer || !nReadCount ) |
|
|
|
{ |
|
|
|
if( !bLastChance ) |
|
|
|
return FALSE; |
|
|
|
|
|
|
|
m_nNoReplyCount++; |
|
|
|
if( m_nNoReplyCount > MAX_NO_REPLY_COUNT ) |
|
|
|
// if( m_nNoReplyCount > MAX_NO_REPLY_COUNT || ( m_nMode == CMD_GET_PTZ && m_nNoReplyCount > MAX_NOT_IN_POSITION_COUNT ) ) // v_1
|
|
|
|
if( m_nNoReplyCount > PELCO_MAX_NO_REPLY_COUNT ) // v_2
|
|
|
|
{ |
|
|
|
// perform goto idle state
|
|
|
|
// m_nMode = CMD_INIT; // Comented for BOSH/Pelco
|
|
|
|
// m_nMode = CMD_INIT; // Commented for BOSH/Pelco
|
|
|
|
} else // else - Bosh Pelco
|
|
|
|
|
|
|
|
return FALSE; |
|
|
|
@ -293,7 +360,7 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
case STAGE_INIT_BACKLIGHT_COMPENSATION: m_nStage = STAGE_INIT_WHITE_BALANCE; break; |
|
|
|
case STAGE_INIT_WHITE_BALANCE: |
|
|
|
OnPerformCmd(); |
|
|
|
OnEvtInit(); |
|
|
|
OnEvtInit(); |
|
|
|
break; |
|
|
|
} |
|
|
|
break; |
|
|
|
@ -301,17 +368,17 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
case CMD_GET_PTZ: |
|
|
|
switch( m_nStage ) |
|
|
|
{ |
|
|
|
case STAGE_GET_PAN_POSITION: |
|
|
|
case STAGE_GET_PAN_POSITION: |
|
|
|
m_Position.dPan = PTZ_PELCO::Pan2Degree( PTZ_PELCO::Pan2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
m_nStage = STAGE_GET_TILT_POSITION; |
|
|
|
break; |
|
|
|
|
|
|
|
case STAGE_GET_TILT_POSITION: |
|
|
|
case STAGE_GET_TILT_POSITION: |
|
|
|
m_Position.dTilt = PTZ_PELCO::Tilt2Degree( PTZ_PELCO::Tilt2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
m_nStage = STAGE_GET_ZOOM_POSITION; |
|
|
|
break; |
|
|
|
|
|
|
|
case STAGE_GET_ZOOM_POSITION: |
|
|
|
case STAGE_GET_ZOOM_POSITION: |
|
|
|
m_Position.dZoom = PTZ_PELCO::Zoom2Percent( PTZ_PELCO::Zoom2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
// ready to process new message
|
|
|
|
OnPerformCmd(); |
|
|
|
@ -327,17 +394,17 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
case STAGE_SET_PAN_POSITION: m_nStage = STAGE_SET_TILT_POSITION; break; |
|
|
|
case STAGE_SET_TILT_POSITION: m_nStage = STAGE_SET_ZOOM_POSITION; break; |
|
|
|
case STAGE_SET_ZOOM_POSITION: /*m_nStage = STAGE_GET_PAN_POSITION; break;
|
|
|
|
case STAGE_GET_PAN_POSITION: |
|
|
|
case STAGE_GET_PAN_POSITION: |
|
|
|
m_TempPosition.dPan = PTZ_PELCO::Pan2Degree( PTZ_PELCO::Pan2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
m_nStage = STAGE_GET_TILT_POSITION; |
|
|
|
break; |
|
|
|
|
|
|
|
case STAGE_GET_TILT_POSITION: |
|
|
|
case STAGE_GET_TILT_POSITION: |
|
|
|
m_TempPosition.dTilt = PTZ_PELCO::Tilt2Degree( PTZ_PELCO::Tilt2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
m_nStage = STAGE_GET_ZOOM_POSITION; |
|
|
|
break; |
|
|
|
|
|
|
|
case STAGE_GET_ZOOM_POSITION: |
|
|
|
case STAGE_GET_ZOOM_POSITION: |
|
|
|
m_TempPosition.dZoom = PTZ_PELCO::Zoom2Percent( PTZ_PELCO::Zoom2Value( pReadBuffer[4], pReadBuffer[5] ) ); |
|
|
|
|
|
|
|
// calculate difference between desired position and current position
|
|
|
|
@ -352,7 +419,7 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
m_Position.dTilt = m_TempPosition.dTilt; |
|
|
|
m_Position.dZoom = m_TempPosition.dZoom; |
|
|
|
*/ // ready to process new message
|
|
|
|
OnPerformCmd(); |
|
|
|
OnPerformCmd(); |
|
|
|
//notify
|
|
|
|
OnEvtSetPTZ( m_Position.dPan, m_Position.dTilt, m_Position.dZoom ); |
|
|
|
/* }
|
|
|
|
@ -370,17 +437,17 @@ BOOL CLgDevicePTZPelco::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChan |
|
|
|
|
|
|
|
case CMD_MOVE_PAN: |
|
|
|
OnPerformCmd(); |
|
|
|
OnEvtMovePan( m_MovePan.bRight, m_MovePan.dSpeed ); |
|
|
|
OnEvtMovePan( m_MovePan.bRight, m_MovePan.dSpeed ); |
|
|
|
break; |
|
|
|
|
|
|
|
case CMD_MOVE_TILT: |
|
|
|
OnPerformCmd(); |
|
|
|
OnEvtMoveTilt( m_MoveTilt.bUp, m_MoveTilt.dSpeed ); |
|
|
|
OnEvtMoveTilt( m_MoveTilt.bUp, m_MoveTilt.dSpeed ); |
|
|
|
break; |
|
|
|
|
|
|
|
case CMD_MOVE_ZOOM: |
|
|
|
OnPerformCmd(); |
|
|
|
OnEvtMoveZoom( m_MoveZoom.bTele, m_MoveZoom.dSpeed ); |
|
|
|
OnEvtMoveZoom( m_MoveZoom.bTele, m_MoveZoom.dSpeed ); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|