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.
384 lines
12 KiB
384 lines
12 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: SingleIPI.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of SingleIPI.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "SingleIPI.h"
|
|
#include "BorderLGS.h"
|
|
#include "HiddenZoneList.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
CSingleIPI::CSingleIPI()
|
|
{
|
|
m_pBorderLGS = NULL;
|
|
memset( m_pExecutableName, 0, sizeof(m_pExecutableName) );
|
|
}
|
|
|
|
CSingleIPI::~CSingleIPI()
|
|
{
|
|
|
|
}
|
|
|
|
bool CSingleIPI::SetBorderLGS( CBorderLGS *pBorderLGS )
|
|
{
|
|
m_pBorderLGS = pBorderLGS;
|
|
return true;
|
|
}
|
|
|
|
bool CSingleIPI::SetZeroShift( double dZeroShift, BOOL bClockwise )
|
|
{
|
|
m_Profile.LgsDisplayClockwise() = bClockwise;
|
|
if( bClockwise ) m_Profile.LgsDisplayZeroShift() = 360 - dZeroShift;
|
|
else m_Profile.LgsDisplayZeroShift() = (int)dZeroShift;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CSingleIPI::GetZeroShift( double *pZeroShift, PBOOL pClockWise )
|
|
{
|
|
*pClockWise = m_Profile.LgsDisplayClockwise();
|
|
if( m_Profile.LgsDisplayClockwise() ) *pZeroShift = 360 - m_Profile.LgsDisplayZeroShift();
|
|
else *pZeroShift = m_Profile.LgsDisplayZeroShift();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CSingleIPI::SetCameraParams( INT nType, LPCTSTR pCommPort, int nVideoDevice, int nVideoInput,
|
|
BOOL bMigvanAuto, PBYTE pMigvanSerialNumber, INT nMic1300Address,
|
|
BOOL bRemoteCamera, double dShift, double *pTiltTable, COFDeviceSensor::PTRANSFORM pTransform,
|
|
double *pZoomTable, double *pFocusTable, INT nDoplerAngle, DWORD nDoplerTimeout )
|
|
{
|
|
strcpy( (char*)m_Profile.PtzCommPort(), (char*)pCommPort );
|
|
|
|
m_Profile.VideoDevice() = nVideoDevice;
|
|
m_Profile.VideoInput() = nVideoInput;
|
|
|
|
m_Profile.PtzType() = (PTZ_CAMERA_TYPE)nType;
|
|
m_Profile.PtzMigvanSerialNumberManual() = !bMigvanAuto;
|
|
memcpy( m_Profile.PtzMigvanSerialNumber(), pMigvanSerialNumber, 5 );
|
|
m_Profile.PtzMic1300Address() = nMic1300Address;
|
|
|
|
m_Profile.get_remote_flag() = bRemoteCamera;
|
|
m_Profile.PtzPanShift() = (int)dShift;
|
|
for( int i = 0; i < 10; i++ )
|
|
{
|
|
m_Profile.PtzRangeZoom(i) = (int)pZoomTable[i];
|
|
m_Profile.PtzRangeTilt(i) = (int)pTiltTable[i];
|
|
m_Profile.PtzRangeFocus(i) = (int)pFocusTable[i];
|
|
}
|
|
m_Profile.get_master_Xc() = pTransform[0].m_dX;
|
|
m_Profile.get_master_Yc() = pTransform[0].m_dY;
|
|
m_Profile.get_master_Zc() = pTransform[0].m_dZ;
|
|
m_Profile.get_master_Psi() = pTransform[0].m_dPsi;
|
|
m_Profile.get_master_Theta() = pTransform[0].m_dTheta;
|
|
m_Profile.get_master_Phi() = pTransform[0].m_dPhi;
|
|
m_Profile.get_slave_Xc() = pTransform[1].m_dX;
|
|
m_Profile.get_slave_Yc() = pTransform[1].m_dY;
|
|
m_Profile.get_slave_Zc() = pTransform[1].m_dZ;
|
|
m_Profile.get_slave_Psi() = pTransform[1].m_dPsi;
|
|
m_Profile.get_slave_Theta() = pTransform[1].m_dTheta;
|
|
m_Profile.get_slave_Phi() = pTransform[1].m_dPhi;
|
|
|
|
m_Profile.DoplerAngle() = nDoplerAngle;
|
|
m_Profile.DoplerTimeout() = nDoplerTimeout;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CSingleIPI::GetCameraParams( PBOOL pRemoteCamera, double *pShift, double *pTiltTable, COFDeviceSensor::PTRANSFORM pTransform,
|
|
double *pZoomTable, double *pFocusTable, PINT pDoplerAngle, PDWORD pDoplerTimeout )
|
|
{
|
|
*pRemoteCamera = m_Profile.get_remote_flag();
|
|
*pShift = m_Profile.PtzPanShift();
|
|
for( int i = 0; i < 10; i++ )
|
|
{
|
|
pZoomTable[i] = m_Profile.PtzRangeZoom(i);
|
|
pTiltTable[i] = m_Profile.PtzRangeTilt(i);
|
|
pFocusTable[i] = m_Profile.PtzRangeFocus(i);
|
|
}
|
|
pTransform[0].m_dX = m_Profile.get_master_Xc();
|
|
pTransform[0].m_dY = m_Profile.get_master_Yc();
|
|
pTransform[0].m_dZ = m_Profile.get_master_Zc();
|
|
pTransform[0].m_dPsi = m_Profile.get_master_Psi();
|
|
pTransform[0].m_dTheta = m_Profile.get_master_Theta();
|
|
pTransform[0].m_dPhi = m_Profile.get_master_Phi();
|
|
pTransform[1].m_dX = m_Profile.get_slave_Xc();
|
|
pTransform[1].m_dY = m_Profile.get_slave_Yc();
|
|
pTransform[1].m_dZ = m_Profile.get_slave_Zc();
|
|
pTransform[1].m_dPsi = m_Profile.get_slave_Psi();
|
|
pTransform[1].m_dTheta = m_Profile.get_slave_Theta();
|
|
pTransform[1].m_dPhi = m_Profile.get_slave_Phi();
|
|
|
|
*pDoplerAngle = m_Profile.DoplerAngle();
|
|
*pDoplerTimeout = m_Profile.DoplerTimeout();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool CSingleIPI::SetLgsParams( LPCTSTR pCommPort, int nBaudRate, int nAddress, double dRange,
|
|
int MasterOffset, int MasterDelta, int MasterWidth, int MasterOrder, int MasterSST, int MasterFlip,
|
|
int SlaveOffset, int SlaveDelta, int SlaveWidth, int SlaveOrder, int SlaveSST, int SlaveFlip )
|
|
{
|
|
strcpy( (char*)m_Profile.LgsCommPort(), (char*)pCommPort );
|
|
m_Profile.LgsBaudRate() = nBaudRate;
|
|
m_Profile.LgsAddress() = nAddress;
|
|
m_Profile.LgsRange() = (INT)dRange;
|
|
|
|
m_Profile.GetData().LgsMasterOffset = MasterOffset;
|
|
m_Profile.GetData().LgsMasterDelta = MasterDelta;
|
|
m_Profile.GetData().LgsMasterWidth = MasterWidth;
|
|
m_Profile.GetData().LgsMasterOrder = MasterOrder;
|
|
m_Profile.GetData().LgsMasterSST = MasterSST;
|
|
m_Profile.GetData().LgsMasterFlip = MasterFlip;
|
|
|
|
m_Profile.GetData().LgsSlaveOffset = SlaveOffset;
|
|
m_Profile.GetData().LgsSlaveDelta = SlaveDelta;
|
|
m_Profile.GetData().LgsSlaveWidth = SlaveWidth;
|
|
m_Profile.GetData().LgsSlaveOrder = SlaveOrder;
|
|
m_Profile.GetData().LgsSlaveSST = SlaveSST;
|
|
m_Profile.GetData().LgsSlaveFlip = SlaveFlip;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CSingleIPI::GetLgsParams( double &dRange,
|
|
int &MasterOffset, int &MasterDelta, int &MasterWidth, int &MasterOrder, int &MasterSST, int &MasterFlip,
|
|
int &SlaveOffset, int &SlaveDelta, int &SlaveWidth, int &SlaveOrder, int &SlaveSST, int &SlaveFlip )
|
|
{
|
|
dRange = m_Profile.GetData().LgsRange;
|
|
|
|
MasterOffset = m_Profile.GetData().LgsMasterOffset;
|
|
MasterDelta = m_Profile.GetData().LgsMasterDelta;
|
|
MasterWidth = m_Profile.GetData().LgsMasterWidth;
|
|
MasterOrder = m_Profile.GetData().LgsMasterOrder;
|
|
MasterSST = m_Profile.GetData().LgsMasterSST;
|
|
MasterFlip = m_Profile.GetData().LgsMasterFlip;
|
|
|
|
SlaveOffset = m_Profile.GetData().LgsSlaveOffset;
|
|
SlaveDelta = m_Profile.GetData().LgsSlaveDelta;
|
|
SlaveWidth = m_Profile.GetData().LgsSlaveWidth;
|
|
SlaveOrder = m_Profile.GetData().LgsSlaveOrder;
|
|
SlaveSST = m_Profile.GetData().LgsSlaveSST;
|
|
SlaveFlip = m_Profile.GetData().LgsSlaveFlip;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool CSingleIPI::Run( bool bWait, LPCTSTR pExecutableName, CWnd *pWnd )
|
|
{
|
|
if( pExecutableName )
|
|
_tcscpy( m_pExecutableName, pExecutableName );
|
|
else
|
|
_tcscpy( m_pExecutableName, _T("SingleIPI.exe") );
|
|
|
|
m_pParentWnd = pWnd;
|
|
|
|
if( bWait )
|
|
return OnRun();
|
|
|
|
return Start( FALSE ) == TRUE;
|
|
}
|
|
|
|
/*
|
|
bool CSingleIPI::OnRun()
|
|
{
|
|
// store current folder
|
|
TCHAR pStoredCurrentDirectory[MAX_PATH];
|
|
::GetCurrentDirectory( MAX_PATH, pStoredCurrentDirectory );
|
|
|
|
// prepare working folder
|
|
TCHAR pPathName[MAX_PATH];
|
|
LPCTSTR pDirectory = pPathName;
|
|
::GetModuleFileName( NULL, pPathName, MAX_PATH );
|
|
::PathRemoveFileSpec( pPathName );
|
|
::PathAppend( pPathName, "SingleIPI" );
|
|
::CreateDirectory( pDirectory, NULL );
|
|
|
|
// copy executable
|
|
TCHAR pExecutableFileName[MAX_PATH];
|
|
::PathCombine( pExecutableFileName, pDirectory, m_pExecutableName );
|
|
::CopyFile( m_pExecutableName, pExecutableFileName, FALSE );
|
|
|
|
// delete old files !!!
|
|
TCHAR pRemoveDataFile[MAX_PATH];
|
|
::PathCombine( pRemoveDataFile, pPathName, "DrawMap.dat" );
|
|
::DeleteFile( pRemoveDataFile );
|
|
::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen020() );
|
|
::DeleteFile( pRemoveDataFile );
|
|
::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen050() );
|
|
::DeleteFile( pRemoveDataFile );
|
|
::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen100() );
|
|
::DeleteFile( pRemoveDataFile );
|
|
|
|
// set work directory
|
|
::SetCurrentDirectory( pDirectory );
|
|
|
|
// update SingleIPI's profile
|
|
m_Profile.Save( "SingleIPI.dat" );
|
|
|
|
// store border data
|
|
if( m_pBorderLGS )
|
|
m_pBorderLGS->SaveAsSingleIPI( "DrawMap.dat" );
|
|
|
|
// store hidden zones
|
|
if( m_pHiddenZoneList )
|
|
m_pHiddenZoneList->SaveAsSingleIPI( "Hidden.dat" );
|
|
|
|
// run SingleIPI
|
|
STARTUPINFO si;
|
|
PROCESS_INFORMATION pi;
|
|
::ZeroMemory( &si, sizeof(si) );
|
|
::ZeroMemory( &pi, sizeof(pi) );
|
|
|
|
// prepare workaround
|
|
TCHAR pCommandLineWithParam[MAX_PATH];
|
|
strcpy( pCommandLineWithParam, pExecutableFileName );
|
|
#ifndef SETUP_DEMO_VERSION
|
|
strcat( pCommandLineWithParam, " SETUP" );
|
|
#endif
|
|
if( !::CreateProcess( pExecutableFileName, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
|
|
|
|
|
|
// prepare workaround
|
|
// TCHAR pCommandLine[MAX_PATH];
|
|
// ::PathCombine( pCommandLine, pStoredCurrentDirectory, m_pExecutableName );
|
|
// TCHAR pCommandLineWithParam[MAX_PATH];
|
|
// strcpy( pCommandLineWithParam, pCommandLine );
|
|
#ifndef SETUP_DEMO_VERSION
|
|
// strcat( pCommandLineWithParam, " SETUP" );
|
|
#endif
|
|
// if( !::CreateProcess( pCommandLine, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
|
|
|
|
|
|
// TCHAR pRelativePath[MAX_PATH];
|
|
// PathRelativePathTo( pRelativePath, pDirectory, FILE_ATTRIBUTE_DIRECTORY, pCommandLine, 0 );
|
|
// TCHAR pRelativePathWithParam[MAX_PATH];
|
|
// strcpy( pRelativePathWithParam, pRelativePath );
|
|
#ifndef SETUP_DEMO_VERSION
|
|
// strcat( pRelativePathWithParam, " SETUP" );
|
|
#endif
|
|
// if( !::CreateProcess( pRelativePath, pRelativePathWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSingleIPI::OnRun"), _T("CreateProcess failed with 0x%08X"), GetLastError() );
|
|
|
|
// restore current folder
|
|
::SetCurrentDirectory( pStoredCurrentDirectory );
|
|
return false;
|
|
}
|
|
|
|
bool bResult = false;
|
|
|
|
// wait for end of SingleIPI
|
|
if( CLgThread::GetThreadStopEvent() )
|
|
{
|
|
HANDLE pEvent[] = { CLgThread::GetThreadStopEvent(), pi.hProcess };
|
|
bResult = ::WaitForMultipleObjects( 2, pEvent, FALSE, INFINITE ) == ( WAIT_OBJECT_0 + 1 );
|
|
}
|
|
else
|
|
bResult = ::WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0;
|
|
|
|
// load results
|
|
if( bResult )
|
|
{
|
|
// load hidden zones
|
|
if( m_pHiddenZoneList )
|
|
m_pHiddenZoneList->LoadAsSingleIPI( "Hidden.dat" );
|
|
|
|
// load camera shift
|
|
m_Profile.Load( "SingleIPI.dat" );
|
|
|
|
// load border data
|
|
if( m_pBorderLGS )
|
|
m_pBorderLGS->LoadAsSingleIPI( "DrawMap.dat" );
|
|
}
|
|
|
|
// restore current folder
|
|
::SetCurrentDirectory( pStoredCurrentDirectory );
|
|
|
|
return bResult;
|
|
}
|
|
*/
|
|
|
|
bool CSingleIPI::OnRun()
|
|
{
|
|
// delete old files !!!
|
|
::DeleteFile( "DrawMap.dat" );
|
|
::DeleteFile( m_Profile.SettingsScreen020() );
|
|
::DeleteFile( m_Profile.SettingsScreen050() );
|
|
::DeleteFile( m_Profile.SettingsScreen100() );
|
|
|
|
// update SingleIPI's profile
|
|
m_Profile.Save( "SingleIPI.dat" );
|
|
|
|
// store border data
|
|
if( m_pBorderLGS )
|
|
m_pBorderLGS->SaveAsSingleIPI( "DrawMap.dat" );
|
|
|
|
// run SingleIPI
|
|
STARTUPINFO si;
|
|
PROCESS_INFORMATION pi;
|
|
::ZeroMemory( &si, sizeof(si) );
|
|
::ZeroMemory( &pi, sizeof(pi) );
|
|
|
|
// prepare workaround
|
|
TCHAR pCommandLineWithParam[MAX_PATH];
|
|
strcpy( pCommandLineWithParam, m_pExecutableName );
|
|
#ifndef SETUP_DEMO_VERSION
|
|
strcat( pCommandLineWithParam, " SETUP" );
|
|
#endif
|
|
strcat( pCommandLineWithParam, " NORESTART" );
|
|
if( !::CreateProcess( m_pExecutableName, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSingleIPI::OnRun"), _T("CreateProcess failed with 0x%08X"), GetLastError() );
|
|
return false;
|
|
}
|
|
|
|
m_pParentWnd->ShowWindow( SW_MINIMIZE );
|
|
|
|
bool bResult = false;
|
|
|
|
// wait for end of SingleIPI
|
|
if( CLgThread::GetThreadStopEvent() )
|
|
{
|
|
HANDLE pEvent[] = { CLgThread::GetThreadStopEvent(), pi.hProcess };
|
|
bResult = ::WaitForMultipleObjects( 2, pEvent, FALSE, INFINITE ) == ( WAIT_OBJECT_0 + 1 );
|
|
}
|
|
else
|
|
bResult = ::WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0;
|
|
|
|
// load results
|
|
if( bResult )
|
|
{
|
|
// load camera shift
|
|
m_Profile.Load( "SingleIPI.dat" );
|
|
|
|
// load border data
|
|
if( m_pBorderLGS )
|
|
m_pBorderLGS->LoadAsSingleIPI( "DrawMap.dat" );
|
|
}
|
|
|
|
m_pParentWnd->ShowWindow( SW_RESTORE );
|
|
|
|
return bResult;
|
|
}
|
|
|
|
DWORD CSingleIPI::ThreadProc()
|
|
{
|
|
return OnRun();
|
|
}
|