Old fashion design for PC-104
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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: SingleIPI.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of SingleIPI.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "SingleIPI.h"
  16. #include "BorderLGS.h"
  17. #include "HiddenZoneList.h"
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[]=__FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23. CSingleIPI::CSingleIPI()
  24. {
  25. m_pBorderLGS = NULL;
  26. memset( m_pExecutableName, 0, sizeof(m_pExecutableName) );
  27. }
  28. CSingleIPI::~CSingleIPI()
  29. {
  30. }
  31. bool CSingleIPI::SetBorderLGS( CBorderLGS *pBorderLGS )
  32. {
  33. m_pBorderLGS = pBorderLGS;
  34. return true;
  35. }
  36. bool CSingleIPI::SetZeroShift( double dZeroShift, BOOL bClockwise )
  37. {
  38. m_Profile.LgsDisplayClockwise() = bClockwise;
  39. if( bClockwise ) m_Profile.LgsDisplayZeroShift() = 360 - dZeroShift;
  40. else m_Profile.LgsDisplayZeroShift() = (int)dZeroShift;
  41. return true;
  42. }
  43. bool CSingleIPI::GetZeroShift( double *pZeroShift, PBOOL pClockWise )
  44. {
  45. *pClockWise = m_Profile.LgsDisplayClockwise();
  46. if( m_Profile.LgsDisplayClockwise() ) *pZeroShift = 360 - m_Profile.LgsDisplayZeroShift();
  47. else *pZeroShift = m_Profile.LgsDisplayZeroShift();
  48. return true;
  49. }
  50. bool CSingleIPI::SetCameraParams( INT nType, LPCTSTR pCommPort, int nVideoDevice, int nVideoInput,
  51. BOOL bMigvanAuto, PBYTE pMigvanSerialNumber, INT nMic1300Address,
  52. BOOL bRemoteCamera, double dShift, double *pTiltTable, COFDeviceSensor::PTRANSFORM pTransform,
  53. double *pZoomTable, double *pFocusTable, INT nDoplerAngle, DWORD nDoplerTimeout )
  54. {
  55. strcpy( (char*)m_Profile.PtzCommPort(), (char*)pCommPort );
  56. m_Profile.VideoDevice() = nVideoDevice;
  57. m_Profile.VideoInput() = nVideoInput;
  58. m_Profile.PtzType() = (PTZ_CAMERA_TYPE)nType;
  59. m_Profile.PtzMigvanSerialNumberManual() = !bMigvanAuto;
  60. memcpy( m_Profile.PtzMigvanSerialNumber(), pMigvanSerialNumber, 5 );
  61. m_Profile.PtzMic1300Address() = nMic1300Address;
  62. m_Profile.get_remote_flag() = bRemoteCamera;
  63. m_Profile.PtzPanShift() = (int)dShift;
  64. for( int i = 0; i < 10; i++ )
  65. {
  66. m_Profile.PtzRangeZoom(i) = (int)pZoomTable[i];
  67. m_Profile.PtzRangeTilt(i) = (int)pTiltTable[i];
  68. m_Profile.PtzRangeFocus(i) = (int)pFocusTable[i];
  69. }
  70. m_Profile.get_master_Xc() = pTransform[0].m_dX;
  71. m_Profile.get_master_Yc() = pTransform[0].m_dY;
  72. m_Profile.get_master_Zc() = pTransform[0].m_dZ;
  73. m_Profile.get_master_Psi() = pTransform[0].m_dPsi;
  74. m_Profile.get_master_Theta() = pTransform[0].m_dTheta;
  75. m_Profile.get_master_Phi() = pTransform[0].m_dPhi;
  76. m_Profile.get_slave_Xc() = pTransform[1].m_dX;
  77. m_Profile.get_slave_Yc() = pTransform[1].m_dY;
  78. m_Profile.get_slave_Zc() = pTransform[1].m_dZ;
  79. m_Profile.get_slave_Psi() = pTransform[1].m_dPsi;
  80. m_Profile.get_slave_Theta() = pTransform[1].m_dTheta;
  81. m_Profile.get_slave_Phi() = pTransform[1].m_dPhi;
  82. m_Profile.DoplerAngle() = nDoplerAngle;
  83. m_Profile.DoplerTimeout() = nDoplerTimeout;
  84. return true;
  85. }
  86. bool CSingleIPI::GetCameraParams( PBOOL pRemoteCamera, double *pShift, double *pTiltTable, COFDeviceSensor::PTRANSFORM pTransform,
  87. double *pZoomTable, double *pFocusTable, PINT pDoplerAngle, PDWORD pDoplerTimeout )
  88. {
  89. *pRemoteCamera = m_Profile.get_remote_flag();
  90. *pShift = m_Profile.PtzPanShift();
  91. for( int i = 0; i < 10; i++ )
  92. {
  93. pZoomTable[i] = m_Profile.PtzRangeZoom(i);
  94. pTiltTable[i] = m_Profile.PtzRangeTilt(i);
  95. pFocusTable[i] = m_Profile.PtzRangeFocus(i);
  96. }
  97. pTransform[0].m_dX = m_Profile.get_master_Xc();
  98. pTransform[0].m_dY = m_Profile.get_master_Yc();
  99. pTransform[0].m_dZ = m_Profile.get_master_Zc();
  100. pTransform[0].m_dPsi = m_Profile.get_master_Psi();
  101. pTransform[0].m_dTheta = m_Profile.get_master_Theta();
  102. pTransform[0].m_dPhi = m_Profile.get_master_Phi();
  103. pTransform[1].m_dX = m_Profile.get_slave_Xc();
  104. pTransform[1].m_dY = m_Profile.get_slave_Yc();
  105. pTransform[1].m_dZ = m_Profile.get_slave_Zc();
  106. pTransform[1].m_dPsi = m_Profile.get_slave_Psi();
  107. pTransform[1].m_dTheta = m_Profile.get_slave_Theta();
  108. pTransform[1].m_dPhi = m_Profile.get_slave_Phi();
  109. *pDoplerAngle = m_Profile.DoplerAngle();
  110. *pDoplerTimeout = m_Profile.DoplerTimeout();
  111. return true;
  112. }
  113. bool CSingleIPI::SetLgsParams( LPCTSTR pCommPort, int nBaudRate, int nAddress, double dRange,
  114. int MasterOffset, int MasterDelta, int MasterWidth, int MasterOrder, int MasterSST, int MasterFlip,
  115. int SlaveOffset, int SlaveDelta, int SlaveWidth, int SlaveOrder, int SlaveSST, int SlaveFlip )
  116. {
  117. strcpy( (char*)m_Profile.LgsCommPort(), (char*)pCommPort );
  118. m_Profile.LgsBaudRate() = nBaudRate;
  119. m_Profile.LgsAddress() = nAddress;
  120. m_Profile.LgsRange() = (INT)dRange;
  121. m_Profile.GetData().LgsMasterOffset = MasterOffset;
  122. m_Profile.GetData().LgsMasterDelta = MasterDelta;
  123. m_Profile.GetData().LgsMasterWidth = MasterWidth;
  124. m_Profile.GetData().LgsMasterOrder = MasterOrder;
  125. m_Profile.GetData().LgsMasterSST = MasterSST;
  126. m_Profile.GetData().LgsMasterFlip = MasterFlip;
  127. m_Profile.GetData().LgsSlaveOffset = SlaveOffset;
  128. m_Profile.GetData().LgsSlaveDelta = SlaveDelta;
  129. m_Profile.GetData().LgsSlaveWidth = SlaveWidth;
  130. m_Profile.GetData().LgsSlaveOrder = SlaveOrder;
  131. m_Profile.GetData().LgsSlaveSST = SlaveSST;
  132. m_Profile.GetData().LgsSlaveFlip = SlaveFlip;
  133. return true;
  134. }
  135. bool CSingleIPI::GetLgsParams( double &dRange,
  136. int &MasterOffset, int &MasterDelta, int &MasterWidth, int &MasterOrder, int &MasterSST, int &MasterFlip,
  137. int &SlaveOffset, int &SlaveDelta, int &SlaveWidth, int &SlaveOrder, int &SlaveSST, int &SlaveFlip )
  138. {
  139. dRange = m_Profile.GetData().LgsRange;
  140. MasterOffset = m_Profile.GetData().LgsMasterOffset;
  141. MasterDelta = m_Profile.GetData().LgsMasterDelta;
  142. MasterWidth = m_Profile.GetData().LgsMasterWidth;
  143. MasterOrder = m_Profile.GetData().LgsMasterOrder;
  144. MasterSST = m_Profile.GetData().LgsMasterSST;
  145. MasterFlip = m_Profile.GetData().LgsMasterFlip;
  146. SlaveOffset = m_Profile.GetData().LgsSlaveOffset;
  147. SlaveDelta = m_Profile.GetData().LgsSlaveDelta;
  148. SlaveWidth = m_Profile.GetData().LgsSlaveWidth;
  149. SlaveOrder = m_Profile.GetData().LgsSlaveOrder;
  150. SlaveSST = m_Profile.GetData().LgsSlaveSST;
  151. SlaveFlip = m_Profile.GetData().LgsSlaveFlip;
  152. return true;
  153. }
  154. bool CSingleIPI::Run( bool bWait, LPCTSTR pExecutableName, CWnd *pWnd )
  155. {
  156. if( pExecutableName )
  157. _tcscpy( m_pExecutableName, pExecutableName );
  158. else
  159. _tcscpy( m_pExecutableName, _T("SingleIPI.exe") );
  160. m_pParentWnd = pWnd;
  161. if( bWait )
  162. return OnRun();
  163. return Start( FALSE ) == TRUE;
  164. }
  165. /*
  166. bool CSingleIPI::OnRun()
  167. {
  168. // store current folder
  169. TCHAR pStoredCurrentDirectory[MAX_PATH];
  170. ::GetCurrentDirectory( MAX_PATH, pStoredCurrentDirectory );
  171. // prepare working folder
  172. TCHAR pPathName[MAX_PATH];
  173. LPCTSTR pDirectory = pPathName;
  174. ::GetModuleFileName( NULL, pPathName, MAX_PATH );
  175. ::PathRemoveFileSpec( pPathName );
  176. ::PathAppend( pPathName, "SingleIPI" );
  177. ::CreateDirectory( pDirectory, NULL );
  178. // copy executable
  179. TCHAR pExecutableFileName[MAX_PATH];
  180. ::PathCombine( pExecutableFileName, pDirectory, m_pExecutableName );
  181. ::CopyFile( m_pExecutableName, pExecutableFileName, FALSE );
  182. // delete old files !!!
  183. TCHAR pRemoveDataFile[MAX_PATH];
  184. ::PathCombine( pRemoveDataFile, pPathName, "DrawMap.dat" );
  185. ::DeleteFile( pRemoveDataFile );
  186. ::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen020() );
  187. ::DeleteFile( pRemoveDataFile );
  188. ::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen050() );
  189. ::DeleteFile( pRemoveDataFile );
  190. ::PathCombine( pRemoveDataFile, pPathName, m_Profile.SettingsScreen100() );
  191. ::DeleteFile( pRemoveDataFile );
  192. // set work directory
  193. ::SetCurrentDirectory( pDirectory );
  194. // update SingleIPI's profile
  195. m_Profile.Save( "SingleIPI.dat" );
  196. // store border data
  197. if( m_pBorderLGS )
  198. m_pBorderLGS->SaveAsSingleIPI( "DrawMap.dat" );
  199. // store hidden zones
  200. if( m_pHiddenZoneList )
  201. m_pHiddenZoneList->SaveAsSingleIPI( "Hidden.dat" );
  202. // run SingleIPI
  203. STARTUPINFO si;
  204. PROCESS_INFORMATION pi;
  205. ::ZeroMemory( &si, sizeof(si) );
  206. ::ZeroMemory( &pi, sizeof(pi) );
  207. // prepare workaround
  208. TCHAR pCommandLineWithParam[MAX_PATH];
  209. strcpy( pCommandLineWithParam, pExecutableFileName );
  210. #ifndef SETUP_DEMO_VERSION
  211. strcat( pCommandLineWithParam, " SETUP" );
  212. #endif
  213. if( !::CreateProcess( pExecutableFileName, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
  214. // prepare workaround
  215. // TCHAR pCommandLine[MAX_PATH];
  216. // ::PathCombine( pCommandLine, pStoredCurrentDirectory, m_pExecutableName );
  217. // TCHAR pCommandLineWithParam[MAX_PATH];
  218. // strcpy( pCommandLineWithParam, pCommandLine );
  219. #ifndef SETUP_DEMO_VERSION
  220. // strcat( pCommandLineWithParam, " SETUP" );
  221. #endif
  222. // if( !::CreateProcess( pCommandLine, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
  223. // TCHAR pRelativePath[MAX_PATH];
  224. // PathRelativePathTo( pRelativePath, pDirectory, FILE_ATTRIBUTE_DIRECTORY, pCommandLine, 0 );
  225. // TCHAR pRelativePathWithParam[MAX_PATH];
  226. // strcpy( pRelativePathWithParam, pRelativePath );
  227. #ifndef SETUP_DEMO_VERSION
  228. // strcat( pRelativePathWithParam, " SETUP" );
  229. #endif
  230. // if( !::CreateProcess( pRelativePath, pRelativePathWithParam, NULL, NULL, FALSE, 0, NULL, pDirectory, &si, &pi ) )
  231. {
  232. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSingleIPI::OnRun"), _T("CreateProcess failed with 0x%08X"), GetLastError() );
  233. // restore current folder
  234. ::SetCurrentDirectory( pStoredCurrentDirectory );
  235. return false;
  236. }
  237. bool bResult = false;
  238. // wait for end of SingleIPI
  239. if( CLgThread::GetThreadStopEvent() )
  240. {
  241. HANDLE pEvent[] = { CLgThread::GetThreadStopEvent(), pi.hProcess };
  242. bResult = ::WaitForMultipleObjects( 2, pEvent, FALSE, INFINITE ) == ( WAIT_OBJECT_0 + 1 );
  243. }
  244. else
  245. bResult = ::WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0;
  246. // load results
  247. if( bResult )
  248. {
  249. // load hidden zones
  250. if( m_pHiddenZoneList )
  251. m_pHiddenZoneList->LoadAsSingleIPI( "Hidden.dat" );
  252. // load camera shift
  253. m_Profile.Load( "SingleIPI.dat" );
  254. // load border data
  255. if( m_pBorderLGS )
  256. m_pBorderLGS->LoadAsSingleIPI( "DrawMap.dat" );
  257. }
  258. // restore current folder
  259. ::SetCurrentDirectory( pStoredCurrentDirectory );
  260. return bResult;
  261. }
  262. */
  263. bool CSingleIPI::OnRun()
  264. {
  265. // delete old files !!!
  266. ::DeleteFile( "DrawMap.dat" );
  267. ::DeleteFile( m_Profile.SettingsScreen020() );
  268. ::DeleteFile( m_Profile.SettingsScreen050() );
  269. ::DeleteFile( m_Profile.SettingsScreen100() );
  270. // update SingleIPI's profile
  271. m_Profile.Save( "SingleIPI.dat" );
  272. // store border data
  273. if( m_pBorderLGS )
  274. m_pBorderLGS->SaveAsSingleIPI( "DrawMap.dat" );
  275. // run SingleIPI
  276. STARTUPINFO si;
  277. PROCESS_INFORMATION pi;
  278. ::ZeroMemory( &si, sizeof(si) );
  279. ::ZeroMemory( &pi, sizeof(pi) );
  280. // prepare workaround
  281. TCHAR pCommandLineWithParam[MAX_PATH];
  282. strcpy( pCommandLineWithParam, m_pExecutableName );
  283. #ifndef SETUP_DEMO_VERSION
  284. strcat( pCommandLineWithParam, " SETUP" );
  285. #endif
  286. strcat( pCommandLineWithParam, " NORESTART" );
  287. if( !::CreateProcess( m_pExecutableName, pCommandLineWithParam, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) )
  288. {
  289. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSingleIPI::OnRun"), _T("CreateProcess failed with 0x%08X"), GetLastError() );
  290. return false;
  291. }
  292. m_pParentWnd->ShowWindow( SW_MINIMIZE );
  293. bool bResult = false;
  294. // wait for end of SingleIPI
  295. if( CLgThread::GetThreadStopEvent() )
  296. {
  297. HANDLE pEvent[] = { CLgThread::GetThreadStopEvent(), pi.hProcess };
  298. bResult = ::WaitForMultipleObjects( 2, pEvent, FALSE, INFINITE ) == ( WAIT_OBJECT_0 + 1 );
  299. }
  300. else
  301. bResult = ::WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_OBJECT_0;
  302. // load results
  303. if( bResult )
  304. {
  305. // load camera shift
  306. m_Profile.Load( "SingleIPI.dat" );
  307. // load border data
  308. if( m_pBorderLGS )
  309. m_pBorderLGS->LoadAsSingleIPI( "DrawMap.dat" );
  310. }
  311. m_pParentWnd->ShowWindow( SW_RESTORE );
  312. return bResult;
  313. }
  314. DWORD CSingleIPI::ThreadProc()
  315. {
  316. return OnRun();
  317. }