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.

2275 lines
74 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
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: SensorArray.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of SensorArray.cpp
  13. //----------------------------------------------------------------------------
  14. // SensorArray.cpp: implementation of the CSensorArray class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. //#include "Chicago.h"
  19. #include "SensorArray.h"
  20. #include "SensorLGS.h"
  21. #include "SensorSPRU.h"
  22. #include "SocketSPRU.h"
  23. //#include "SocketMMServer.h"
  24. //#include "SocketMMClient.h"
  25. #include "SocketSM.h"
  26. #include "SocketECS.h"
  27. #include "SocketBackup.h"
  28. #include "SocketMD.h"
  29. #include "SocketLGS.h"
  30. #include "SocketVM.h"
  31. //#include "SocketPTZ.h"
  32. #include "SocketPTZm.h"
  33. #include "DeviceLGSm.h"
  34. #include "DeviceLGSs.h"
  35. //#include "DevicePTZs.h"
  36. #include "DevicePTZm.h"
  37. #include "DeviceRabbit.h"
  38. #include "CameraPTZ.h"
  39. #include "..\..\LgLib\Version.h"
  40. #include "SensorDC.h"
  41. #include "SensorCLD.h"
  42. #include "DeviceCLD.h"
  43. #include "SocketRS232DI.h"
  44. #include "SocketMigvanPTZ.h"
  45. #include "DeviceMigvanPTZ.h"
  46. #include "DevicePCI1762.h"
  47. #include "DeviceCameraMic1300.h"
  48. #include "DeviceCameraHebron.h"
  49. #include "SocketCameraMic1300.h"
  50. #include "SocketCCC.h"
  51. #include "..\Chicago\DeviceCameraTKS576.h"
  52. #include "..\Chicago\SocketCameraTKS576.h"
  53. #include "..\DLIB\SocketCameraPhilipsG3AD.h"
  54. #include "..\DLIB\DeviceCameraPhilipsG3AD.h"
  55. #include "..\DLIB\SocketCameraAmericanDynamics.h"
  56. #include "..\DLIB\DeviceCameraAmericanDynamics.h"
  57. #include "SocketCameraPelco.h"
  58. #include "DeviceCameraPelco.h"
  59. #include "..\DLIB\SocketCameraVicon.h"
  60. #include "..\DLIB\DeviceCameraVicon.h"
  61. #include "..\..\LgLib\MFC\LgBitCodeFile.h"
  62. #include "ObjectFactory.h"
  63. #ifdef _DEBUG
  64. #undef THIS_FILE
  65. static char THIS_FILE[]=__FILE__;
  66. #define new DEBUG_NEW
  67. #endif
  68. //////////////////////////////////////////////////////////////////////
  69. // Construction/Destruction
  70. //////////////////////////////////////////////////////////////////////
  71. CSensorArray::CSensorArray()
  72. {
  73. memset( m_nLastDemoSampleTime, 0, sizeof(m_nLastDemoSampleTime) );
  74. m_bDebugMode = FALSE;
  75. m_nSensor = 0;
  76. m_ppSensor = NULL;
  77. m_hEventWnd = NULL;
  78. m_nZonesCount = 0;
  79. m_ppZones = NULL;
  80. m_nSocket = 0;
  81. m_ppSocket = NULL;
  82. m_nSensor = 0;
  83. m_ppSensor = NULL;
  84. m_nBitmapsCount = 0;
  85. m_pBitmaps = NULL;
  86. m_nGuardsCount = 0;
  87. m_pGuards = NULL;
  88. m_nSupersCount = 0;
  89. m_pSupers = NULL;
  90. m_pConditions = NULL;
  91. m_nConditionsCount = 0;
  92. m_pFilters = NULL;
  93. m_nFiltersCount = 0;
  94. m_pCommands = NULL;
  95. m_nCommandsCount = 0;
  96. // m_pPatrols = NULL;
  97. // m_nPatrolsCount = 0;
  98. m_ppVideoCamera = NULL;
  99. m_nVideoCamera = 0;
  100. m_ppVideoMatrix = NULL;
  101. m_nVideoMatrix = 0;
  102. m_ppDirectInput = NULL;
  103. m_nDirectInput = 0;
  104. m_ppDirectOutput = NULL;
  105. m_nDirectOutput = 0;
  106. m_ppDevice = NULL;
  107. m_nDevice = 0;
  108. m_ppVideoCaptureDevice = NULL;
  109. m_nVideoCaptureDevice = 0;
  110. m_nBG = 0;
  111. m_pBG = NULL;
  112. m_nIrisDayHour = 7;
  113. m_nIrisDayMinute = 0;
  114. m_nIrisNightHour = 19;
  115. m_nIrisNightMinute = 0;
  116. m_dIrisDayValue = 0.4;
  117. m_dIrisNightValue = 1.0;
  118. m_bIrisNeedSwitchDay = TRUE;
  119. m_bIrisNeedSwitchNight = TRUE;
  120. m_pSettings = NULL;
  121. m_bDemoMode = FALSE;
  122. LOGFONT lf =
  123. {
  124. -16, -8/2, 0, 0, FW_NORMAL, 0UL, 0UL, 0UL,
  125. OEM_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  126. DEFAULT_QUALITY, DEFAULT_PITCH, _T("Courier New")
  127. };
  128. m_ProgramSettings.LogFontReport = m_ProgramSettings.LogFontVideo = lf;
  129. m_ProgramSettings.ColorVideo = RGB(255,0,0);
  130. m_ProgramSettings.Capture.dZoomScale = 1.0;
  131. m_bBackgroundDirty = FALSE;
  132. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensorArray::CSensorArray") );
  133. }
  134. CSensorArray::~CSensorArray()
  135. {
  136. if( m_ppSocket )
  137. {
  138. for( int i = 0; i < m_nSocket; i++ )
  139. delete m_ppSocket[i];
  140. free( m_ppSocket );
  141. }
  142. if( m_ppSensor )
  143. {
  144. for( int i = 0; i < m_nSensor; i++ )
  145. delete m_ppSensor[i];
  146. free( m_ppSensor );
  147. m_nSensor = 0;
  148. m_ppSensor = NULL;
  149. }
  150. if( m_ppZones )
  151. {
  152. for( int i = 0; i < m_nZonesCount; i++ )
  153. delete m_ppZones[i];
  154. delete [] m_ppZones;
  155. }
  156. if( m_pBitmaps )
  157. {
  158. for( int i = 0; i < m_nBitmapsCount; i++ )
  159. ::DeleteObject( m_pBitmaps[i].Detach() );
  160. delete [] m_pBitmaps;
  161. }
  162. if( m_pGuards )
  163. {
  164. delete [] m_pGuards;
  165. }
  166. if( m_pSupers )
  167. {
  168. delete [] m_pSupers;
  169. }
  170. if( m_pConditions )
  171. {
  172. delete [] m_pConditions;
  173. }
  174. if( m_pFilters )
  175. {
  176. delete [] m_pFilters;
  177. }
  178. if( m_pCommands )
  179. {
  180. delete [] m_pCommands;
  181. }
  182. if( m_ppVideoCaptureDevice )
  183. {
  184. for( int i = 0; i < m_nVideoCaptureDevice; i++ )
  185. delete m_ppVideoCaptureDevice[i];
  186. free( m_ppVideoCaptureDevice );
  187. }
  188. if( m_ppVideoMatrix )
  189. {
  190. for( int i = 0; i < m_nVideoMatrix; i++ )
  191. delete m_ppVideoMatrix[i];
  192. delete [] m_ppVideoMatrix;
  193. }
  194. if( m_ppVideoCamera )
  195. {
  196. for( int i = 0; i < m_nVideoCamera; i++ )
  197. delete m_ppVideoCamera[i];
  198. free( m_ppVideoCamera );
  199. }
  200. if( m_ppDirectInput )
  201. {
  202. for( int i = 0; i < m_nDirectInput; i++ )
  203. delete m_ppDirectInput[i];
  204. free( m_ppDirectInput );
  205. }
  206. if( m_ppDirectOutput )
  207. {
  208. for( int i = 0; i < m_nDirectOutput; i++ )
  209. delete m_ppDirectOutput[i];
  210. free( m_ppDirectOutput );
  211. }
  212. if( m_ppDevice )
  213. {
  214. for( int i = 0; i < m_nDevice; i++ )
  215. delete m_ppDevice[i];
  216. free( m_ppDevice );
  217. }
  218. if( m_pBG )
  219. {
  220. delete [] m_pBG;
  221. }
  222. UpdateSettings();
  223. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensorArray::~CSensorArray") );
  224. }
  225. CSensor* CSensorArray::GetSensor( SDPOINT& p )
  226. {
  227. double dMin = DBL_MAX;
  228. INT nMin = -1;
  229. for( INT i = 0; i < m_nSensor; i++ )
  230. {
  231. SDPOINT sp = m_ppSensor[i]->GetPosition();
  232. double d = sqrt( pow( sp.x - p.x, 2 ) + pow( sp.y - p.y, 2 ) );
  233. if( d < dMin )
  234. {
  235. dMin = d;
  236. nMin = i;
  237. }
  238. }
  239. if( nMin != -1 )
  240. return m_ppSensor[nMin];
  241. return NULL;
  242. }
  243. CSensor* CSensorArray::GetSensor( CLgDRect& drect )
  244. {
  245. for( INT i = 0; i < m_nSensor; i++ )
  246. {
  247. SDPOINT sp = m_ppSensor[i]->GetPosition();
  248. if( sp.x >= drect.left && sp.x <= drect.right &&
  249. sp.y >= drect.top && sp.y <= drect.bottom )
  250. {
  251. return m_ppSensor[i];
  252. }
  253. }
  254. return NULL;
  255. }
  256. CZone* CSensorArray::GetZone(SDPOINT &p)
  257. {
  258. double dMin = DBL_MAX;
  259. INT nMin = -1;
  260. for( INT i = 0; i < m_nZonesCount; i++ )
  261. {
  262. SDPOINT sp = m_ppZones[i]->GetPosition();
  263. double d = sqrt( pow( sp.x - p.x, 2 ) + pow( sp.y - p.y, 2 ) );
  264. if( d < dMin )
  265. {
  266. dMin = d;
  267. nMin = i;
  268. }
  269. }
  270. if( nMin != -1 )
  271. return m_ppZones[nMin];
  272. return NULL;
  273. }
  274. /*
  275. void CSensorArray::Paint( CDC *pDC, CRect& viewRect, CSize& mapSize, SDPOINT& mapShift, double mapScale, BOOL bInverse, BOOL bBigSize )
  276. {
  277. for( INT i = 0; i < m_nSensor; i++ )
  278. m_ppSensor[i]->Paint( pDC, viewRect, mapSize, mapShift, mapScale, bInverse, bBigSize );
  279. for( INT z = 0; z < m_nZonesCount; z++ )
  280. m_ppZones[z]->Paint( pDC, viewRect, mapSize, mapShift, mapScale, bInverse, bBigSize );
  281. }
  282. */
  283. using namespace OFNS;
  284. static void GetSocketConnectionList( CSensorArray::CVoidList &list, OFNS::COFPin *pPin )
  285. {
  286. if( !pPin )
  287. return;
  288. CObjectFactory *pOF = pPin->GetOF();
  289. for( int i = 0; i < pPin->m_nDeviceCount; i++ )
  290. {
  291. COFDevice *pTempl = pOF->DeviceGet( pPin->m_pDevice[i].nIndex, pPin->m_pDevice[i].nType );
  292. switch( pPin->m_nPinType )
  293. {
  294. case PT_SOCKET_MD:
  295. case PT_SOCKET_PTZ:
  296. case PT_SOCKET_VM:
  297. case PT_SOCKET_LGS:
  298. case PT_SOCKET_MIC1300:
  299. case PT_SOCKET_TKS576:
  300. case PT_SOCKET_PG3AD:
  301. case PT_SOCKET_VICON:
  302. case PT_SOCKET_PELCO:
  303. case PT_SOCKET_AMERICAN_DYNAMIS:
  304. if( !list.Find( pTempl->m_pDevice ) )
  305. {
  306. list.AddTail( pTempl->m_pDevice );
  307. GetSocketConnectionList( list, pTempl->GetPin( pPin->m_pDevice[i].nPin ) );
  308. }
  309. break;
  310. }
  311. }
  312. }
  313. //#define STI_SETUP
  314. BOOL CSensorArray::SaveTransform( CSensor *pSensor )
  315. {
  316. try
  317. {
  318. using namespace OFNS;
  319. OFNS::CObjectFactory OF;
  320. CLgBitCodeFile ofFile( 9 );
  321. if( ofFile.Open( m_CurrentFileName, CFile::modeRead ) )
  322. {
  323. CArchive ofAr( &ofFile, CArchive::load );
  324. OF.Serialize( ofAr );
  325. }
  326. else return FALSE;
  327. ofFile.Close();
  328. COFDeviceLGS *pTempl = (COFDeviceLGS*)OF.DeviceGet( pSensor->m_nTemplateIndex, pSensor->m_nTemplateType );
  329. if( pTempl )
  330. {
  331. pTempl->m_Transform[0].m_dX = pSensor->GetTransform(0)->GetParameters()[0];
  332. pTempl->m_Transform[0].m_dY = pSensor->GetTransform(0)->GetParameters()[1];
  333. pTempl->m_Transform[0].m_dZ = pSensor->GetTransform(0)->GetParameters()[2];
  334. pTempl->m_Transform[0].m_dPsi = pSensor->GetTransform(0)->GetParameters()[3];
  335. pTempl->m_Transform[0].m_dTheta = pSensor->GetTransform(0)->GetParameters()[4];
  336. pTempl->m_Transform[0].m_dPhi = pSensor->GetTransform(0)->GetParameters()[5];
  337. pTempl->m_Transform[1].m_dX = pSensor->GetTransform(1)->GetParameters()[0];
  338. pTempl->m_Transform[1].m_dY = pSensor->GetTransform(1)->GetParameters()[1];
  339. pTempl->m_Transform[1].m_dZ = pSensor->GetTransform(1)->GetParameters()[2];
  340. pTempl->m_Transform[1].m_dPsi = pSensor->GetTransform(1)->GetParameters()[3];
  341. pTempl->m_Transform[1].m_dTheta = pSensor->GetTransform(1)->GetParameters()[4];
  342. pTempl->m_Transform[1].m_dPhi = pSensor->GetTransform(1)->GetParameters()[5];
  343. }
  344. if( ofFile.Open( m_CurrentFileName, CFile::modeWrite ) )
  345. {
  346. CArchive ofAr( &ofFile, CArchive::store );
  347. OF.Serialize( ofAr );
  348. }
  349. else return FALSE;
  350. ofFile.Close();
  351. }
  352. catch( CFileException *e )
  353. {
  354. e->ReportError();
  355. }
  356. catch( CArchiveException *e )
  357. {
  358. e->ReportError();
  359. }
  360. return TRUE;
  361. }
  362. BOOL CSensorArray::SaveCalibrationName( CSensor *pSensor )
  363. {
  364. try
  365. {
  366. using namespace OFNS;
  367. OFNS::CObjectFactory OF;
  368. CLgBitCodeFile ofFile( 9 );
  369. if( ofFile.Open( m_CurrentFileName, CFile::modeRead ) )
  370. {
  371. CArchive ofAr( &ofFile, CArchive::load );
  372. OF.Serialize( ofAr );
  373. }
  374. else return FALSE;
  375. ofFile.Close();
  376. COFDeviceLGS *pTempl = (COFDeviceLGS*)OF.DeviceGet( pSensor->m_nTemplateIndex, pSensor->m_nTemplateType );
  377. if( pTempl )
  378. pTempl->m_arrCalibrationName = pSensor->GetCalibrationNameArray();
  379. if( ofFile.Open( m_CurrentFileName, CFile::modeWrite ) )
  380. {
  381. CArchive ofAr( &ofFile, CArchive::store );
  382. OF.Serialize( ofAr );
  383. }
  384. else return FALSE;
  385. ofFile.Close();
  386. }
  387. catch( CFileException *e )
  388. {
  389. e->ReportError();
  390. }
  391. catch( CArchiveException *e )
  392. {
  393. e->ReportError();
  394. }
  395. return TRUE;
  396. }
  397. BOOL CSensorArray::Load( LPCTSTR pFileName, int nRunningMode, CSettings *pSettings, BOOL bDemo )
  398. {
  399. BOOL bResult = FALSE;
  400. m_CurrentFileName = pFileName;
  401. __try
  402. {
  403. bResult = Load_( pFileName, nRunningMode, pSettings, bDemo );
  404. }
  405. __except( EXCEPTION_EXECUTE_HANDLER )
  406. {
  407. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::Load"), _T("Exception 0x%08X"), _exception_code() );
  408. bResult = FALSE;
  409. }
  410. return bResult;
  411. }
  412. BOOL CSensorArray::Load_( LPCTSTR pFileName, int nRunningMode, CSettings *pSettings, BOOL bDemo )
  413. {
  414. m_bDemoMode = bDemo;
  415. m_pSettings = pSettings;
  416. if( m_pSettings )
  417. {
  418. m_pSettings->Load( _T("IRIS_DAY_HOUR"), &m_nIrisDayHour );
  419. m_pSettings->Load( _T("IRIS_DAY_MINUTE"), &m_nIrisDayMinute );
  420. m_pSettings->Load( _T("IRIS_DAY_VALUE"), &m_dIrisDayValue );
  421. m_pSettings->Load( _T("IRIS_NIGHT_HOUR"), &m_nIrisNightHour );
  422. m_pSettings->Load( _T("IRIS_NIGHT_MINUTE"), &m_nIrisNightMinute );
  423. m_pSettings->Load( _T("IRIS_NIGHT_VALUE"), &m_dIrisNightValue );
  424. m_pSettings->Load( _T("SETTINGS"), &m_ProgramSettings, sizeof(m_ProgramSettings) );
  425. }
  426. #ifndef STI_SETUP
  427. try
  428. {
  429. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Started") );
  430. using namespace OFNS;
  431. CLgBitCodeFile ofFile( pFileName, CFile::modeRead, 9 );
  432. CArchive ofAr( &ofFile, CArchive::load );
  433. {
  434. OFNS::CObjectFactory OF;
  435. OF.Serialize( ofAr );
  436. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("OF.Serialize passed") );
  437. // store settings
  438. m_SetupSettings = OF.GetSettings();
  439. // m_Background.Load = OF.FileGroupGetTemp( OF.m_FileNameBG );
  440. m_Background.Load( OF.m_FileNameBG, OF.FileGroupGet(), OF.GetMeterScale() );
  441. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("m_Background.Load passed") );
  442. m_nBG = OF.TemplateGetCount();
  443. if( m_nBG )
  444. {
  445. m_pBG = new CLgMemoryDC[ m_nBG ];
  446. for( int i = 0; i < m_nBG; i++ )
  447. {
  448. // HBITMAP hBmp = (HBITMAP)::LoadImage( NULL, OF.FileGroupGetTemp( OF.TemplateGet(i)->GetBG() ), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  449. HBITMAP hBmp = (HBITMAP)OF.FileGroupGet()->LoadImage( OF.TemplateGet(i)->GetBG(), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  450. m_pBG[ i ].Create( hBmp, FALSE );
  451. }
  452. }
  453. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Template loating passed") );
  454. // basic device creating
  455. for( int nType = OFNS::DT_FIRST; nType < OFNS::DT_COUNT; nType++ )
  456. {
  457. int nIndex;
  458. switch( OF.m_pDevice[ nType ].nType )
  459. {
  460. case OFNS::DT_MIGVAN_VM8X4:
  461. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  462. m_ppVideoMatrix = (CVideoMatrix**)realloc( m_ppVideoMatrix, sizeof(CVideoMatrix*) * ( m_nVideoMatrix + OF.m_pDevice[ nType ].nCount ) );
  463. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  464. {
  465. COFDeviceMigvanVM8x4* pTempl = static_cast<COFDeviceMigvanVM8x4*>( OF.m_pDevice[ nType ].ppDevice[ nIndex ] );
  466. // hardware imagination
  467. m_ppDevice[ m_nDevice + nIndex ] = new CDeviceVMs;
  468. CDeviceVMs *pDevice = static_cast<CDeviceVMs*>(m_ppDevice[ m_nDevice + nIndex ]);
  469. pDevice->SetAutoInit( pTempl->m_bAuto );
  470. pDevice->SetHardwareID( pTempl->m_pHardwareID );
  471. // logical imagination
  472. m_ppVideoMatrix[ m_nVideoMatrix + nIndex ] = new CVideoMatrix;
  473. m_ppVideoMatrix[ m_nVideoMatrix + nIndex ]->ConnectToDevice( pDevice );
  474. pTempl->m_pDevice = pDevice;
  475. pTempl->m_pVideoDevice[0] = m_ppVideoMatrix[ m_nVideoMatrix + nIndex ];
  476. }
  477. m_nDevice += OF.m_pDevice[ nType ].nCount;
  478. m_nVideoMatrix += OF.m_pDevice[ nType ].nCount;
  479. break;
  480. case OFNS::DT_RABBIT_CAMERA:
  481. m_ppVideoCamera = (CVideoCamera**)realloc( m_ppVideoCamera, sizeof(CVideoCamera*) * ( m_nVideoCamera + OF.m_pDevice[ nType ].nCount ) );
  482. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  483. {
  484. COFDeviceRabbitCamera* pTempl = static_cast<COFDeviceRabbitCamera*>( OF.m_pDevice[ nType ].ppDevice[ nIndex ] );
  485. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  486. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  487. pVideoCamera->SetName( &pTempl->GetName() );
  488. pVideoCamera->SetSensorArray( this );
  489. }
  490. m_nVideoCamera += OF.m_pDevice[ nType ].nCount;
  491. break;
  492. case OFNS::DT_CAMERA_LGS:
  493. m_ppVideoCamera = (CVideoCamera**)realloc( m_ppVideoCamera, sizeof(CVideoCamera*) * ( m_nVideoCamera + OF.m_pDevice[ nType ].nCount ) );
  494. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  495. {
  496. COFDeviceCameraLGS* pTempl = static_cast<COFDeviceCameraLGS*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  497. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  498. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  499. pVideoCamera->SetName( &pTempl->GetName() );
  500. pVideoCamera->SetSensorArray( this );
  501. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  502. }
  503. m_nVideoCamera += OF.m_pDevice[ nType ].nCount;
  504. break;
  505. case OFNS::DT_CAMERA:
  506. m_ppVideoCamera = (CVideoCamera**)realloc( m_ppVideoCamera, sizeof(CVideoCamera*) * ( m_nVideoCamera + OF.m_pDevice[ nType ].nCount ) );
  507. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  508. {
  509. COFDeviceCamera* pTempl = static_cast<COFDeviceCamera*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  510. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCamera;
  511. CVideoCamera *pVideoCamera = static_cast<CVideoCamera*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  512. pVideoCamera->SetName( &pTempl->GetName() );
  513. pVideoCamera->SetSensorArray( this );
  514. }
  515. m_nVideoCamera += OF.m_pDevice[ nType ].nCount;
  516. break;
  517. case OFNS::DT_RABBIT:
  518. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  519. m_ppVideoMatrix = (CVideoMatrix**)realloc( m_ppVideoMatrix, sizeof(CVideoMatrix*) * ( m_nVideoMatrix + OF.m_pDevice[ nType ].nCount * 2 ) );
  520. m_ppDirectInput = (CDirectInput**)realloc( m_ppDirectInput, sizeof(CDirectInput*) * ( m_nDirectInput + OF.m_pDevice[ nType ].nCount * CDeviceRabbit::DI_INPUT_COUNT ) );
  521. m_ppDirectOutput = (CDirectOutput**)realloc( m_ppDirectOutput, sizeof(CDirectOutput*) * ( m_nDirectOutput + OF.m_pDevice[ nType ].nCount * CDeviceRabbit::DO_OUTPUT_COUNT ) );
  522. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  523. {
  524. COFDeviceRabbit* pTempl = static_cast<COFDeviceRabbit*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  525. // hardware imagination
  526. m_ppDevice[ m_nDevice + nIndex ] = new CDeviceRabbit;
  527. CDeviceRabbit *pDevice = static_cast<CDeviceRabbit*>(m_ppDevice[ m_nDevice + nIndex ]);
  528. // pDevice->SetAddress( pTempl->m_nAddress );
  529. // logical imagination
  530. for( int k = 0; k < 2; k++ )
  531. {
  532. int n = m_nVideoMatrix + nIndex * 2 + k;
  533. m_ppVideoMatrix[ n ] = new CVideoMatrix;
  534. m_ppVideoMatrix[ n ]->ConnectToDevice( pDevice->GetDeviceVM(k) );
  535. pTempl->m_pVideoDevice[k] = m_ppVideoMatrix[ n ];
  536. }
  537. for( k = 0; k < CDeviceRabbit::DI_INPUT_COUNT; k++ )
  538. {
  539. int n = m_nDirectInput + nIndex * CDeviceRabbit::DI_INPUT_COUNT + k;
  540. // ???????? pDevice->SetNC( k, pTempl->GetPin()>m_pDryContact[k].bNC );
  541. m_ppDirectInput[ n ] = new CDirectInput;
  542. m_ppDirectInput[ n ]->ConnectToDevice( pDevice, k, 0 );
  543. pTempl->m_pDI[k] = m_ppDirectInput[ n ];
  544. }
  545. for( k = 0; k < CDeviceRabbit::DO_OUTPUT_COUNT; k++ )
  546. {
  547. int n = m_nDirectOutput + nIndex * CDeviceRabbit::DO_OUTPUT_COUNT + k;
  548. m_ppDirectOutput[ n ] = new CDirectOutput;
  549. m_ppDirectOutput[ n ]->ConnectToDevice( pDevice, k, 0 );
  550. pTempl->m_pDO[k] = m_ppDirectOutput[ n ];
  551. }
  552. pTempl->m_pDevice = pDevice;
  553. }
  554. m_nDevice += OF.m_pDevice[ nType ].nCount;
  555. m_nVideoMatrix += OF.m_pDevice[ nType ].nCount * 2;
  556. m_nDirectInput += OF.m_pDevice[ nType ].nCount * CDeviceRabbit::DI_INPUT_COUNT;
  557. m_nDirectOutput += OF.m_pDevice[ nType ].nCount * CDeviceRabbit::DO_OUTPUT_COUNT;
  558. break;
  559. case OFNS::DT_LGS:
  560. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  561. m_ppSensor = (CSensor**)realloc( m_ppSensor, sizeof(CSensor*) * ( m_nSensor + OF.m_pDevice[ nType ].nCount ) );
  562. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  563. {
  564. COFDeviceLGS* pTempl = static_cast<COFDeviceLGS*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  565. // CDevice *pDevice;
  566. CSensorLGS *pSensorLGS;
  567. CDeviceLGSm *pDeviceLGSm;
  568. CDeviceLGSs *pDeviceLGSs;
  569. int n = m_nSensor + nIndex;
  570. switch( pTempl->m_nSubType )
  571. {
  572. case COFDeviceLGS::ST_MULTI:
  573. pDeviceLGSm = new CDeviceLGSm;
  574. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = pDeviceLGSm;
  575. // pDevice = m_ppDevice[ m_nDevice + nIndex ];
  576. pDeviceLGSm->CLgNetDeviceLGS::SetAddress( pTempl->m_nAddress );
  577. m_ppSensor[n] = new CSensorLGS;
  578. pSensorLGS = static_cast<CSensorLGS*>(m_ppSensor[n]);
  579. pSensorLGS->ConnectToDevice( pDeviceLGSm );
  580. break;
  581. case COFDeviceLGS::ST_SINGLE:
  582. pDeviceLGSs = new CDeviceLGSs;
  583. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = pDeviceLGSs;
  584. m_ppSensor[n] = new CSensorLGS;
  585. pSensorLGS = static_cast<CSensorLGS*>(m_ppSensor[n]);
  586. pSensorLGS->ConnectToDevice( pDeviceLGSs );
  587. break;
  588. }
  589. pSensorLGS->SetDebugMode( m_bDebugMode );
  590. pSensorLGS->SetRange( pTempl->m_dRange );
  591. pSensorLGS->SetBorderLGS( pTempl->GetBorderLGS() );
  592. // pSensorLGS->SetHiddenZoneList( pTempl->GetHiddenZoneList() );
  593. pSensorLGS->SetCommonZero( pTempl->GetCommonZero() );
  594. pSensorLGS->SetPosition( SDPOINT( pTempl->m_Pos.x / OF.GetMapSize()->cx,
  595. pTempl->m_Pos.y / OF.GetMapSize()->cy) );
  596. pSensorLGS->Enable( TRUE );
  597. pSensorLGS->SetAddress( 0 );
  598. pSensorLGS->SetArrayIndex( n );
  599. pSensorLGS->SetSocket( 2 );
  600. pSensorLGS->SetZoneIndex( 0 ); // need to changed
  601. pSensorLGS->SetSensorArray( this );
  602. pSensorLGS->SetState( CSensor::UNKNOWN );
  603. pSensorLGS->SetName( pTempl->GetName() );
  604. pSensorLGS->SetPatrol( FALSE );
  605. // for update in calibration program
  606. pSensorLGS->m_nTemplateType = nType;
  607. pSensorLGS->m_nTemplateIndex = nIndex;
  608. CTransform *ppTransform[2];
  609. for( int i = 0; i < 2; i++ )
  610. {
  611. ppTransform[i] = new CTransform();
  612. ppTransform[i]->Prepare( pTempl->m_Transform[i].m_dX, pTempl->m_Transform[i].m_dY, pTempl->m_Transform[i].m_dZ,
  613. pTempl->m_Transform[i].m_dPsi, pTempl->m_Transform[i].m_dTheta, pTempl->m_Transform[i].m_dPhi );
  614. }
  615. pSensorLGS->SetTransform( pTempl->m_bRemoteCamera, pTempl->m_dPanShift, pTempl->m_dTiltTable, ppTransform[0], ppTransform[1] );
  616. pSensorLGS->SetAddressCCC( pTempl->m_nAddressCCC );
  617. pSensorLGS->SetImageCount( pTempl->m_nImageCount );
  618. pSensorLGS->GetCalibrationNameArray() = pTempl->m_arrCalibrationName;
  619. pTempl->m_pSensor = pSensorLGS;
  620. }
  621. m_nDevice += OF.m_pDevice[ nType ].nCount;
  622. m_nSensor += OF.m_pDevice[ nType ].nCount;
  623. break;
  624. case OFNS::DT_CLD:
  625. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  626. m_ppSensor = (CSensor**)realloc( m_ppSensor, sizeof(CSensor*) * ( m_nSensor + OF.m_pDevice[ nType ].nCount ) );
  627. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  628. {
  629. COFDeviceCLD* pTempl = static_cast<COFDeviceCLD*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  630. CDevice *pDevice;
  631. CSensorCLD *pSensorCLD;
  632. int n = m_nSensor + nIndex;
  633. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCLD;
  634. pDevice = m_ppDevice[ m_nDevice + nIndex ];
  635. static_cast<CDeviceCLD*>(pDevice)->CLgNetDeviceCLD::SetAddress( pTempl->m_nAddress );
  636. m_ppSensor[n] = new CSensorCLD;
  637. pSensorCLD = static_cast<CSensorCLD*>(m_ppSensor[n]);
  638. pSensorCLD->ConnectToDevice( static_cast<CDeviceCLD*>(pDevice) );
  639. // ((CDeviceCLD*)pDevice)->SetSensorCLD( pSensorCLD );
  640. // pSensorCLD->SetDebugMode( m_bDebugMode );
  641. pSensorCLD->SetRange( pTempl->m_dRange );
  642. pSensorCLD->SetCommonZero( pTempl->GetCommonZero() );
  643. pSensorCLD->SetPosition( SDPOINT( pTempl->m_Pos.x / OF.GetMapSize()->cx,
  644. pTempl->m_Pos.y / OF.GetMapSize()->cy) );
  645. pSensorCLD->Enable( TRUE );
  646. pSensorCLD->SetAddress( 0 );
  647. pSensorCLD->SetArrayIndex( n );
  648. pSensorCLD->SetSocket( 2 );
  649. pSensorCLD->SetZoneIndex( 0 ); // need to changed
  650. pSensorCLD->SetSensorArray( this );
  651. pSensorCLD->SetState( CSensor::UNKNOWN );
  652. pSensorCLD->SetName( pTempl->GetName() );
  653. pSensorCLD->SetPatrol( FALSE );
  654. pSensorCLD->SetImageCount( pTempl->m_nImageCount );
  655. pSensorCLD->SetAddressCCC( pTempl->m_nAddressCCC );
  656. pTempl->m_pSensor = pSensorCLD;
  657. }
  658. m_nDevice += OF.m_pDevice[ nType ].nCount;
  659. m_nSensor += OF.m_pDevice[ nType ].nCount;
  660. break;
  661. /* +++ +++ +++
  662. case OFNS::DT_MIGVAN_CAMERA:
  663. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  664. m_ppVideoCamera = (CVideoCamera**)realloc( m_ppVideoCamera, sizeof(CVideoCamera*) * ( m_nVideoCamera + OF.m_pDevice[ nType ].nCount ) );
  665. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  666. {
  667. COFDeviceMigvanCameraPTZ* pTempl = (COFDeviceMigvanCameraPTZ*)OF.m_pDevice[ nType ].ppDevice[ nIndex ];
  668. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceMigvanPTZ;
  669. CDeviceMigvanPTZ *pDevice = (CDeviceMigvanPTZ*)m_ppDevice[ m_nDevice + nIndex ];
  670. pDevice->SetAutoInit( pTempl->m_bAuto );
  671. pDevice->SetHardwareID( pTempl->m_pHardwareID );
  672. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  673. CVideoCameraPTZ *pVideoCamera = (CVideoCameraPTZ*)m_ppVideoCamera[ m_nVideoCamera + nIndex ];
  674. pVideoCamera->SetSensorArray( this );
  675. pVideoCamera->ConnectToDevice( pDevice );
  676. pVideoCamera->SetName( &pTempl->GetName() );
  677. }
  678. m_nDevice += OF.m_pDevice[ nType ].nCount;
  679. m_nVideoCamera += OF.m_pDevice[ nType ].nCount;
  680. break;
  681. */
  682. case OFNS::DT_CAMERA_PTZ:
  683. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  684. m_ppVideoCamera = (CVideoCamera**)realloc( m_ppVideoCamera, sizeof(CVideoCamera*) * ( m_nVideoCamera + OF.m_pDevice[ nType ].nCount ) );
  685. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  686. {
  687. COFDeviceCameraPTZ* pTempl = static_cast<COFDeviceCameraPTZ*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  688. switch( pTempl->GetSubType() )
  689. {
  690. case COFDeviceCameraPTZ::PTZST_MIGVAN_878:
  691. case COFDeviceCameraPTZ::PTZST_MIGVAN_KD6Z:
  692. {
  693. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceMigvanPTZ;
  694. CDeviceMigvanPTZ *pDevice = static_cast<CDeviceMigvanPTZ*>(m_ppDevice[ m_nDevice + nIndex ]);
  695. pDevice->SetAutoInit( pTempl->m_uData.migvan.bAuto );
  696. pDevice->SetHardwareID( pTempl->m_uData.migvan.pHardwareID );
  697. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  698. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  699. pVideoCamera->SetSensorArray( this );
  700. pVideoCamera->ConnectToDevice( pDevice );
  701. pVideoCamera->SetName( &pTempl->GetName() );
  702. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  703. if( bDemo )
  704. pVideoCamera->PostReady();
  705. }
  706. break;
  707. case COFDeviceCameraPTZ::PTZST_MIC_1_300:
  708. {
  709. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraMic1300;
  710. CDeviceCameraMic1300 *pDevice = static_cast<CDeviceCameraMic1300*>(m_ppDevice[ m_nDevice + nIndex ]);
  711. pDevice->SetAddress( pTempl->m_uData.mic1300.bAddress );
  712. // pDevice->SetAutoInit( pTempl->m_uData.migvan.bAuto );
  713. // pDevice->SetHardwareID( pTempl->m_uData.migvan.pHardwareID );
  714. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  715. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  716. pVideoCamera->SetSensorArray( this );
  717. pVideoCamera->ConnectToDevice( pDevice );
  718. pVideoCamera->SetName( &pTempl->GetName() );
  719. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  720. if( bDemo )
  721. pVideoCamera->PostReady();
  722. }
  723. break;
  724. case COFDeviceCameraPTZ::PTZST_TK_S576:
  725. {
  726. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraTKS576;
  727. CDeviceCameraTKS576 *pDevice = static_cast<CDeviceCameraTKS576*>(m_ppDevice[ m_nDevice + nIndex ]);
  728. pDevice->SetAddress( pTempl->m_uData.tks576.bAddress );
  729. // pDevice->SetAutoInit( pTempl->m_uData.migvan.bAuto );
  730. // pDevice->SetHardwareID( pTempl->m_uData.migvan.pHardwareID );
  731. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  732. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  733. pVideoCamera->SetSensorArray( this );
  734. pVideoCamera->ConnectToDevice( pDevice );
  735. pVideoCamera->SetName( &pTempl->GetName() );
  736. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  737. if( bDemo )
  738. pVideoCamera->PostReady();
  739. }
  740. break;
  741. case COFDeviceCameraPTZ::PTZST_PG3AD_NEW:
  742. case COFDeviceCameraPTZ::PTZST_PG3AD_OLD:
  743. {
  744. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraPhilipsG3AD;
  745. CDeviceCameraPhilipsG3AD *pDevice = static_cast<CDeviceCameraPhilipsG3AD*>(m_ppDevice[ m_nDevice + nIndex ]);
  746. pDevice->SetAddress( pTempl->m_uData.pg3ad.bAddress );
  747. if( pTempl->GetSubType() == COFDeviceCameraPTZ::PTZST_PG3AD_OLD )
  748. pDevice->SetOldType();
  749. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  750. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  751. pVideoCamera->SetSensorArray( this );
  752. pVideoCamera->ConnectToDevice( pDevice );
  753. pVideoCamera->SetName( &pTempl->GetName() );
  754. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  755. if( bDemo )
  756. pVideoCamera->PostReady();
  757. }
  758. break;
  759. case COFDeviceCameraPTZ::PTZST_AMERICAN_DYNAMICS:
  760. {
  761. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraAmericanDynamics;
  762. CDeviceCameraAmericanDynamics *pDevice = static_cast<CDeviceCameraAmericanDynamics*>(m_ppDevice[ m_nDevice + nIndex ]);
  763. pDevice->SetAddress( pTempl->m_uData.american_dynamics.bAddress );
  764. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  765. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  766. pVideoCamera->SetSensorArray( this );
  767. pVideoCamera->ConnectToDevice( pDevice );
  768. pVideoCamera->SetName( &pTempl->GetName() );
  769. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  770. if( bDemo )
  771. pVideoCamera->PostReady();
  772. }
  773. break;
  774. case COFDeviceCameraPTZ::PTZST_PELCO:
  775. {
  776. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraPelco;
  777. CDeviceCameraPelco *pDevice = static_cast<CDeviceCameraPelco*>(m_ppDevice[ m_nDevice + nIndex ]);
  778. pDevice->SetAddress( pTempl->m_uData.pelco.bAddress );
  779. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  780. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  781. pVideoCamera->SetSensorArray( this );
  782. pVideoCamera->ConnectToDevice( pDevice );
  783. pVideoCamera->SetName( &pTempl->GetName() );
  784. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  785. if( bDemo )
  786. pVideoCamera->PostReady();
  787. }
  788. break;
  789. case COFDeviceCameraPTZ::PTZST_VICON:
  790. {
  791. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraVicon;
  792. CDeviceCameraVicon *pDevice = static_cast<CDeviceCameraVicon*>(m_ppDevice[ m_nDevice + nIndex ]);
  793. pDevice->SetAddress( pTempl->m_uData.vicon.bAddress );
  794. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  795. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  796. pVideoCamera->SetSensorArray( this );
  797. pVideoCamera->ConnectToDevice( pDevice );
  798. pVideoCamera->SetName( &pTempl->GetName() );
  799. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  800. if( bDemo )
  801. pVideoCamera->PostReady();
  802. }
  803. break;
  804. case COFDeviceCameraPTZ::PTZST_HEBRON:
  805. {
  806. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraHebron;
  807. CDeviceCameraHebron *pDevice = static_cast<CDeviceCameraHebron*>(m_ppDevice[ m_nDevice + nIndex ]);
  808. pDevice->SetAddress( pTempl->m_uData.hebron.bAddress );
  809. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  810. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  811. pVideoCamera->SetSensorArray( this );
  812. pVideoCamera->ConnectToDevice( pDevice );
  813. pVideoCamera->SetName( &pTempl->GetName() );
  814. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  815. if( bDemo )
  816. pVideoCamera->PostReady();
  817. }
  818. break;
  819. case COFDeviceCameraPTZ::PTZST_3_TRACK:
  820. {
  821. pTempl->m_pDevice = m_ppDevice[ m_nDevice + nIndex ] = new CDeviceCameraHebron;
  822. CDeviceCameraHebron *pDevice = static_cast<CDeviceCameraHebron*>(m_ppDevice[ m_nDevice + nIndex ]);
  823. pDevice->SetAddress( pTempl->m_uData.tri_track.bAddress );
  824. pTempl->m_pVideoDevice[0] = m_ppVideoCamera[ m_nVideoCamera + nIndex ] = new CVideoCameraPTZ;
  825. CVideoCameraPTZ *pVideoCamera = static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[ m_nVideoCamera + nIndex ]);
  826. pVideoCamera->SetSensorArray( this );
  827. pVideoCamera->ConnectToDevice( pDevice );
  828. pVideoCamera->SetName( &pTempl->GetName() );
  829. pVideoCamera->SetRangeZoom( pTempl->m_dZoomTable );
  830. pVideoCamera->SetDoplerParams( pTempl->m_uData.tri_track.nAngle, pTempl->m_uData.tri_track.dwTimeout );
  831. if( bDemo )
  832. pVideoCamera->PostReady();
  833. }
  834. break;
  835. }
  836. }
  837. m_nDevice += OF.m_pDevice[ nType ].nCount;
  838. m_nVideoCamera += OF.m_pDevice[ nType ].nCount;
  839. break;
  840. case OFNS::DT_SOCKET:
  841. m_ppSocket = (CSocket**)realloc( m_ppSocket, sizeof(CSocket*) * ( m_nSocket + OF.m_pDevice[ nType ].nCount ) );
  842. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  843. {
  844. COFDeviceSocket* pTempl = static_cast<COFDeviceSocket*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  845. CSocketMD *pSocketMD;
  846. CSocketMigvanPTZ *pSocketPTZ;
  847. CSocketCameraMic1300 *pSocketMic1300;
  848. CSocketCameraTKS576 *pSocketTKS576;
  849. CSocketCameraPhilipsG3AD *pSocketPG3AD;
  850. CSocketCameraAmericanDynamics *pAmericanDynamics;
  851. CSocketCameraPelco *pSocketPelco;
  852. CSocketCameraVicon *pSocketVicon;
  853. CSocketVM *pSocketVM;
  854. CSocketLGS *pSocketLGS;
  855. CSocketCCC *pSocketCCC;
  856. CSocketRS232DI *pSocketDI;
  857. // int k;
  858. pTempl->m_pDevice = NULL;
  859. switch( pTempl->m_nSubType )
  860. {
  861. case COFDeviceSocket::ST_MD:
  862. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketMD;
  863. pSocketMD = static_cast<CSocketMD*>(m_ppSocket[ m_nSocket + nIndex ]);
  864. pSocketMD->Create( this, pTempl->m_Port, atoi( pTempl->m_BaudRate ), pTempl->m_bSpyMode );
  865. pSocketMD->SetName( pTempl->m_Port + CString( _T("(MultiDrop)") ) );
  866. break;
  867. case COFDeviceSocket::ST_PTZ:
  868. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketMigvanPTZ;
  869. pSocketPTZ = static_cast<CSocketMigvanPTZ*>(m_ppSocket[ m_nSocket + nIndex ]);
  870. pSocketPTZ->Create( this, pTempl->m_Port );
  871. pSocketPTZ->SetName( pTempl->m_Port + CString( _T("(Migvan PTZ)") ) );
  872. break;
  873. case COFDeviceSocket::ST_MIC1300:
  874. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraMic1300;
  875. pSocketMic1300 = static_cast<CSocketCameraMic1300*>(m_ppSocket[ m_nSocket + nIndex ]);
  876. pSocketMic1300->Create( this, pTempl->m_Port );
  877. pSocketMic1300->SetName( pTempl->m_Port + CString( _T("(MIC1-300 PTZ)") ) );
  878. break;
  879. case COFDeviceSocket::ST_TKS576:
  880. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraTKS576;
  881. pSocketTKS576 = static_cast<CSocketCameraTKS576*>(m_ppSocket[ m_nSocket + nIndex ]);
  882. pSocketTKS576->Create( this, pTempl->m_Port );
  883. pSocketTKS576->SetName( pTempl->m_Port + CString( _T("(JVC TK-S576 PTZ)") ) );
  884. break;
  885. case COFDeviceSocket::ST_PG3AD:
  886. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraPhilipsG3AD;
  887. pSocketPG3AD = static_cast<CSocketCameraPhilipsG3AD*>(m_ppSocket[ m_nSocket + nIndex ]);
  888. pSocketPG3AD->Create( this, pTempl->m_Port );
  889. pSocketPG3AD->SetName( pTempl->m_Port + CString( _T("(Philips G3 AutoDome PTZ)") ) );
  890. break;
  891. case COFDeviceSocket::ST_AMERICAN_DYNAMICS:
  892. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraAmericanDynamics;
  893. pAmericanDynamics = static_cast<CSocketCameraAmericanDynamics*>(m_ppSocket[ m_nSocket + nIndex ]);
  894. pAmericanDynamics->Create( this, pTempl->m_Port );
  895. pAmericanDynamics->SetName( pTempl->m_Port + CString( _T("(American Dynamics PTZ)") ) );
  896. break;
  897. case COFDeviceSocket::ST_PELCO:
  898. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraPelco;
  899. pSocketPelco = static_cast<CSocketCameraPelco*>(m_ppSocket[ m_nSocket + nIndex ]);
  900. pSocketPelco->Create( this, pTempl->m_Port );
  901. pSocketPelco->SetName( pTempl->m_Port + CString( _T("(Pelco PTZ)") ) );
  902. break;
  903. case COFDeviceSocket::ST_VICON:
  904. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCameraVicon;
  905. pSocketVicon = static_cast<CSocketCameraVicon*>(m_ppSocket[ m_nSocket + nIndex ]);
  906. pSocketVicon->Create( this, pTempl->m_Port );
  907. pSocketVicon->SetName( pTempl->m_Port + CString( _T("(Vicon S2000 PTZ)") ) );
  908. break;
  909. case COFDeviceSocket::ST_LGS:
  910. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketLGS;
  911. pSocketLGS = static_cast<CSocketLGS*>(m_ppSocket[ m_nSocket + nIndex ]);
  912. pSocketLGS->Create( this, pTempl->m_Port );
  913. pSocketLGS->SetName( pTempl->m_Port + CString( _T("(Single LGS)") ) );
  914. break;
  915. case COFDeviceSocket::ST_VM:
  916. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketVM;
  917. pSocketVM = static_cast<CSocketVM*>(m_ppSocket[ m_nSocket + nIndex ]);
  918. pSocketVM->Create( this, pTempl->m_Port );
  919. pSocketVM->SetName( pTempl->m_Port + CString( _T("(Migvan VM)") ) );
  920. break;
  921. case COFDeviceSocket::ST_CCC:
  922. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketCCC;
  923. pSocketCCC = static_cast<CSocketCCC*>(m_ppSocket[ m_nSocket + nIndex ]);
  924. pSocketCCC->Create( this, pTempl->m_Port );
  925. pSocketCCC->SetName( pTempl->m_Port + CString( _T("(CCC)") ) );
  926. break;
  927. case COFDeviceSocket::ST_DI:
  928. pTempl->m_pSocket = m_ppSocket[ m_nSocket + nIndex ] = new CSocketRS232DI;
  929. pSocketDI = static_cast<CSocketRS232DI*>(m_ppSocket[ m_nSocket + nIndex ]);
  930. pSocketDI->Create( this, pTempl->m_Port, pTempl->m_bSelfTest, pTempl->m_nSelfTest );
  931. pSocketDI->SetName( pTempl->m_Port + CString( _T("(RS232 D/C)") ) );
  932. pTempl->m_pDevice = (CDevice*)pSocketDI;
  933. break;
  934. }
  935. }
  936. m_nSocket += OF.m_pDevice[ nType ].nCount;
  937. break;
  938. case OFNS::DT_PCI_1762:
  939. m_ppDevice = (CDevice**)realloc( m_ppDevice, sizeof(CDevice*) * ( m_nDevice + OF.m_pDevice[ nType ].nCount ) );
  940. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  941. {
  942. COFDevicePCI1762* pTempl = static_cast<COFDevicePCI1762*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  943. // hardware imagination
  944. m_ppDevice[ m_nDevice + nIndex ] = new CDevicePCI1762;
  945. CDevicePCI1762 *pDevice = static_cast<CDevicePCI1762*>(m_ppDevice[ m_nDevice + nIndex ]);
  946. pDevice->Create( 0 );
  947. pTempl->m_pDevice = pDevice;
  948. }
  949. m_nDevice += OF.m_pDevice[ nType ].nCount;
  950. break;
  951. case OFNS::DT_VIDEO_IN:
  952. m_ppVideoCaptureDevice = (CVideoCaptureDevice**)realloc( m_ppVideoCaptureDevice, sizeof(CVideoCaptureDevice*) * ( m_nVideoCaptureDevice + OF.m_pDevice[ nType ].nCount ) );
  953. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  954. {
  955. COFDeviceVideoIn* pTempl = static_cast<COFDeviceVideoIn*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  956. pTempl->m_pVideoDevice[0] = m_ppVideoCaptureDevice[ m_nVideoCaptureDevice + nIndex ] = new CVideoCaptureDevice;
  957. CVideoCaptureDevice *pVideoCaptureDevice = m_ppVideoCaptureDevice[ m_nVideoCaptureDevice + nIndex ];
  958. pVideoCaptureDevice->SetIOCount( 4, 0 );
  959. pVideoCaptureDevice->SetVideoDeviceID( pTempl->m_nSubType );
  960. pVideoCaptureDevice->SetVideoStandard( pTempl->m_nStandard );
  961. }
  962. m_nVideoCaptureDevice += OF.m_pDevice[ nType ].nCount;
  963. break;
  964. case OFNS::DT_DRY_CONTACTS:
  965. m_ppSensor = (CSensor**)realloc( m_ppSensor, sizeof(CSensor*) * ( m_nSensor + OF.m_pDevice[ nType ].nCount ) );
  966. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  967. {
  968. COFDeviceDryContacts * pTempl = static_cast<COFDeviceDryContacts*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  969. CSensorDC *pSensorDC;
  970. m_ppSensor[ m_nSensor + nIndex ] = pSensorDC = new CSensorDC;
  971. pSensorDC->SetPosition( SDPOINT( pTempl->m_Pos.x / OF.GetMapSize()->cx,
  972. pTempl->m_Pos.y / OF.GetMapSize()->cy) );
  973. pSensorDC->Enable( TRUE );
  974. pSensorDC->SetArrayIndex( m_nSensor + nIndex );
  975. pSensorDC->SetSocket( 2 );
  976. pSensorDC->SetZoneIndex( 0 ); // need to changed
  977. pSensorDC->SetSensorArray( this );
  978. pSensorDC->SetState( CSensor::UNKNOWN );
  979. pSensorDC->SetName( pTempl->GetName() );
  980. pSensorDC->SetPatrol( FALSE );
  981. pSensorDC->SetPTZ( pTempl->m_Pan, pTempl->m_Tilt, pTempl->m_Zoom / 100.0 );
  982. // for background
  983. COFTemplateDC *pTDC = OF.TemplateGet( pTempl->m_nTemplate );
  984. pSensorDC->SetBG( &m_pBG[ pTempl->m_nTemplate ] );
  985. for( int i = 0; i < pTDC->BitGetCount(); i++ )
  986. pSensorDC->AddBitPos( pTDC->BitGet( i )->GetPos() );
  987. // for update in calibration program
  988. pSensorDC->m_nTemplateType = nType;
  989. pSensorDC->m_nTemplateIndex = nIndex;
  990. CTransform *ppTransform[2];
  991. for( i = 0; i < 2; i++ )
  992. {
  993. ppTransform[i] = new CTransform();
  994. ppTransform[i]->Prepare( pTempl->m_Transform[i].m_dX, pTempl->m_Transform[i].m_dY, pTempl->m_Transform[i].m_dZ,
  995. pTempl->m_Transform[i].m_dPsi, pTempl->m_Transform[i].m_dTheta, pTempl->m_Transform[i].m_dPhi );
  996. }
  997. pSensorDC->SetTransform( pTempl->m_bRemoteCamera, pTempl->m_dPanShift, pTempl->m_dTiltTable, ppTransform[0], ppTransform[1] );
  998. pSensorDC->SetAddressCCC( pTempl->m_nAddressCCC );
  999. pSensorDC->SetImageCount( pTempl->m_nImageCount );
  1000. // small trick
  1001. pTempl->m_pSensor = pSensorDC;
  1002. }
  1003. m_nSensor += OF.m_pDevice[ nType ].nCount;
  1004. break;
  1005. }
  1006. }
  1007. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Device loading passed") );
  1008. // logical connections layer creating
  1009. for( nType = OFNS::DT_FIRST; nType < OFNS::DT_COUNT; nType++ )
  1010. {
  1011. int nIndex;
  1012. switch( OF.m_pDevice[ nType ].nType )
  1013. {
  1014. case OFNS::DT_SOCKET: // perform sockets connection
  1015. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  1016. {
  1017. COFDeviceSocket* pTempl = static_cast<COFDeviceSocket*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  1018. CSocketMD *pSocketMD;
  1019. CSocketMigvanPTZ *pSocketPTZ;
  1020. CSocketCameraMic1300 *pSocketMic1300;
  1021. CSocketCameraTKS576 *pSocketTKS576;
  1022. CSocketCameraPhilipsG3AD *pSocketPG3AD;
  1023. CSocketCameraAmericanDynamics *pSocketAmericanDynamics;
  1024. CSocketCameraPelco *pSocketPelco;
  1025. CSocketCameraVicon *pSocketVicon;
  1026. CSocketVM *pSocketVM;
  1027. CSocketLGS *pSocketLGS;
  1028. CVoidList list;
  1029. GetSocketConnectionList( list, pTempl->GetPin(0) );
  1030. POSITION pos = list.GetHeadPosition();
  1031. switch( pTempl->m_nSubType )
  1032. {
  1033. case COFDeviceSocket::ST_MD:
  1034. pSocketMD = static_cast<CSocketMD*>(pTempl->m_pSocket);
  1035. while( pos )
  1036. {
  1037. CDevice *pDevice = static_cast<CDevice*>(list.GetNext( pos ));
  1038. if( pDevice )
  1039. {
  1040. pDevice->SetSocket( pSocketMD );
  1041. switch( pDevice->GetDeviceType() )
  1042. {
  1043. case OFNS::DT_LGS: pSocketMD->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( static_cast<CDeviceLGSm*>(pDevice) ); break;
  1044. case OFNS::DT_CLD: pSocketMD->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( static_cast<CDeviceCLD*>(pDevice) ); break;
  1045. case OFNS::DT_CAMERA_PTZ: pSocketMD->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( static_cast<CDeviceCameraHebron*>(pDevice) ); break;
  1046. }
  1047. }
  1048. }
  1049. break;
  1050. case COFDeviceSocket::ST_PTZ:
  1051. pSocketPTZ = static_cast<CSocketMigvanPTZ*>(pTempl->m_pSocket);
  1052. while( pos )
  1053. {
  1054. CDeviceMigvanPTZ *pDevice = static_cast<CDeviceMigvanPTZ*>(list.GetNext( pos ));
  1055. if( pDevice )
  1056. {
  1057. pDevice->SetSocket( pSocketPTZ );
  1058. pSocketPTZ->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1059. pDevice->InitDevice();
  1060. }
  1061. }
  1062. break;
  1063. case COFDeviceSocket::ST_MIC1300:
  1064. pSocketMic1300 = static_cast<CSocketCameraMic1300*>(pTempl->m_pSocket);
  1065. while( pos )
  1066. {
  1067. CDeviceCameraMic1300 *pDevice = static_cast<CDeviceCameraMic1300*>(list.GetNext( pos ));
  1068. if( pDevice )
  1069. {
  1070. pDevice->SetSocket( pSocketMic1300 );
  1071. pSocketMic1300->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1072. // pDevice->InitDevice();
  1073. }
  1074. }
  1075. break;
  1076. case COFDeviceSocket::ST_TKS576:
  1077. pSocketTKS576 = static_cast<CSocketCameraTKS576*>(pTempl->m_pSocket);
  1078. while( pos )
  1079. {
  1080. CDeviceCameraTKS576 *pDevice = static_cast<CDeviceCameraTKS576*>(list.GetNext( pos ));
  1081. if( pDevice )
  1082. {
  1083. pDevice->SetSocket( pSocketTKS576 );
  1084. pSocketTKS576->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1085. // pDevice->InitDevice();
  1086. }
  1087. }
  1088. break;
  1089. case COFDeviceSocket::ST_PG3AD:
  1090. pSocketPG3AD = (CSocketCameraPhilipsG3AD*)pTempl->m_pSocket;
  1091. while( pos )
  1092. {
  1093. CDeviceCameraPhilipsG3AD *pDevice = static_cast<CDeviceCameraPhilipsG3AD*>(list.GetNext( pos ));
  1094. if( pDevice )
  1095. {
  1096. pDevice->SetSocket( pSocketPG3AD );
  1097. pSocketPG3AD->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1098. // pDevice->InitDevice();
  1099. }
  1100. }
  1101. break;
  1102. case COFDeviceSocket::ST_AMERICAN_DYNAMICS:
  1103. pSocketAmericanDynamics = (CSocketCameraAmericanDynamics*)pTempl->m_pSocket;
  1104. while( pos )
  1105. {
  1106. CDeviceCameraAmericanDynamics *pDevice = static_cast<CDeviceCameraAmericanDynamics*>(list.GetNext( pos ));
  1107. if( pDevice )
  1108. {
  1109. pDevice->SetSocket( pSocketAmericanDynamics );
  1110. pSocketAmericanDynamics->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1111. // pDevice->InitDevice();
  1112. }
  1113. }
  1114. break;
  1115. case COFDeviceSocket::ST_PELCO:
  1116. pSocketPelco = (CSocketCameraPelco*)pTempl->m_pSocket;
  1117. while( pos )
  1118. {
  1119. CDeviceCameraPelco *pDevice = static_cast<CDeviceCameraPelco*>(list.GetNext( pos ));
  1120. if( pDevice )
  1121. {
  1122. pDevice->SetSocket( pSocketPelco );
  1123. pSocketPelco->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1124. // pDevice->InitDevice();
  1125. }
  1126. }
  1127. break;
  1128. case COFDeviceSocket::ST_VICON:
  1129. pSocketVicon = (CSocketCameraVicon*)pTempl->m_pSocket;
  1130. while( pos )
  1131. {
  1132. CDeviceCameraVicon *pDevice = static_cast<CDeviceCameraVicon*>(list.GetNext( pos ));
  1133. if( pDevice )
  1134. {
  1135. pDevice->SetSocket( pSocketVicon );
  1136. pSocketVicon->CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( pDevice );
  1137. // pDevice->InitDevice();
  1138. }
  1139. }
  1140. break;
  1141. case COFDeviceSocket::ST_LGS:
  1142. pSocketLGS = (CSocketLGS*)pTempl->m_pSocket;
  1143. while( pos )
  1144. {
  1145. CDeviceLGSs *pDevice = static_cast<CDeviceLGSs*>(list.GetNext( pos ));
  1146. if( pDevice )
  1147. pSocketLGS->DeviceAttach( pDevice );
  1148. }
  1149. break;
  1150. case COFDeviceSocket::ST_VM:
  1151. pSocketVM = static_cast<CSocketVM*>(pTempl->m_pSocket);
  1152. while( pos )
  1153. {
  1154. CDeviceVMs *pDevice = static_cast<CDeviceVMs*>(list.GetNext( pos ));
  1155. if( pDevice )
  1156. pSocketVM->DeviceAttach( pDevice );
  1157. }
  1158. break;
  1159. case COFDeviceSocket::ST_DI:
  1160. break;
  1161. }
  1162. }
  1163. break;
  1164. }
  1165. for( nIndex = 0; nIndex < OF.m_pDevice[ nType ].nCount; nIndex++ )
  1166. {
  1167. COFDevice* pTempl1 = static_cast<COFDevice*>(OF.m_pDevice[ nType ].ppDevice[ nIndex ]);
  1168. for( int nPin1 = 0; nPin1 < pTempl1->GetPinCount(); nPin1++ )
  1169. {
  1170. COFPin *pPin1 = pTempl1->GetPin(nPin1);
  1171. for( int nPin2 = 0; nPin2 < pPin1->m_nDeviceCount; nPin2++ )
  1172. {
  1173. COFDevice* pTempl2 = static_cast<COFDevice*>(OF.DeviceGet( pPin1->m_pDevice[ nPin2 ].nIndex, pPin1->m_pDevice[ nPin2 ].nType ));
  1174. COFPin *pPin2 = pTempl2->GetPin( pPin1->m_pDevice[ nPin2 ].nPin );
  1175. switch( pPin1->GetType() )
  1176. {
  1177. case PT_VIDEO_IN:
  1178. {
  1179. CVideoPin *pP1, *pP2;
  1180. if( pTempl1->GetType() == DT_RABBIT )
  1181. {
  1182. if( pPin1->m_nSubIndex > 1 ) pP1 = pTempl1->m_pVideoDevice[0]->GetInput( pPin1->m_nSubIndex-2 );
  1183. else pP1 = pTempl1->m_pVideoDevice[1]->GetInput( pPin1->m_nSubIndex );
  1184. }
  1185. else pP1 = pTempl1->m_pVideoDevice[0]->GetInput( pPin1->m_nSubIndex );
  1186. if( pTempl2->GetType() == DT_RABBIT )
  1187. {
  1188. if( pPin2->m_nSubIndex > 0 ) pP1 = pTempl2->m_pVideoDevice[0]->GetOutput( pPin2->m_nSubIndex-1 );
  1189. else pP2 = pTempl2->m_pVideoDevice[1]->GetOutput( pPin2->m_nSubIndex );
  1190. }
  1191. else pP2 = pTempl2->m_pVideoDevice[0]->GetOutput( pPin2->m_nSubIndex );
  1192. // connect video pins
  1193. pP2->Connect( pP1 );
  1194. }
  1195. break;
  1196. case PT_VIDEO_OUT: // actualy already connected in previous CASE block
  1197. break;
  1198. case PT_RABBIT_CAMERA:
  1199. {
  1200. CDeviceRabbit *pDevice = static_cast<CDeviceRabbit*>(pTempl1->m_pDevice);
  1201. CVideoCameraPTZ *pCamera = static_cast<CVideoCameraPTZ*>(pTempl2->m_pVideoDevice[0]);
  1202. pCamera->ConnectToDevice( pDevice );
  1203. }
  1204. break;
  1205. case PT_CAMERA_LGS:
  1206. {
  1207. CDeviceLGSm *pDevice = static_cast<CDeviceLGSm*>(pTempl2->m_pDevice);
  1208. CVideoCameraPTZ *pCamera = static_cast<CVideoCameraPTZ*>(pTempl1->m_pVideoDevice[0]);
  1209. pCamera->ConnectToDevice( pDevice );
  1210. }
  1211. break;
  1212. case PT_CAMERA_RABBIT: // actualy already connected in previous block
  1213. break;
  1214. case PT_SENSOR_CAMERA:
  1215. if( !pPin1->IsFree() )
  1216. {
  1217. pTempl1->m_pSensor->SetVideoCamera( static_cast<CVideoCamera*>(pTempl2->m_pVideoDevice[0]) );
  1218. if( static_cast<CVideoCamera*>(pTempl2->m_pVideoDevice[0])->GetType() == VC_PTZ )
  1219. static_cast<CVideoCameraPTZ*>(pTempl2->m_pVideoDevice[0])->SetSensor( pTempl1->m_pSensor );
  1220. }
  1221. break;
  1222. case PT_CAMERA_SENSOR: // actualy already connected in previous block
  1223. break;
  1224. case PT_SOCKET_MD:
  1225. case PT_SOCKET_PTZ:
  1226. case PT_SOCKET_VM:
  1227. case PT_SOCKET_LGS:
  1228. case PT_SOCKET_MIC1300:
  1229. case PT_SOCKET_TKS576:
  1230. case PT_SOCKET_PG3AD:
  1231. case PT_SOCKET_PELCO:
  1232. case PT_SOCKET_AMERICAN_DYNAMIS:
  1233. break;
  1234. case PT_INPUT_SENSOR:
  1235. {
  1236. CDirectInputSet *pSensorInputSet = NULL;
  1237. CDirectInputSet *pCommandInputSet = NULL;
  1238. switch( pTempl1->m_pSensor->GetType() )
  1239. {
  1240. case CVisual::DC: pSensorInputSet = &static_cast<CSensorDC*>(pTempl1->m_pSensor)->GetSensorInputSet();
  1241. case CVisual::LGS:
  1242. case CVisual::CLD: pCommandInputSet = &pTempl1->m_pSensor->GetCommandInputSet(); break;
  1243. }
  1244. CDirectInputSet *pInputSet = NULL;
  1245. switch( pPin1->GetSubType() )
  1246. {
  1247. case PST_SENSOR: pInputSet = pSensorInputSet; ASSERT( pInputSet ); break;
  1248. case PST_COMMAND: pInputSet = pCommandInputSet; ASSERT( pInputSet ); break;
  1249. default: ASSERT( NULL ); break;
  1250. }
  1251. if( !pInputSet )
  1252. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::Load"), _T("DirectInputSet equal NULL") );
  1253. else
  1254. {
  1255. CDeviceDI *pDeviceDI = NULL;
  1256. switch( pTempl2->m_pDevice->GetDeviceType() )
  1257. {
  1258. case OFNS::DT_PCI_1762: pDeviceDI = static_cast<CDeviceDI*>( static_cast<CDevicePCI1762*>(pTempl2->m_pDevice) ); break;
  1259. case OFNS::DT_SOCKET: pDeviceDI = static_cast<CSocketRS232DI*>(pTempl2->m_pDevice)->GetDeviceDI(); break;
  1260. }
  1261. if( !pDeviceDI )
  1262. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::Load"), _T("DeviceDI equal NULL") );
  1263. else
  1264. {
  1265. pInputSet->ConnectToDevice( pDeviceDI, pPin2->m_nSubIndex, pPin1->m_nSubIndex );
  1266. pDeviceDI->SetNC( pPin2->m_nSubIndex, pPin2->GetParam() );
  1267. }
  1268. }
  1269. }
  1270. break;
  1271. case PT_SENSOR_INPUT:
  1272. break;
  1273. case PT_EVENT_OUTPUT:
  1274. {
  1275. CDirectOutputSet *pEventOutputSet = &pTempl1->m_pSensor->GetEventOutputSet();
  1276. if( !pEventOutputSet )
  1277. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::Load"), _T("DirectOutputSet equal NULL") );
  1278. else
  1279. {
  1280. CDeviceDO *pDeviceDO = NULL;
  1281. switch( pTempl2->m_pDevice->GetDeviceType() )
  1282. {
  1283. case DT_PCI_1762: pDeviceDO = static_cast<CDeviceDO*>( static_cast<CDevicePCI1762*>(pTempl2->m_pDevice) ); break;
  1284. case DT_SOCKET: pDeviceDO = static_cast<CSocketRS232DI*>( pTempl2->m_pSocket )->GetDeviceDO(); break;
  1285. }
  1286. if( !pDeviceDO )
  1287. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::Load"), _T("DeviceDO equal NULL") );
  1288. else
  1289. {
  1290. pEventOutputSet->ConnectToDevice( pDeviceDO, pPin2->m_nSubIndex, pPin1->m_nSubIndex );
  1291. // pDeviceDO->SetNC( pPin2->m_nSubIndex, pPin2->GetParam() );
  1292. }
  1293. }
  1294. }
  1295. break;
  1296. case PT_OUTPUT_EVENT:
  1297. break;
  1298. }
  1299. }
  1300. }
  1301. }
  1302. }
  1303. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Locical connections passed") );
  1304. OF.GetProtectedString( m_Copyright );
  1305. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("OF.GetProtectedString passed") );
  1306. }
  1307. m_nZonesCount = 1;
  1308. m_ppZones = new CZone*[ m_nZonesCount ];
  1309. for( int i = 0; i < m_nZonesCount; i++ )
  1310. {
  1311. m_ppZones[i] = new CZone;
  1312. m_ppZones[i]->SetName( CString( _T("ZONE") ) );
  1313. m_ppZones[i]->Create( this, i );
  1314. m_ppZones[i]->SetState( CSensor::UNKNOWN );
  1315. SDPOINT p(0.0,0.0);
  1316. for( int j = 0; j < m_ppZones[i]->GetCount(); j++ )
  1317. {
  1318. p.x += m_ppZones[i]->GetSensor( j )->GetPosition().x;
  1319. p.y += m_ppZones[i]->GetSensor( j )->GetPosition().y;
  1320. }
  1321. p.x /= m_ppZones[i]->GetCount();
  1322. p.y /= m_ppZones[i]->GetCount();
  1323. m_ppZones[i]->SetPosition( p );
  1324. }
  1325. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Zones creating passed") );
  1326. m_Options.bNeedAutorization = FALSE;
  1327. m_Options.nZoomFactor = 25;
  1328. m_PhoneCallCenter.Create( this );
  1329. UpdateSettings();
  1330. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("m_PhoneCallCenter.Create passed") );
  1331. }
  1332. catch( CFileException *e )
  1333. {
  1334. e->ReportError();
  1335. }
  1336. catch( CArchiveException *e )
  1337. {
  1338. e->ReportError();
  1339. }
  1340. #endif
  1341. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CSensorArray::Load"), _T("Succeeded") );
  1342. return TRUE;
  1343. }
  1344. /*
  1345. void CSensorArray::SensorUpdate(CSensor *pSensor)
  1346. {
  1347. if( m_hEventWnd )
  1348. {
  1349. PostMessage( m_hEventWnd, WM_SENSOR_UPDATE, (WPARAM)0, (LPARAM)pSensor );
  1350. }
  1351. }
  1352. void CSensorArray::SensorEvent(int nIndex, DWORD data)
  1353. {
  1354. if( m_pEventWnd )
  1355. {
  1356. // m_pEventWnd->PostMessage( WM_SENSOR_EVENT, (WPARAM)nIndex, (LPARAM)data );
  1357. EVENT event;
  1358. event.dwID = LGS_EVENT_SENSOR;
  1359. event.dwData1 = nIndex;
  1360. event.dwData2 = data;
  1361. m_pEventQueue->PostEvent( event );
  1362. }
  1363. }
  1364. */
  1365. void CSensorArray::CommandLoop( int nRunningMode )
  1366. {
  1367. for( int i = 0; i < m_nSocket; i++ )
  1368. {
  1369. switch( nRunningMode )
  1370. {
  1371. case MODE_HOST:
  1372. switch( m_ppSocket[i]->GetType() )
  1373. {
  1374. // case SOCKET_SPRU:
  1375. // case SOCKET_SM:
  1376. // case SOCKET_ECS:
  1377. // case SOCKET_BACKUP:
  1378. case SOCKET_MD:
  1379. case SOCKET_LGS:
  1380. case SOCKET_PTZ:
  1381. case SOCKET_RS232DI:
  1382. case SOCKET_CCC:
  1383. // case SOCKET_VM:
  1384. m_ppSocket[i]->CommandLoopStart();
  1385. break;
  1386. }
  1387. break;
  1388. case MODE_BACKUP:
  1389. switch( m_ppSocket[i]->GetType() )
  1390. {
  1391. case SOCKET_BACKUP:
  1392. m_ppSocket[i]->CommandLoopStart();
  1393. break;
  1394. case SOCKET_SPRU:
  1395. case SOCKET_SM:
  1396. case SOCKET_ECS:
  1397. case SOCKET_MD:
  1398. case SOCKET_VM:
  1399. m_ppSocket[i]->CommandLoopStop();
  1400. break;
  1401. }
  1402. break;
  1403. case MODE_BACKUP_ACTIVE:
  1404. switch( m_ppSocket[i]->GetType() )
  1405. {
  1406. case SOCKET_SPRU:
  1407. case SOCKET_SM:
  1408. case SOCKET_ECS:
  1409. case SOCKET_BACKUP:
  1410. case SOCKET_MD:
  1411. case SOCKET_VM:
  1412. m_ppSocket[i]->CommandLoopStart();
  1413. break;
  1414. }
  1415. break;
  1416. case MODE_MOBILEMAP:
  1417. switch( m_ppSocket[i]->GetType() )
  1418. {
  1419. case SOCKET_BACKUP:
  1420. m_ppSocket[i]->CommandLoopStart();
  1421. break;
  1422. case SOCKET_SPRU:
  1423. case SOCKET_SM:
  1424. case SOCKET_ECS:
  1425. case SOCKET_MD:
  1426. case SOCKET_VM:
  1427. m_ppSocket[i]->CommandLoopStop();
  1428. break;
  1429. }
  1430. break;
  1431. case MODE_STOP:
  1432. m_ppSocket[i]->CommandLoopStop();
  1433. break;
  1434. }
  1435. }
  1436. }
  1437. /*
  1438. void CSensorArray::SocketEvent(int nIndex, DWORD data)
  1439. {
  1440. if( m_pEventWnd )
  1441. {
  1442. // m_pEventWnd->PostMessage( WM_SOCKET_EVENT, (WPARAM)nIndex, (LPARAM)data );
  1443. EVENT event;
  1444. event.dwID = LGS_EVENT_SOCKET;
  1445. event.dwData1 = nIndex;
  1446. event.dwData2 = data;
  1447. m_pEventQueue->PostEvent( event );
  1448. }
  1449. }
  1450. */
  1451. void CSensorArray::SetEventQueue(CEventQueue *pEventQueue)
  1452. {
  1453. m_pEventQueue = pEventQueue;
  1454. }
  1455. void CSensorArray::Reset( CSensor *pSensor )
  1456. {
  1457. if( pSensor )
  1458. {
  1459. pSensor->Reset();
  1460. }
  1461. else
  1462. {
  1463. for( int i = 0; i < m_nZonesCount; i++ )
  1464. m_ppZones[i]->Reset();
  1465. for( i = 0; i < m_nVideoCamera; i++ )
  1466. {
  1467. if( m_ppVideoCamera[i]->GetType() == VC_PTZ )
  1468. static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[i])->CmdReset();
  1469. }
  1470. }
  1471. }
  1472. BOOL CSensorArray::PostSocketEvent( EVENT &event, INT nType )
  1473. {
  1474. BOOL bSuccess = FALSE;
  1475. for( int i = 0; i < m_nSocket; i++ )
  1476. if( m_ppSocket[i]->GetType() == nType )
  1477. bSuccess = m_ppSocket[i]->PostEvent( event );
  1478. return FALSE;
  1479. }
  1480. BOOL CSensorArray::CheckGuard( LPSTR pGuard )
  1481. {
  1482. if( m_nGuardsCount )
  1483. {
  1484. for( int g = 0; g < m_nGuardsCount; g++ )
  1485. if( !stricmp( m_pGuards[ g ].pName, pGuard ) )
  1486. return TRUE;
  1487. return FALSE;
  1488. }
  1489. return TRUE;
  1490. }
  1491. BOOL CSensorArray::CheckSuper( LPSTR pSuper )
  1492. {
  1493. if( m_nSupersCount )
  1494. {
  1495. for( int s = 0; s < m_nSupersCount; s++ )
  1496. if( !stricmp( m_pSupers[ s ].pName, pSuper ) )
  1497. return TRUE;
  1498. return FALSE;
  1499. }
  1500. return TRUE;
  1501. }
  1502. BOOL CSensorArray::CheckSuperPassword( LPSTR pSuper, LPSTR pPassword )
  1503. {
  1504. if( m_nSupersCount )
  1505. {
  1506. for( int s = 0; s < m_nSupersCount; s++ )
  1507. if( !stricmp( m_pSupers[ s ].pName, pSuper ) )
  1508. {
  1509. if( !stricmp( m_pSupers[ s ].pPassword, pPassword ) )
  1510. return TRUE;
  1511. break;
  1512. }
  1513. return FALSE;
  1514. }
  1515. return TRUE;
  1516. }
  1517. BOOL CSensorArray::CheckFilters()
  1518. {
  1519. for( int f = 0; f < m_nFiltersCount; f++ )
  1520. {
  1521. IOFILTER *pFilter = m_pFilters + f;
  1522. BOOL bResult = TRUE;
  1523. for( int c = 0; c < pFilter->ff.nInputCount; c++ )
  1524. {
  1525. FILE_CONDITION *pCondition = m_pConditions + pFilter->ff.inputs[c];
  1526. CSensorSPRU *pSensor = static_cast<CSensorSPRU*>(GetSensor( pCondition->nSensor ));
  1527. INT nState = pSensor->GetState();
  1528. INT nBitMask = pSensor->GetBitMask();
  1529. INT nBitState = pSensor->GetBitState() & nBitMask;
  1530. INT nBitAlarm = pSensor->GetBitAlarm() & nBitMask;
  1531. INT nBitEnable = pSensor->GetBitEnable() & nBitMask;
  1532. BOOL bCondition = FALSE;
  1533. if( pCondition->nState & FILE_UNKNOWN )
  1534. {
  1535. if( nState== CVisual::UNKNOWN )
  1536. bCondition = TRUE;
  1537. }
  1538. if( pCondition->nState & FILE_SS_NORMAL )
  1539. {
  1540. if( nState==CVisual::NORMAL )
  1541. bCondition = TRUE;
  1542. }
  1543. if( pCondition->nState & FILE_SS_TIMEOUT )
  1544. {
  1545. if( nState==CVisual::TIMEOUT )
  1546. bCondition = TRUE;
  1547. }
  1548. if( pCondition->bAll )
  1549. {
  1550. if( pCondition->nState & FILE_SS_DISABLE )
  1551. {
  1552. if( ( nBitEnable & pCondition->nBitMask) == pCondition->nBitMask )
  1553. bCondition = TRUE;
  1554. }
  1555. if( pCondition->nState & FILE_SS_POSTALARM )
  1556. {
  1557. if( ( nBitAlarm & pCondition->nBitMask ) == pCondition->nBitMask )
  1558. bCondition = TRUE;
  1559. }
  1560. if( pCondition->nState & FILE_SS_ALARM )
  1561. {
  1562. if( ( nBitState & pCondition->nBitMask ) == pCondition->nBitMask )
  1563. bCondition = TRUE;
  1564. }
  1565. }
  1566. else
  1567. {
  1568. if( pCondition->nState & FILE_SS_DISABLE )
  1569. {
  1570. if( nBitEnable & pCondition->nBitMask )
  1571. bCondition = TRUE;
  1572. }
  1573. if( pCondition->nState & FILE_SS_POSTALARM )
  1574. {
  1575. if( nBitAlarm & pCondition->nBitMask )
  1576. bCondition = TRUE;
  1577. }
  1578. if( pCondition->nState & FILE_SS_ALARM )
  1579. {
  1580. if( nBitState & pCondition->nBitMask )
  1581. bCondition = TRUE;
  1582. }
  1583. }
  1584. if( !bCondition )
  1585. {
  1586. bResult = FALSE;
  1587. break;
  1588. }
  1589. }
  1590. if( bResult )
  1591. {
  1592. if( pFilter->bNeedPerform )
  1593. {
  1594. EVENT event;
  1595. event.id = LGS_EVENT_GPRU_COMMAND_SEND;
  1596. event.color = 0;
  1597. strcpy( event.pText, "" );
  1598. SYSTEMTIME st;
  1599. ::GetLocalTime( &st );
  1600. ::SystemTimeToFileTime( &st, (LPFILETIME)&event.time );
  1601. event.data8 = 0;
  1602. for( int c = 0; c < pFilter->ff.nCommandCount; c++ )
  1603. {
  1604. FILE_COMMAND *pCommand = m_pCommands + pFilter->ff.commands[c];
  1605. event.data16 = MAKEWORD( pCommand->nAddress, pCommand->nLine );
  1606. event.data32 = ( ( pCommand->nCommand >> 8 ) & 0xFF ) |
  1607. ( ( pCommand->nCommand >> 16 ) & 0xFF00 );
  1608. PostSocketEvent( event, SOCKET_SPRU );
  1609. event.data16 = MAKEWORD( pCommand->nAddress+1, pCommand->nLine );
  1610. event.data32 = ( pCommand->nCommand & 0xFF ) |
  1611. ( ( pCommand->nCommand >> 8 ) & 0xFF00 );
  1612. PostSocketEvent( event, SOCKET_SPRU );
  1613. }
  1614. pFilter->bNeedPerform = FALSE;
  1615. }
  1616. }
  1617. else pFilter->bNeedPerform = TRUE;
  1618. }
  1619. /*
  1620. EVENT event;
  1621. event.event = LGS_EVENT_GPRU_COMMAND_SEND;
  1622. event.color = 0;
  1623. strcpy( event.pText, "" );
  1624. SYSTEMTIME st;
  1625. ::GetLocalTime( &st );
  1626. event.data8 = 0;
  1627. event.data16 = MAKEWORD( 0, 0 );
  1628. event.data32 = 0;
  1629. SystemTimeToFileTime( &st, (LPFILETIME)&event.time );
  1630. PostSocketEvent( event, SOCKET_SPRU );
  1631. */
  1632. return TRUE;
  1633. }
  1634. BOOL CSensorArray::CheckPatrols()
  1635. {
  1636. /*
  1637. DWORD dwCT = ::GetTickCount();
  1638. for( int i = 0; i < m_nPatrolsCount; i++ )
  1639. {
  1640. if( m_pPatrols[i].bActive )
  1641. {
  1642. if( dwCT >= m_pPatrols[i].maxTime )
  1643. {
  1644. m_pEventQueue->PostEvent( LGS_EVENT_PATROL, FALSE, m_pPatrols[i].nActive, 0, RGB(0xFF,0,0), "patrol time expaired" );
  1645. m_pPatrols[i].bActive = FALSE;
  1646. }
  1647. }
  1648. }
  1649. */
  1650. m_Patrol.CheckTime();
  1651. return TRUE;
  1652. }
  1653. BOOL CSensorArray::CheckSensors()
  1654. {
  1655. for( int i = 0; i < m_nSensor; i++ )
  1656. {
  1657. switch( m_ppSensor[i]->GetType() )
  1658. {
  1659. case CSensor::DC:
  1660. static_cast<CSensorDC*>(m_ppSensor[i])->CheckState();
  1661. break;
  1662. case CSensor::LGS:
  1663. static_cast<CSensorLGS*>(m_ppSensor[i])->CheckState();
  1664. break;
  1665. case CSensor::CLD:
  1666. static_cast<CSensorCLD*>(m_ppSensor[i])->CheckState();
  1667. break;
  1668. }
  1669. }
  1670. return TRUE;
  1671. }
  1672. BOOL CSensorArray::CheckSensorsCommand()
  1673. {
  1674. for( int i = 0; i < m_nSensor; i++ )
  1675. {
  1676. switch( m_ppSensor[i]->GetType() )
  1677. {
  1678. case CSensor::DC:
  1679. static_cast<CSensorDC*>(m_ppSensor[i])->CheckCommand();
  1680. break;
  1681. case CSensor::LGS:
  1682. static_cast<CSensorLGS*>(m_ppSensor[i])->CheckCommand();
  1683. break;
  1684. case CSensor::CLD:
  1685. static_cast<CSensorCLD*>(m_ppSensor[i])->CheckCommand();
  1686. break;
  1687. }
  1688. }
  1689. return TRUE;
  1690. }
  1691. BOOL CSensorArray::CheckCameras()
  1692. {
  1693. for( int i = 0; i < m_nVideoCamera; i++ )
  1694. m_ppVideoCamera[i]->CheckState();
  1695. SYSTEMTIME st;
  1696. ::GetLocalTime( &st );
  1697. int cTime = st.wHour * 60 + st.wMinute;
  1698. int dTime = m_nIrisDayHour * 60 + m_nIrisDayMinute;
  1699. int nTime = m_nIrisNightHour * 60 + m_nIrisNightMinute;
  1700. if( cTime >= dTime && cTime < nTime )
  1701. {
  1702. if( m_bIrisNeedSwitchDay )
  1703. {
  1704. for( int i = 0; i < m_nVideoCamera; i++ )
  1705. {
  1706. if( m_ppVideoCamera[i]->GetType() == VC_PTZ )
  1707. {
  1708. static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[i])->SetIrisDay( TRUE );
  1709. }
  1710. }
  1711. m_bIrisNeedSwitchDay = FALSE;
  1712. m_bIrisNeedSwitchNight = TRUE;
  1713. }
  1714. }
  1715. else
  1716. {
  1717. if( m_bIrisNeedSwitchNight )
  1718. {
  1719. for( int i = 0; i < m_nVideoCamera; i++ )
  1720. {
  1721. if( m_ppVideoCamera[i]->GetType() == VC_PTZ )
  1722. {
  1723. static_cast<CVideoCameraPTZ*>(m_ppVideoCamera[i])->SetIrisDay( FALSE );
  1724. }
  1725. }
  1726. m_bIrisNeedSwitchNight = FALSE;
  1727. m_bIrisNeedSwitchDay = TRUE;
  1728. }
  1729. }
  1730. return TRUE;
  1731. }
  1732. void CSensorArray::GetIrisTime( int& nDayHour, int& nDayMinute, double &dDayValue, int& nNightHour, int& nNightMinute, double &dNightValue )
  1733. {
  1734. nDayHour = m_nIrisDayHour;
  1735. nDayMinute = m_nIrisDayMinute;
  1736. nNightHour = m_nIrisNightHour;
  1737. nNightMinute = m_nIrisNightMinute;
  1738. dDayValue = m_dIrisDayValue;
  1739. dNightValue = m_dIrisNightValue;
  1740. }
  1741. void CSensorArray::SetIrisTime( int nDayHour, int nDayMinute, double dDayValue, int nNightHour, int nNightMinute, double dNightValue )
  1742. {
  1743. m_nIrisDayHour = nDayHour;
  1744. m_nIrisDayMinute = nDayMinute;
  1745. m_nIrisNightHour = nNightHour;
  1746. m_nIrisNightMinute = nNightMinute;
  1747. m_dIrisDayValue = dDayValue;
  1748. m_dIrisNightValue = dNightValue;
  1749. }
  1750. void CSensorArray::UpdateDemo( INT nVideoInput, double SampleTime )
  1751. {
  1752. INT nDevice = 0;
  1753. for( INT i = 0; i < m_nDevice; i++ )
  1754. {
  1755. if( m_ppDevice[i]->GetSocket()->GetType() == SOCKET_MD )
  1756. {
  1757. // if current LGS relative to current video
  1758. if( nDevice++ == nVideoInput )
  1759. {
  1760. INT nSampleTime = (INT)SampleTime;
  1761. const double _PI_ = 2 * asin(1.0);
  1762. if( nSampleTime == 0 )
  1763. m_nLastDemoSampleTime[nVideoInput] = 0;
  1764. switch( nVideoInput )
  1765. {
  1766. case 0:
  1767. if( nSampleTime >= 42 && m_nLastDemoSampleTime[nVideoInput] < nSampleTime )
  1768. {
  1769. m_nLastDemoSampleTime[nVideoInput] = nSampleTime;
  1770. double x = -75 + nSampleTime;
  1771. double y = -20 * cos( 3.1415 / 2.0 * x / 100 );
  1772. double r = sqrt( x * x + y * y );
  1773. double a = (INT)(atan2((double)-y , (double)x) * 180.0 / _PI_);
  1774. if(a < 0.0 ) a += 360.0;
  1775. EVENT event;
  1776. event.id = LGS_EVENT_DEMO;
  1777. event.pDemoDevice = m_ppDevice[i];
  1778. event.dDemoRange = r / 100.0;
  1779. event.dDemoAngle = a;
  1780. PostSocketEvent( event, SOCKET_MD );
  1781. }
  1782. break;
  1783. case 1:
  1784. if( nSampleTime >= 20 && m_nLastDemoSampleTime[nVideoInput] < nSampleTime )
  1785. {
  1786. m_nLastDemoSampleTime[nVideoInput] = nSampleTime;
  1787. double x = 60-nSampleTime;
  1788. double y = -20 * cos( 3.1415 / 2.0 * x / 100 );
  1789. double r = sqrt( x * x + y * y );
  1790. double a = (INT)(atan2((double)-y , (double)x) * 180.0 / _PI_);
  1791. if(a < 0.0 ) a += 360.0;
  1792. EVENT event;
  1793. event.id = LGS_EVENT_DEMO;
  1794. event.pDemoDevice = m_ppDevice[i];
  1795. event.dDemoRange = r / 100.0;
  1796. event.dDemoAngle = a;
  1797. PostSocketEvent( event, SOCKET_MD );
  1798. }
  1799. break;
  1800. }
  1801. }
  1802. }
  1803. }
  1804. }
  1805. /*
  1806. BOOL CSensorArray::StoreExtendedInfo( LPCTSTR pFormat, ... )
  1807. {
  1808. const INT MAX_EXTENDED_TEXT_LINE = 100;
  1809. const INT MAX_EXTENDED_TEXT_LINE_COUNT = 1000000;
  1810. // open file
  1811. CFile file;
  1812. if( !file.Open( "ISSC_EX.LOG", CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite ) )
  1813. return FALSE;
  1814. // place header
  1815. DWORD dwPos = 0;
  1816. if( file.Read( &dwPos, sizeof(dwPos) ) != sizeof(dwPos) )
  1817. {
  1818. try
  1819. {
  1820. file.Write( &dwPos, sizeof(dwPos) );
  1821. }
  1822. catch( CFileException* )
  1823. {
  1824. file.Close();
  1825. return FALSE;
  1826. }
  1827. }
  1828. // goto position
  1829. file.Seek( dwPos + sizeof(dwPos), SEEK_SET );
  1830. // write information
  1831. try
  1832. {
  1833. TCHAR pBuffer[MAX_EXTENDED_TEXT_LINE];
  1834. memset( pBuffer, ' ', MAX_EXTENDED_TEXT_LINE );
  1835. pBuffer[MAX_EXTENDED_TEXT_LINE-2] = '\r';
  1836. pBuffer[MAX_EXTENDED_TEXT_LINE-1] = '\n';
  1837. // prepare string
  1838. va_list pMarker;
  1839. va_start( pMarker, pFormat );
  1840. INT nCount = _vsntprintf( pBuffer, MAX_EXTENDED_TEXT_LINE, pFormat, pMarker );
  1841. // substitute terminating 0 with ' ';
  1842. if( nCount >= 0 ) pBuffer[ nCount ] = ' ';
  1843. va_end( pMarker );
  1844. // write to file
  1845. file.Write( pBuffer, MAX_EXTENDED_TEXT_LINE );
  1846. }
  1847. catch( CFileException* )
  1848. {
  1849. file.Close();
  1850. return FALSE;
  1851. }
  1852. // calculate position
  1853. dwPos = (dwPos + MAX_EXTENDED_TEXT_LINE) % (MAX_EXTENDED_TEXT_LINE * MAX_EXTENDED_TEXT_LINE_COUNT);
  1854. // goto position
  1855. file.Seek( 0, SEEK_SET );
  1856. // write information
  1857. try
  1858. {
  1859. file.Write( &dwPos, sizeof(dwPos) );
  1860. }
  1861. catch( CFileException* )
  1862. {
  1863. file.Close();
  1864. return FALSE;
  1865. }
  1866. file.Close();
  1867. return TRUE;
  1868. }
  1869. */
  1870. BOOL CSensorArray::StoreExtendedInfo( LPCTSTR pFormat, ... )
  1871. {
  1872. return TRUE;
  1873. const DWORD MAX_EXTENDED_FILE_SIZE = 10000000UL; // 10 Mb
  1874. LPCTSTR pFileName = _T("ISSC_EX_0.LOG");
  1875. LPCTSTR pFileName2 = _T("ISSC_EX_1.LOG");
  1876. // get file size
  1877. WIN32_FILE_ATTRIBUTE_DATA FileAttributeData;
  1878. memset( &FileAttributeData, 0, sizeof(FileAttributeData) );
  1879. if( !::GetFileAttributesEx( pFileName, GetFileExInfoStandard, &FileAttributeData ) )
  1880. {
  1881. DWORD dwError = ::GetLastError();
  1882. switch( dwError )
  1883. {
  1884. case ERROR_FILE_NOT_FOUND:
  1885. break;
  1886. default:
  1887. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::StoreExtendedInfo"), _T("GetFileAttributesEx failed with 0x%08X"), dwError );
  1888. return FALSE;
  1889. }
  1890. }
  1891. // check file size
  1892. if( FileAttributeData.nFileSizeLow > MAX_EXTENDED_FILE_SIZE )
  1893. {
  1894. // copy contens to new file
  1895. if( !::MoveFileEx( pFileName, pFileName2, MOVEFILE_REPLACE_EXISTING ) )
  1896. {
  1897. DWORD dwError = GetLastError();
  1898. switch( dwError )
  1899. {
  1900. case ERROR_CALL_NOT_IMPLEMENTED:
  1901. if( ::DeleteFile( pFileName2 ) )
  1902. {
  1903. dwError = GetLastError();
  1904. switch( dwError )
  1905. {
  1906. case ERROR_FILE_NOT_FOUND:
  1907. break;
  1908. default:
  1909. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::StoreExtendedInfo"), _T("DeleteFile failed with 0x%08X"), dwError );
  1910. return FALSE;
  1911. }
  1912. }
  1913. if( !::MoveFile( pFileName, pFileName2 ) )
  1914. {
  1915. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::StoreExtendedInfo"), _T("MoveFile failed with 0x%08X"), GetLastError() );
  1916. return FALSE;
  1917. }
  1918. break;
  1919. default:
  1920. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::StoreExtendedInfo"), _T("MoveFileEx failed with 0x%08X"), dwError );
  1921. return FALSE;
  1922. }
  1923. }
  1924. }
  1925. FILE *pFile = _tfopen( pFileName, _T("a+") );
  1926. if( !pFile )
  1927. {
  1928. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CSensorArray::StoreExtendedInfo"), _T("_tfopen filed with 0x%08X"), GetLastError() );
  1929. return FALSE;
  1930. }
  1931. // prepare string
  1932. TCHAR pBuffer[MAX_PATH];
  1933. va_list pMarker;
  1934. va_start( pMarker, pFormat );
  1935. INT nCount = _vsntprintf( pBuffer, MAX_PATH, pFormat, pMarker );
  1936. // update counter if size was exeeded
  1937. if( nCount < 0 ) nCount = MAX_PATH;
  1938. va_end( pMarker );
  1939. // write data
  1940. fwrite( pBuffer, 1, nCount, pFile );
  1941. TCHAR pLR[] = _T("\r\n");
  1942. fwrite( pLR, 1, sizeof(TCHAR) * 2, pFile );
  1943. // close file
  1944. fclose( pFile );
  1945. return TRUE;
  1946. }
  1947. BOOL CSensorArray::DrawBackground( CDC *pDC, CRect *pRect )
  1948. {
  1949. m_Background.Draw( pDC, pRect );
  1950. double dMeterToPixelScale = pRect->Width() / m_Background.GetMeterScale();
  1951. for( INT i = 0; i < m_nSensor; i++ )
  1952. {
  1953. CSensor *pSensor = GetSensor(i);
  1954. CPoint center( (INT)( pSensor->GetPosition().x * pRect->Width() ),
  1955. (INT)( pSensor->GetPosition().y * pRect->Height() ) );
  1956. pSensor->OnDrawBackground( pDC, center, dMeterToPixelScale );
  1957. }
  1958. return TRUE;
  1959. }
  1960. void CSensorArray::UpdateSettings()
  1961. {
  1962. if( !m_pSettings )
  1963. return;
  1964. m_pSettings->Save( _T("IRIS_DAY_HOUR"), m_nIrisDayHour );
  1965. m_pSettings->Save( _T("IRIS_DAY_MINUTE"), m_nIrisDayMinute );
  1966. m_pSettings->Save( _T("IRIS_DAY_VALUE"), m_dIrisDayValue );
  1967. m_pSettings->Save( _T("IRIS_NIGHT_HOUR"), m_nIrisNightHour );
  1968. m_pSettings->Save( _T("IRIS_NIGHT_MINUTE"), m_nIrisNightMinute );
  1969. m_pSettings->Save( _T("IRIS_NIGHT_VALUE"), m_dIrisNightValue );
  1970. m_pSettings->Save( _T("SETTINGS"), &m_ProgramSettings, sizeof(m_ProgramSettings) );
  1971. for( int i = 0; i < m_nSensor; i++ )
  1972. {
  1973. CSensor *pSensor = m_ppSensor[i];
  1974. switch( pSensor->GetType() )
  1975. {
  1976. case CVisual::LGS:
  1977. static_cast<CSensorLGS*>(pSensor)->SetAutoReset( m_ProgramSettings.AutoResetLGS.bEnable, m_ProgramSettings.AutoResetLGS.nTime );
  1978. break;
  1979. }
  1980. }
  1981. }
  1982. void CSensorArray::SetBackgroundDirty( BOOL bDirty )
  1983. {
  1984. m_bBackgroundDirty = bDirty;
  1985. }
  1986. BOOL CSensorArray::IsBackgroundDirty()
  1987. {
  1988. return m_bBackgroundDirty;
  1989. }
  1990. BOOL CSensorArray::FullSystemRepair()
  1991. {
  1992. for( INT i = 0; i < GetSensorCount(); i++ )
  1993. {
  1994. CSensor *pSensor = GetSensor(i);
  1995. ASSERT( pSensor );
  1996. switch( pSensor->GetType() )
  1997. {
  1998. case CVisual::CLD: static_cast<CSensorCLD*>(pSensor)->Reset(); break;
  1999. case CVisual::LGS: static_cast<CSensorLGS*>(pSensor)->CmdReset( TRUE ); break;
  2000. case CVisual::DC: break;
  2001. }
  2002. }
  2003. return TRUE;
  2004. }