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.

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