//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: DeviceMigvanPTZ.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of DeviceMigvanPTZ.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "Device.h" #include "DeviceMigvanPTZ.h" #include "SocketMigvanPTZ.h" #include "..\..\LgLib\Version.h" #include "SensorArray.h" CDeviceMigvanPTZ::CDeviceMigvanPTZ() { m_bEnable = FALSE; // static DWORD nID = 0; // SetID( nID++ ); // m_MessageDispatcher.SetID( nID++ ); m_MessageDispatcher.CLgLinkP::Link( this ); ::ZeroMemory( m_pHardwareID, sizeof( m_pHardwareID ) ); m_bAutoInit = FALSE; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceMigvanPTZ::CDeviceMigvanPTZ") ); } CDeviceMigvanPTZ::~CDeviceMigvanPTZ() { LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CDeviceMigvanPTZ::~CDeviceMigvanPTZ") ); } BOOL CDeviceMigvanPTZ::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol ) { // check for demo mode BOOL bDemo = FALSE; if( CDevice::GetSocket() ) { CSensorArray *pSensorArray = CDevice::GetSocket()->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: CDevicePTZ::SetReady(); break; } } // to prevent processor overheating Sleep( 10 ); return TRUE; } // to do normal processing // call actual DeviceProc CLgNetDeviceMigvanPTZ::DeviceProc( (CLgNetSocketMigvanPTZ*)GetSocket(), pProtocol ); CLgNetMessageMigvanPTZ msg; msg.SetSenderID( m_MessageDispatcher.GetID() ); msg.SetDistinationID( GetID() ); // process commands PTZEVENT event; while( m_Queue.Pop( event ) ) { switch( event.id ) { case PTZC_INIT: if( m_bAutoInit ) { msg.BuildCmdAutoInit(); m_MessageDispatcher.SendMessageToChild( msg ); } else { msg.BuildCmdSetAddress( GetAddress(), m_pHardwareID ); m_MessageDispatcher.SendMessageToChild( msg ); } break; case PTZC_GET_PTZ: msg.BuildCmdGetPTZ(); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_RESET: msg.BuildCmdWarmBoot(); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_SET_PTZ: msg.BuildCmdSetPTZ( event.ptz.pan, event.ptz.tilt, event.ptz.zoom * 100.0 ); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_PAN: msg.BuildCmdMovePan( event.move.nDir == PAN_RIGHT, ( event.move.nDir == PAN_STOP ) ? 0 : event.move.speed * 100 ); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_TILT: msg.BuildCmdMoveTilt( event.move.nDir == TILT_UP, ( event.move.nDir == TILT_STOP ) ? 0 : event.move.speed * 100 ); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_ZOOM: msg.BuildCmdMoveZoom( event.move.nDir == ZOOM_TELE, ( event.move.nDir == ZOOM_STOP ) ? 0 : event.move.speed * 100 ); m_MessageDispatcher.SendMessageToChild( msg ); break; case PTZC_IRIS: msg.BuildCmdSetIris( event.iris.value * 100 ); m_MessageDispatcher.SendMessageToChild( msg ); break; default: break; } } // read messages while( m_MessageDispatcher.PopMessage( msg ) ) { BYTE bCommand; if( msg.GetCommand(&bCommand) ) { CLgDevicePTZ::PTZ_POSITION position; switch( bCommand ) { case CLgDevicePTZMigvan::EVT_AUTO_INIT: case CLgDevicePTZMigvan::EVT_ADDRESS: CDevicePTZ::SetPTZ( 0, 0, 0 ); break; case CLgDevicePTZMigvan::EVT_GET_PTZ: if( msg.GetPTZ( &position ) ) CDevicePTZ::SetPTZ( position.dPan, position.dTilt, position.dZoom / 100.0 ); break; case CLgDevicePTZMigvan::EVT_WARM_BOOT: CDevicePTZ::SetPTZ( 0, 0, 0 ); break; case CLgDevicePTZMigvan::EVT_SET_PTZ: if( msg.GetPTZ( &position ) ) CDevicePTZ::SetPTZ( position.dPan, position.dTilt, position.dZoom / 100.0 ); break; case CLgDevicePTZMigvan::EVT_MOVE_PAN: case CLgDevicePTZMigvan::EVT_MOVE_TILT: case CLgDevicePTZMigvan::EVT_MOVE_ZOOM: case CLgDevicePTZMigvan::EVT_SET_IRIS: case CLgDevicePTZMigvan::EVT_COMMAND_ERROR: default: CDevicePTZ::SetReady(); break; } } } return TRUE; }