//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 09/04/2000 // Last modification: 17/11/2003 // Project Intruder Position Indicator // SUBSYSTEM: Receiver information from LGS // FILE: Lgs.cpp // AUTHOR: Chizhevskiy Sergey // OVERVIEW // ~~~~~~~~ // Source file for implemenation of class CLgs //---------------------------------------------------------------------------- #include "stdafx.h" #include "..\LgLib\Version.h" #include "..\LgLib\LgDebug.h" #include "Application.h" #include "Lgs.h" CLgs::CLgs() { m_dCoeficient = 100; m_pApplication = NULL; m_hRestartWnd = NULL; m_hResetWnd = NULL;; m_hSendFileWnd = NULL; m_hSoftwareVersionWnd = NULL; m_hFullResetWnd = NULL; m_hSetParametersWnd[0] = m_hSetParametersWnd[1] = 0; m_hGetParametersWnd[0] = m_hGetParametersWnd[1] = 0; ZeroMemory( &m_Parameters, sizeof( m_Parameters ) ); ZeroMemory( m_pSrcFileName, sizeof(m_pSrcFileName) ); ZeroMemory( m_pDstFileName, sizeof(m_pDstFileName) ); m_hGetSerialNumberWnd = NULL; memset( &m_SerialNumber, 0, sizeof(m_SerialNumber) ); memset( &m_SoftwareVersion, 0, sizeof(m_SoftwareVersion) ); memset( &m_FullBorder, 0, sizeof(m_FullBorder) ); memset( &m_Border, 0, sizeof(m_Border) ); memset( &m_VoltageParameters, 0, sizeof(m_VoltageParameters) ); m_hSetCommSpeedWnd = NULL; m_nSetCommSpeed = LGS_COMM_BAUDRATE; memset( &m_CameraPosition, 0 , sizeof(m_CameraPosition) ); m_bCameraReady = TRUE; m_bShowCommunicationErrors = FALSE; LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgs::CLgs" ); } CLgs::~CLgs() { Destroy(); LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgs::~CLgs" ); } BOOL CLgs::Create(CApplication *pApp, LPCTSTR pCommPort, INT nBaudRate, INT nBitCount, INT nStopBits, INT nProtocol, double range, INT nAddress, BOOL bAutoBaudrate, BOOL bShowCommunicationErrors, DWORD dwTransactionTimeout ) { Destroy(); m_dCoeficient = range; m_pApplication = pApp; // m_nAddress = nAddress; m_bShowCommunicationErrors = bShowCommunicationErrors; m_nCommErrorCount.QuadPart = 0; if( !m_Socket.Create( pCommPort, nBaudRate, FALSE, FALSE ) ) return FALSE; // device initialization // m_Device.SetID( 1 ); m_Device.CLgNetDeviceMD::SetAddress( nAddress ); m_Device.CLgDeviceLGS::SetAddress( nAddress ); m_Device.SetAutoBaudrate( bAutoBaudrate ); m_Device.SetTransactionTimeout( dwTransactionTimeout ); // m_Socket.SetID( 0 ); m_Socket.CLgLinkP::Link( &m_Device ); m_Socket.CLgLinkP::Link( &m_Device ); GeneralTestFunction(); return TRUE; } BOOL CLgs::Start() { return CLgThread::Start( FALSE ); } BOOL CLgs::Destroy() { CLgThread::Stop( TRUE ); m_Socket.Destroy(); return TRUE; } #define DEFAULT_PERIOD 1000UL DWORD CLgs::ThreadProc() { // ::SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ); // ::SetThreadPriority( GetThreadHandle(), THREAD_PRIORITY_TIME_CRITICAL ); __try { m_OutMsg.SetDistinationID( m_Device.GetID() ); m_OutMsg.SetSenderID( m_Socket.GetID() ); // prepare test packet // m_OutMsg.BuildCmdFSFindFirst( "*.*" ); // m_Device.SendMessageToChild( m_OutMsg ); while( !CLgThread::IsStopping() ) { // #define SELF_TARGET_TEST #if defined(SELF_TARGET_TEST) && defined(_DEBUG) static INT nRange = 1; static INT dRange = 10; static INT nAngle = 0; static INT dAngle = 5; static DWORD dwTime = 0; if( GetTickCount() - dwTime > 1000UL ) { dwTime = GetTickCount(); INT nDevice = rand()%2; nAngle = (nAngle + 5)%360; nRange += dRange; if( nRange > (INT)m_dCoeficient || nRange < 0 ) { dRange = -dRange; nRange += dRange; } m_pApplication->GetTargetQueue()->PostEvent( nDevice ? 'b' : 'a', nAngle, nRange, nDevice, NULL, 0 ); // m_pApplication->GetTargetQueue()->PostEvent( 'q', nAngle, -1, 0, NULL, 0 ); } #endif // check response HANDLE hEvents[] = { CLgThread::GetThreadStopEvent(), m_Socket.GetMessageEvent() }; switch( WaitForMultipleObjects( 2, hEvents, FALSE, 10UL ) ) { default: case WAIT_OBJECT_0: return 0; case WAIT_TIMEOUT: continue; case WAIT_OBJECT_0 + 1: break; } // process responce while( m_Socket.PopMessage( m_InMsg ) ) { BYTE bCommand; if( !m_InMsg.GetCommand( &bCommand ) ) continue; switch( bCommand ) { case CLgDevicePTZ::EVT_ERROR_DATA: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_ERROR_DATA" ); // CLgs::CmdCameraGetPTZ(); break; case CLgDeviceLGS::EVT_CAMERA_ERROR: m_bCameraReady = TRUE; break; case CLgDevicePTZ::EVT_GET_PTZ: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_PTZ" ); if(m_InMsg.GetPTZ( &m_CameraPosition ) ) m_bCameraReady = TRUE; break; case CLgDevicePTZ::EVT_SET_PTZ: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_PTZ" ); if( m_InMsg.GetPTZ( &m_CameraPosition ) ) m_bCameraReady = TRUE; break; case CLgDevicePTZ::EVT_SET_FOCUS: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_FOCUS" ); // m_InMsg.GetFocus( &m_CameraFocus ); // m_bCameraReady = TRUE; break; case CLgDevicePTZ::EVT_GET_FOCUS: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_FOCUS" ); m_InMsg.GetFocus( &m_CameraFocus ); break; case CLgDevicePTZ::EVT_SET_IRIS: m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_IRIS" ); break; case CLgDevicePTZ::EVT_MOVE_PAN: m_bCameraReady = TRUE; // CmdCameraGetPTZ(); LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_PAN" ); break; case CLgDevicePTZ::EVT_MOVE_TILT: m_bCameraReady = TRUE; // CmdCameraGetPTZ(); LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_TILT" ); break; case CLgDevicePTZ::EVT_MOVE_ZOOM: m_bCameraReady = TRUE; // CmdCameraGetPTZ(); LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_ZOOM" ); break; case CLgDevicePTZ::EVT_MOVE_FOCUS: m_bCameraReady = TRUE; // CmdCameraGetPTZ(); LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_MOVE_FOCUS" ); break; case CLgDevicePTZ::EVT_WIPER: m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_WIPER" ); break; case CLgDeviceLGS::EVT_RESET: ::PostMessage(m_hResetWnd, WM_LGS_RESET, 1, 0); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_RESTART: ::PostMessage(m_hRestartWnd, WM_LGS_RESTART, 1, 0); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_FULL_RESET: ::PostMessage(m_hFullResetWnd, WM_LGS_FULL_RESET, 1, 0); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_QUIT: // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_BORDER: if( m_InMsg.GetBorder( &m_Border ) ) { OnFinishDraw(); ::PostMessage(m_hDrawMapWnd, WM_LGS_DRAWMAP, 0, 0); } break; case CLgDeviceLGS::EVT_BORDER_PREPARING: ::PostMessage( m_hDrawMapWnd, WM_LGS_DRAWMAP, 2, (LONG)0 ); break; case CLgDeviceLGS::EVT_BORDER_PROGRESS: { INT dProgress; if( m_InMsg.GetBorderProgress( &dProgress ) ) { ::PostMessage( m_hDrawMapWnd, WM_LGS_DRAWMAP, 1, dProgress ); } } break; case CLgDeviceLGS::EVT_FULL_BORDER: { if( m_InMsg.GetFullBorder( &m_FullBorder ) ) { OnFinishDraw(); ::PostMessage(m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 0, 0); } } break; case CLgDeviceLGS::EVT_FULL_BORDER_PREPARING: { INT dPercent; if( m_InMsg.GetFullBorderPreparing( &dPercent ) ) { ::PostMessage( m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 2, (LONG)dPercent ); } } break; case CLgDeviceLGS::EVT_FULL_BORDER_PROGRESS: { INT dProgress; if( m_InMsg.GetFullBorderProgress( &dProgress ) ) { ::PostMessage( m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 1, (LONG)dProgress ); } } break; case CLgDeviceLGS::EVT_BLIND: { CLgDeviceLGS::LGS_BLIND blind; if( m_InMsg.GetBlind( &blind ) ) m_pApplication->GetTargetQueue()->PostEvent( 'm', blind.bReason, 0, blind.nDevice, 0, 0 ); } break; case CLgDeviceLGS::EVT_FLIP: { CLgDeviceLGS::LGS_FLIP flip; if( m_InMsg.GetFlip( &flip ) ) m_pApplication->GetTargetQueue()->PostEvent( 'i', flip.nLoops, 0, flip.nDevice, 0, 0 ); } break; case CLgDeviceLGS::EVT_TARGET: { CLgDeviceLGS::LGS_TARGET target; if( m_InMsg.GetTarget( &target ) ) { // LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDeviceLGS::EVT_TARGET for device %d", target.bDevice ); char cType; if( target.bType == LGS::TT_WIDE ) cType = 'w'; else if( target.bType == LGS::TT_NORMAL ) cType = target.bDevice ? 'b' : 'a'; else // if( target.bType == LGS::TT_BLIND ) cType = 'm'; // else // if( target.bType == LGS::TT_FLIP ) cType = 'i'; // else if( target.bType == LGS::TT_TEST ) cType = 'l'; else break; if( target.bType == LGS::TT_WIDE || target.bType == LGS::TT_NORMAL ) { double range = target.dRange * m_dCoeficient; // if( range < 50.0 ) // range += 1.0; m_pApplication->GetTargetQueue()->PostEvent( cType, target.dAngle, range, target.bDevice, NULL, target.nWidth ); } else m_pApplication->GetTargetQueue()->PostEvent( cType, target.dAngle, target.dRange, target.bDevice, NULL, target.nWidth ); } } break; case CLgDeviceLGS::EVT_DOPLER_ALARM: { CLgDeviceLGS::DOPLER_ALARM alarm; if( m_InMsg.GetDoplerAlarm( &alarm ) ) { m_pApplication->GetTargetQueue()->PostEvent( 'q', alarm.dPan, -1, 0, NULL, 0 ); } } break; case CLgDeviceLGS::EVT_SET_DOPLER: { m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_DOPLER" ); CLgDeviceLGS::DOPLER dopler; if( m_InMsg.GetDopler( &dopler ) ) { // m_pApplication->GetTargetQueue()->PostEvent( 'q', alarm.dPan, -1, 0, NULL, 0 ); } } break; case CLgDeviceLGS::EVT_GET_DOPLER: { m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_DOPLER" ); CLgDeviceLGS::DOPLER dopler; if( m_InMsg.GetDopler( &dopler ) ) { } } break; case CLgDeviceLGS::EVT_GET_DOPLER_MASK: { m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_DOPLER_MASK" ); CLgDeviceLGS::DOPLER_MASK_ARRAY mask; if( m_InMsg.GetDoplerMask( &mask ) ) { } } break; case CLgDeviceLGS::EVT_SET_DOPLER_MASK: { m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_DOPLER" ); CLgDeviceLGS::DOPLER_MASK_ARRAY dopler_mask; if( m_InMsg.GetDoplerMask( &dopler_mask ) ) { } } break; case CLgDeviceLGS::EVT_CONNECTION: { BOOL bConnected = FALSE; if( m_InMsg.GetEvtConnection( &bConnected ) ) m_pApplication->GetTargetQueue()->PostEvent( bConnected ? 'C' : 'c', 0, 0, 0, NULL, 0 ); // notify about connection OnNotifyConnect( bConnected ); } break; case CLgDeviceLGS::EVT_OPERATION_MODE: { CLgDeviceLGS::LGS_OPERATION_MODE eMode = CLgDeviceLGS::LGS_OM_UNKNOWN; if( !m_InMsg.GetEvtOperationMode( &eMode ) ) LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "m_InMsg.GetEvtOperationMode failed" ); else { switch( eMode ) { case CLgDeviceLGS::LGS_OM_STUDY: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_STUDY" ); if( !m_pApplication->GetTargetQueue()->PostEvent( 'd', 0, 0, 0, NULL, 0 ) ) LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("CLgDevicePTZ::EVT_OPERATION_MODE m_pApplication->GetTargetQueue()->PostEvent failed") ); break; case CLgDeviceLGS::LGS_OM_DETECTION: LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_DETECTION" ); if( !m_pApplication->GetTargetQueue()->PostEvent( 'D', 0, 0, 0, NULL, 0 ) ) LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("CLgDevicePTZ::EVT_OPERATION_MODE m_pApplication->GetTargetQueue()->PostEvent failed") ); break; default: case CLgDeviceLGS::LGS_OM_UNKNOWN: LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_UNKNOWN" ); break; } } } break; case CLgDeviceLGS::EVT_VOLTAGE: { BOOL bPowered = FALSE; if( m_InMsg.GetEvtVoltage( &bPowered ) ) m_pApplication->GetTargetQueue()->PostEvent( bPowered ? 'P' : 'p', 0, 0, 0, NULL, 0 ); } break; case CLgDeviceLGS::EVT_ERROR: { CLgDeviceLGS::LGS_ERROR error; if( m_InMsg.GetEvtError( &error ) ) m_pApplication->GetTargetQueue()->PostEvent( 'e', error.eErrorLevel, error.eErrorID, LGS::ER_SUNBIT, error.pErrorText, 0 ); } break; case CLgDeviceLGS::EVT_COMMAND_ERROR: { CLgDevice::DEVICE_CMD_ERROR error; if( m_InMsg.GetEvtCommandError( &error ) ) { // m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, error.pErrorText, 0 ); OnNotifyCommandError( error.nCommand ); } m_bCameraReady = TRUE; LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_COMMAND_ERROR" ); } break; case CLgDeviceLGS::EVT_COMMUNICATION_ERROR: if( m_bShowCommunicationErrors ) { INT nCount; if( m_InMsg.GetEvtCommunicationError( &nCount ) ) { m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "COMMUNICATION ERROR", 0 ); } } break; case CLgDeviceLGS::EVT_GETFILE_RESULT: { BYTE bResult = 0; if( m_InMsg.GetGetFileResult( &bResult ) ) { switch( bResult ) { case CLgDeviceLGS::GET_FILE_ERROR_LGS: m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "ERROR DURING TRANSFER FILE", 0 ); ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 0 ); break; case CLgDeviceLGS::GET_FILE_ERROR_HOST: m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "ERROR DURING OPEN FILE", 0 ); ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 0 ); break; case CLgDeviceLGS::GET_FILE_SUCCESS: ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 1 ); break; } } // notify recipients about reset OnNotifyReset( TRUE, bCommand ); } break; case CLgDeviceLGS::EVT_GETFILE_PROGRESS: { INT dProgress; if( m_InMsg.GetGetFileProgress( &dProgress ) ) ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 1, dProgress ); } break; case CLgDeviceLGS::EVT_GET_CAMERA_PARAMETERS: { if( m_InMsg.GetCameraParameters( &m_CameraParameters ) ) ::PostMessage( m_hGetCameraTypeWnd, WM_LGS_GET_CAMERA_PARAMETERS, 0, 0 ); } break; case CLgDeviceLGS::EVT_SET_CAMERA_PARAMETERS: if( m_InMsg.GetCameraParameters( &m_CameraParameters ) ) ::PostMessage( m_hSetCameraTypeWnd, WM_LGS_SET_CAMERA_PARAMETERS, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_RELAY_PARAMETERS: if( m_InMsg.GetRelayParameters( &m_RelayParameters ) ) ::PostMessage( m_hGetRelayParametersWnd, WM_LGS_GET_RELAY_PARAMETERS, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_RELAY_PARAMETERS: if( m_InMsg.GetRelayParameters( &m_RelayParameters ) ) ::PostMessage( m_hSetRelayParametersWnd, WM_LGS_SET_RELAY_PARAMETERS, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_VOLTAGE_PARAMETERS: if( m_InMsg.GetEvtGetVoltageParameters( &m_VoltageParameters ) ) ::PostMessage( m_hGetVoltageParametersWnd, WM_LGS_GET_VOLTAGE_PARAMETERS, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_VOLTAGE_PARAMETERS: if( m_InMsg.GetEvtSetVoltageParameters( &m_VoltageParameters ) ) ::PostMessage( m_hSetVoltageParametersWnd, WM_LGS_SET_VOLTAGE_PARAMETERS, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_LRF_DISABLE: if( m_InMsg.GetEvtGetLRFDisable( &m_LRFDisable ) ) ::PostMessage( m_hGetLRFDisableWnd, WM_LGS_GET_LRF_DISABLE, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_LRF_DISABLE: if( m_InMsg.GetEvtSetLRFDisable( &m_LRFDisable ) ) ::PostMessage( m_hSetLRFDisableWnd, WM_LGS_SET_LRF_DISABLE, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_WIDTH_TABLE: if( m_InMsg.GetWidthTable( &m_WidthTable ) ) ::PostMessage( m_hGetWidthTableWnd, WM_LGS_GET_WIDTH_TABLE, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_WIDTH_TABLE: if( m_InMsg.GetWidthTable( &m_WidthTable ) ) ::PostMessage( m_hSetWidthTableWnd, WM_LGS_SET_WIDTH_TABLE, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_ZOOM_TABLE: if( m_InMsg.GetZoomTable( &m_ZoomTable ) ) ::PostMessage( m_hGetZoomTableWnd, WM_LGS_GET_ZOOM_TABLE, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_ZOOM_TABLE: if( m_InMsg.GetZoomTable( &m_ZoomTable ) ) ::PostMessage( m_hSetZoomTableWnd, WM_LGS_SET_ZOOM_TABLE, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_TILT_TABLE: if( m_InMsg.GetTiltTable( &m_TiltTable ) ) ::PostMessage( m_hGetTiltTableWnd, WM_LGS_GET_TILT_TABLE, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_TILT_TABLE: if( m_InMsg.GetTiltTable( &m_TiltTable ) ) ::PostMessage( m_hSetTiltTableWnd, WM_LGS_SET_TILT_TABLE, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_PARAMETERS: { CLgDeviceLGS::LGS_PARAMETERS_EX parameters; if( m_InMsg.GetEvtGetParameters( ¶meters ) ) { m_Parameters[parameters.bDevice] = parameters; if( m_hGetParametersWnd[parameters.bDevice] ) { if( !::PostMessage( m_hGetParametersWnd[parameters.bDevice], WM_LGS_PARAMETERS, 0, parameters.bDevice ) ) LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,0,%d) failed"), m_hGetParametersWnd[parameters.bDevice], parameters.bDevice ); else LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,0,%d)"), m_hGetParametersWnd[parameters.bDevice], parameters.bDevice ); } } } break; case CLgDeviceLGS::EVT_SET_PARAMETERS: { CLgDeviceLGS::LGS_PARAMETERS_EX parameters; if( m_InMsg.GetEvtSetParameters( ¶meters ) ) { m_Parameters[parameters.bDevice] = parameters; if( m_hSetParametersWnd[parameters.bDevice] ) { if( !::PostMessage( m_hSetParametersWnd[parameters.bDevice], WM_LGS_PARAMETERS, 1, parameters.bDevice ) ) LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,1,%d) failed"), m_hSetParametersWnd[parameters.bDevice], parameters.bDevice ); else LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,1,%d)"), m_hSetParametersWnd[parameters.bDevice], parameters.bDevice ); } } // notify recipients about reset OnNotifyReset( TRUE, bCommand ); } break; case CLgDeviceLGS::EVT_GET_SERIAL_NUMBER: if( m_InMsg.GetGetSerialNumber( &m_SerialNumber ) ) ::PostMessage( m_hGetSerialNumberWnd, WM_LGS_SERIALNUMBER, 0, 0 ); break; case CLgDeviceLGS::EVT_SET_SERIAL_NUMBER: if( m_InMsg.GetSetSerialNumber( &m_SerialNumber ) ) ::PostMessage( m_hSetAddressWnd, WM_LGS_SERIALNUMBER, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_SET_ADDRESS: if( m_InMsg.GetSetAddress( &m_Address ) ) ::PostMessage( m_hSetAddressWnd, WM_LGS_SET_ADDRESS, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_GET_HZ_DATA_PROGRESS: { INT nProgress; if( m_InMsg.GetEvtGetHzDataProgress( &nProgress ) ) ::PostMessage( m_hGetHzDataWnd, WM_LGS_GET_HZ_DATA_PROGRESS, 0, nProgress ); } break; case CLgDeviceLGS::EVT_GET_HZ_DATA: { if( m_InMsg.GetEvtGetHzData( m_GetHzArray ) ) ::PostMessage( m_hGetHzDataWnd, WM_LGS_GET_HZ_DATA, 0, 0 ); } break; case CLgDeviceLGS::EVT_GET_CALIBRATION_TABLE: case CLgDeviceLGS::EVT_SET_CALIBRATION_TABLE: GeneralTestFunction(); break; case CLgDeviceLGS::EVT_SET_HZ_DATA: if( m_InMsg.GetEvtSetHzData( m_SetHzArray ) ) ::PostMessage( m_hSetHzDataWnd, WM_LGS_SET_HZ_DATA, 1, 0 ); // notify recipients about reset OnNotifyReset( TRUE, bCommand ); break; case CLgDeviceLGS::EVT_SET_HZ_DATA_PROGRESS: { INT nProgress; if( m_InMsg.GetEvtSetHzDataProgress( &nProgress ) ) ::PostMessage( m_hSetHzDataWnd, WM_LGS_SET_HZ_DATA_PROGRESS, 0, nProgress ); } break; case CLgDeviceLGS::EVT_SET_COMM_BAUDRATE: { INT nBaudrate; if( m_InMsg.GetBaudrate( &nBaudrate ) ) { m_nSetCommSpeed = nBaudrate; ::PostMessage(m_hSetCommSpeedWnd, WM_LGS_SET_COMM_SPEED, 1, m_nSetCommSpeed ); SetBaudrate( m_nSetCommSpeed ); } // notify recipients about reset OnNotifyReset( TRUE, bCommand ); } break; case CLgDeviceLGS::EVT_GET_SOFTWARE_VERSION: if( m_InMsg.GetSoftwareVersion( &m_SoftwareVersion ) ) ::PostMessage(m_hSoftwareVersionWnd, WM_LGS_SOFTWARE_VERSION, 0, 0); break; case CLgDeviceLGS::EVT_SEND_BOARDDATA: break; } } } } // __except( EXCEPTION_EXECUTE_HANDLER ) __except( LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "FATAL ERROR: Exception in CLgs::ThreadProc" ), ::Sleep(1), EXCEPTION_CONTINUE_EXECUTION ) { MessageBox( NULL, "FATAL ERROR: Exception in CLgs::ThreadProc", NULL, MB_OK ); } return 0; } void CLgs::GeneralTestFunction() { return; CLgNetMessageLGS msg; CLgDeviceLGS::LGS_CALIBRATION_TABLE ct; ct.nDevice = 1; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetCalibrationTable( ct ); m_Device.SendMessageToChild( msg ); } void CLgs::CmdResetLgs( HWND hWnd ) { m_hResetWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdReset(); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdRestartLgs( HWND hWnd ) { m_hRestartWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdRestart(); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdFullResetLgs(HWND hWnd) { m_hFullResetWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdFullReset(); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdDrawMap( HWND hWnd ) { m_hDrawMapWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdBorder(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdDrawFullMap( HWND hWnd ) { m_hDrawFullMapWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdFullBorder(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetParameters( HWND hWnd, CLgDeviceLGS::PLGS_PARAMETERS_EX pParameters ) { LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::CmdSetParameters"), _T("Wnd %p, Device %d"), hWnd, pParameters->bDevice ); m_hSetParametersWnd[pParameters->bDevice] = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetParameters( pParameters ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetParameters( HWND hWnd, INT nDevice ) { LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::CmdGetParameters"), _T("Wnd %p, Device %d"), hWnd, nDevice ); m_hGetParametersWnd[nDevice] = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetParameters( nDevice ); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSendFile( HWND hWnd, LPCTSTR pSrcFileName, LPCTSTR pDstFileName ) { m_hSendFileWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetFile( pSrcFileName, pDstFileName ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdSetAddress( HWND hWnd, CLgDeviceLGS::LGS_SERIAL_NUMBER *pAddress ) { m_hSetAddressWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetAddress( pAddress->bAddress, pAddress->pSerialNumber, pAddress->bSize ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetSerialNumber( HWND hWnd ) { m_hGetSerialNumberWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetSerialNumber( m_Device.GetAddressLGS() ); m_Device.SendMessageToChild( msg ); } void CLgs::CmdGetSoftwareVersion( HWND hWnd ) { m_hSoftwareVersionWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetSoftwareVersion(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetCommSpeed( HWND hWnd, LONG nSpeed ) { m_hSetCommSpeedWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetCommBaudrate( nSpeed ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } //////////////////////////////////////////////////////////////////////////////////////////////// void CLgs::CmdGetCameraParameters( HWND hWnd ) { m_hGetCameraTypeWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetCameraParameters(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetCameraParameters( HWND hWnd, LGS::PCAMERA_PARAMETERS pParameters ) { m_hSetCameraTypeWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetCameraParameters( pParameters ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetRelayParameters( HWND hWnd ) { m_hGetRelayParametersWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetRelayParameters(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetRelayParameters( HWND hWnd, LGS::PRELAY_PARAMETERS pParameters ) { m_hSetRelayParametersWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetRelayParameters( pParameters ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetWidthTable( HWND hWnd ) { m_hGetWidthTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetWidthTable(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetWidthTable( HWND hWnd, LGS::PWIDTH_TABLE pTable ) { m_hSetWidthTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetWidthTable( pTable ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetZoomTable( HWND hWnd ) { m_hGetZoomTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetZoomTable(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetZoomTable( HWND hWnd, LGS::PZOOM_TABLE pTable ) { m_hSetZoomTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetZoomTable( pTable ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetTiltTable( HWND hWnd ) { m_hGetTiltTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetTiltTable(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetTiltTable( HWND hWnd, LGS::PTILT_TABLE pTable ) { m_hSetTiltTableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetTiltTable( pTable ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetVoltageParameters( HWND hWnd ) { m_hGetVoltageParametersWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetVoltageParameters(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetVoltageParameters( HWND hWnd, LGS::PVOLTAGE_PARAMETERS pParameters ) { m_hSetVoltageParametersWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetVoltageParameters( pParameters ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } void CLgs::CmdGetLRFDisable( HWND hWnd ) { m_hGetLRFDisableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetLRFDisable(); m_Device.SendMessageToChild( msg ); } void CLgs::CmdSetLRFDisable( HWND hWnd, LGS::PLRF_DISABLE pParameters ) { m_hSetLRFDisableWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetLRFDisable( pParameters ); m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); } BOOL CLgs::CmdGetHzData( HWND hWnd, BOOL bRowInclude ) { m_hGetHzDataWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetHzData( bRowInclude ); return m_Device.SendMessageToChild( msg ); } BOOL CLgs::CmdSetHzData( HWND hWnd, CLgDeviceLGS::LGS_HZ_ARRAY& HzArray ) { m_hSetHzDataWnd = hWnd; CLgNetMessageLGS msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetHzData( HzArray ); BOOL bResult = m_Device.SendMessageToChild( msg ); // notify about reset BYTE bCommand; msg.GetCommand( &bCommand ); OnNotifyReset( FALSE, bCommand ); return bResult; } ///////////////////////////////////////////////////////////////////////////////////////////////// // auxilarity subroutines ///////////////////////////////////////////////////////////////////////////////////////////////// void CLgs::OnFinishDraw() { typedef struct { double dAngle[2]; double dRange[2]; int bExist[2]; }BORDER, *PBORDER; HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile ) { DWORD dwNumberOfBytesWritten; DWORD dwNumberOfStructs = LGS_MAX_BORDER_ANGLES; ::WriteFile( hFile, &dwNumberOfStructs, sizeof( dwNumberOfStructs ), &dwNumberOfBytesWritten, NULL ); for( int i = 0; i < dwNumberOfStructs; i++ ) { BORDER border; border.bExist[0] = border.bExist[1] = TRUE; border.dAngle[0] = border.dAngle[1] = i; border.dRange[0] = m_Border.pMaster[i]; border.dRange[1] = m_Border.pSlave[i]; ::WriteFile( hFile, &border, sizeof( border ), &dwNumberOfBytesWritten, NULL ); } ::CloseHandle( hFile ); } } BOOL CLgs::SetBaudrate( INT nSpeed ) { return m_Socket.SetBaudrate( nSpeed ); } ///////////////////////////////////////////////////////////////////////////////////////////////// // camera commands ///////////////////////////////////////////////////////////////////////////////////////////////// BOOL CLgs::IsCameraReady() { return m_bCameraReady; } BOOL CLgs::CmdCameraPan( BOOL bRight, double dSpeed ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdMovePan( bRight, dSpeed ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraTilt( BOOL bUp, double dSpeed ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdMoveTilt( bUp, dSpeed ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraZoom( BOOL bTele, double dSpeed ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdMoveZoom( bTele, dSpeed ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraFocus( BOOL bFar, double dSpeed ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdMoveFocus( bFar, dSpeed ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraIris( double iris ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetIris( iris ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraGotoPosition( double pan, double tilt, double zoom, double focus ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetPTZ( pan, tilt, zoom ); m_Device.SendMessageToChild( msg ); msg.BuildCmdSetFocus( focus ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraGetPosition() { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetFocus(); m_Device.SendMessageToChild( msg ); msg.BuildCmdGetPTZ(); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraDoplerOn( BOOL bOn, INT nDegree, DWORD dwTimeout ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessageDopler msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetDopler( bOn, nDegree, dwTimeout ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraSetDoplerMask( CLgDeviceDopler::PDOPLER_MASK_ARRAY pMask ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessageDopler msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdSetDoplerMask( pMask ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraGetDoplerMask() { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessageDopler msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdGetDoplerMask(); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::CmdCameraWiperOn( BOOL bOn ) { if( !IsCameraReady() ) return FALSE; m_bCameraReady = FALSE; CLgNetMessagePTZ msg; msg.SetDistinationID( m_Device.GetID() ); msg.SetSenderID( m_Socket.GetID() ); msg.BuildCmdWiper( bOn ); m_Device.SendMessageToChild( msg ); return TRUE; } BOOL CLgs::GetCameraPosition( CLgDevicePTZ::PTZ_DEGREE *pPan, CLgDevicePTZ::PTZ_DEGREE *pTilt, CLgDevicePTZ::PTZ_PERCENT *pZoom, CLgDevicePTZ::PTZ_PERCENT *pFocus ) { if( !IsCameraReady() ) return FALSE; if( pPan ) *pPan = m_CameraPosition.dPan; if( pTilt ) *pTilt = m_CameraPosition.dTilt; if( pZoom ) *pZoom = m_CameraPosition.dZoom; if( pFocus ) *pFocus = m_CameraFocus; return TRUE; } BOOL CLgs::RegisterNotify( INT eType, HWND hWnd ) { CLgLocker Lock( &m_NotifyArray ); for( INT i = 0; i < m_NotifyArray.GetCount(); i++ ) { if( m_NotifyArray[i].hWnd == hWnd ) { m_NotifyArray[i].eType = m_NotifyArray[i].eType || eType; return TRUE; } } NOTIFY_RECIPIENT nr; nr.eType = eType; nr.hWnd = hWnd; return m_NotifyArray.Add( nr ); } void CLgs::OnNotifyConnect( BOOL bConnected ) { CLgLocker Lock( &m_NotifyArray ); for( INT i = 0; i < m_NotifyArray.GetCount(); ) { // garbage collection if( !::IsWindow( m_NotifyArray[i].hWnd ) ) { m_NotifyArray.Remove(i); continue; } // send notification if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_CONNECT ) == NOTIFY_TYPE_CONNECT ) ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_CONNECT, bConnected, 0 ); // get next i++; } } void CLgs::OnNotifyReset( BOOL bFinished, INT nResetCommand ) { CLgLocker Lock( &m_NotifyArray ); for( INT i = 0; i < m_NotifyArray.GetCount(); ) { // garbage collection if( !::IsWindow( m_NotifyArray[i].hWnd ) ) { m_NotifyArray.Remove(i); continue; } // send notification if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_RESET ) == NOTIFY_TYPE_RESET ) ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_RESET, bFinished, nResetCommand ); // get next i++; } } void CLgs::OnNotifyCommandError( INT nCommand ) { CLgLocker Lock( &m_NotifyArray ); for( INT i = 0; i < m_NotifyArray.GetCount(); ) { // garbage collection if( !::IsWindow( m_NotifyArray[i].hWnd ) ) { m_NotifyArray.Remove(i); continue; } // send notification if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_COMMAND_ERROR ) == NOTIFY_TYPE_COMMAND_ERROR ) ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_COMMAND_ERROR, nCommand, 0 ); // get next i++; } }