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.

1449 lines
41 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 09/04/2000
  5. // Last modification: 17/11/2003
  6. // Project Intruder Position Indicator
  7. // SUBSYSTEM: Receiver information from LGS
  8. // FILE: Lgs.cpp
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file for implemenation of class CLgs
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\LgLib\Version.h"
  16. #include "..\LgLib\LgDebug.h"
  17. #include "Application.h"
  18. #include "Lgs.h"
  19. CLgs::CLgs()
  20. {
  21. m_dCoeficient = 100;
  22. m_pApplication = NULL;
  23. m_hRestartWnd = NULL;
  24. m_hResetWnd = NULL;;
  25. m_hSendFileWnd = NULL;
  26. m_hSoftwareVersionWnd = NULL;
  27. m_hFullResetWnd = NULL;
  28. m_hSetParametersWnd[0] = m_hSetParametersWnd[1] = 0;
  29. m_hGetParametersWnd[0] = m_hGetParametersWnd[1] = 0;
  30. ZeroMemory( &m_Parameters, sizeof( m_Parameters ) );
  31. ZeroMemory( m_pSrcFileName, sizeof(m_pSrcFileName) );
  32. ZeroMemory( m_pDstFileName, sizeof(m_pDstFileName) );
  33. m_hGetSerialNumberWnd = NULL;
  34. memset( &m_SerialNumber, 0, sizeof(m_SerialNumber) );
  35. memset( &m_SoftwareVersion, 0, sizeof(m_SoftwareVersion) );
  36. memset( &m_FullBorder, 0, sizeof(m_FullBorder) );
  37. memset( &m_Border, 0, sizeof(m_Border) );
  38. memset( &m_VoltageParameters, 0, sizeof(m_VoltageParameters) );
  39. m_hSetCommSpeedWnd = NULL;
  40. m_nSetCommSpeed = LGS_COMM_BAUDRATE;
  41. memset( &m_CameraPosition, 0 , sizeof(m_CameraPosition) );
  42. m_bCameraReady = TRUE;
  43. m_bShowCommunicationErrors = FALSE;
  44. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgs::CLgs" );
  45. }
  46. CLgs::~CLgs()
  47. {
  48. Destroy();
  49. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgs::~CLgs" );
  50. }
  51. BOOL CLgs::Create(CApplication *pApp, LPCTSTR pCommPort, INT nBaudRate, INT nBitCount, INT nStopBits, INT nProtocol, double range, INT nAddress, BOOL bAutoBaudrate, BOOL bShowCommunicationErrors, DWORD dwTransactionTimeout )
  52. {
  53. Destroy();
  54. m_dCoeficient = range;
  55. m_pApplication = pApp;
  56. // m_nAddress = nAddress;
  57. m_bShowCommunicationErrors = bShowCommunicationErrors;
  58. m_nCommErrorCount.QuadPart = 0;
  59. if( !m_Socket.Create( pCommPort, nBaudRate, FALSE, FALSE ) )
  60. return FALSE;
  61. // device initialization
  62. // m_Device.SetID( 1 );
  63. m_Device.CLgNetDeviceMD::SetAddress( nAddress );
  64. m_Device.CLgDeviceLGS::SetAddress( nAddress );
  65. m_Device.SetAutoBaudrate( bAutoBaudrate );
  66. m_Device.SetTransactionTimeout( dwTransactionTimeout );
  67. // m_Socket.SetID( 0 );
  68. m_Socket.CLgLinkP<CLgNetObject,CLgNetObject,CLgNetObjectChild>::Link( &m_Device );
  69. m_Socket.CLgLinkP<CLgNetSocket,CLgNetSocketDevice>::Link( &m_Device );
  70. GeneralTestFunction();
  71. return TRUE;
  72. }
  73. BOOL CLgs::Start()
  74. {
  75. return CLgThread::Start( FALSE );
  76. }
  77. BOOL CLgs::Destroy()
  78. {
  79. CLgThread::Stop( TRUE );
  80. m_Socket.Destroy();
  81. return TRUE;
  82. }
  83. #define DEFAULT_PERIOD 1000UL
  84. DWORD CLgs::ThreadProc()
  85. {
  86. // ::SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS );
  87. // ::SetThreadPriority( GetThreadHandle(), THREAD_PRIORITY_TIME_CRITICAL );
  88. __try
  89. {
  90. m_OutMsg.SetDistinationID( m_Device.GetID() );
  91. m_OutMsg.SetSenderID( m_Socket.GetID() );
  92. // prepare test packet
  93. // m_OutMsg.BuildCmdFSFindFirst( "*.*" );
  94. // m_Device.SendMessageToChild( m_OutMsg );
  95. while( !CLgThread::IsStopping() )
  96. {
  97. // #define SELF_TARGET_TEST
  98. #if defined(SELF_TARGET_TEST) && defined(_DEBUG)
  99. static INT nRange = 1; static INT dRange = 10;
  100. static INT nAngle = 0; static INT dAngle = 5;
  101. static DWORD dwTime = 0;
  102. if( GetTickCount() - dwTime > 1000UL )
  103. {
  104. dwTime = GetTickCount();
  105. INT nDevice = rand()%2;
  106. nAngle = (nAngle + 5)%360;
  107. nRange += dRange;
  108. if( nRange > (INT)m_dCoeficient || nRange < 0 ) { dRange = -dRange; nRange += dRange; }
  109. m_pApplication->GetTargetQueue()->PostEvent( nDevice ? 'b' : 'a', nAngle, nRange, nDevice, NULL, 0 );
  110. // m_pApplication->GetTargetQueue()->PostEvent( 'q', nAngle, -1, 0, NULL, 0 );
  111. }
  112. #endif
  113. // check response
  114. HANDLE hEvents[] = { CLgThread::GetThreadStopEvent(), m_Socket.GetMessageEvent() };
  115. switch( WaitForMultipleObjects( 2, hEvents, FALSE, 10UL ) )
  116. {
  117. default:
  118. case WAIT_OBJECT_0:
  119. return 0;
  120. case WAIT_TIMEOUT:
  121. continue;
  122. case WAIT_OBJECT_0 + 1:
  123. break;
  124. }
  125. // process responce
  126. while( m_Socket.PopMessage( m_InMsg ) )
  127. {
  128. BYTE bCommand;
  129. if( !m_InMsg.GetCommand( &bCommand ) )
  130. continue;
  131. switch( bCommand )
  132. {
  133. case CLgDevicePTZ::EVT_ERROR_DATA:
  134. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_ERROR_DATA" );
  135. // CLgs::CmdCameraGetPTZ();
  136. break;
  137. case CLgDeviceLGS::EVT_CAMERA_ERROR:
  138. m_bCameraReady = TRUE;
  139. break;
  140. case CLgDevicePTZ::EVT_GET_PTZ:
  141. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_PTZ" );
  142. if(m_InMsg.GetPTZ( &m_CameraPosition ) )
  143. m_bCameraReady = TRUE;
  144. break;
  145. case CLgDevicePTZ::EVT_SET_PTZ:
  146. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_PTZ" );
  147. if( m_InMsg.GetPTZ( &m_CameraPosition ) )
  148. m_bCameraReady = TRUE;
  149. break;
  150. case CLgDevicePTZ::EVT_SET_FOCUS:
  151. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_FOCUS" );
  152. // m_InMsg.GetFocus( &m_CameraFocus );
  153. // m_bCameraReady = TRUE;
  154. break;
  155. case CLgDevicePTZ::EVT_GET_FOCUS:
  156. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_FOCUS" );
  157. m_InMsg.GetFocus( &m_CameraFocus );
  158. break;
  159. case CLgDevicePTZ::EVT_SET_IRIS:
  160. m_bCameraReady = TRUE;
  161. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_IRIS" );
  162. break;
  163. case CLgDevicePTZ::EVT_MOVE_PAN:
  164. m_bCameraReady = TRUE;
  165. // CmdCameraGetPTZ();
  166. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_PAN" );
  167. break;
  168. case CLgDevicePTZ::EVT_MOVE_TILT:
  169. m_bCameraReady = TRUE;
  170. // CmdCameraGetPTZ();
  171. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_TILT" );
  172. break;
  173. case CLgDevicePTZ::EVT_MOVE_ZOOM:
  174. m_bCameraReady = TRUE;
  175. // CmdCameraGetPTZ();
  176. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_ZOOM" );
  177. break;
  178. case CLgDevicePTZ::EVT_MOVE_FOCUS:
  179. m_bCameraReady = TRUE;
  180. // CmdCameraGetPTZ();
  181. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_MOVE_FOCUS" );
  182. break;
  183. case CLgDevicePTZ::EVT_WIPER:
  184. m_bCameraReady = TRUE;
  185. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_WIPER" );
  186. break;
  187. case CLgDeviceLGS::EVT_RESET:
  188. ::PostMessage(m_hResetWnd, WM_LGS_RESET, 1, 0);
  189. // notify recipients about reset
  190. OnNotifyReset( TRUE, bCommand );
  191. break;
  192. case CLgDeviceLGS::EVT_RESTART:
  193. ::PostMessage(m_hRestartWnd, WM_LGS_RESTART, 1, 0);
  194. // notify recipients about reset
  195. OnNotifyReset( TRUE, bCommand );
  196. break;
  197. case CLgDeviceLGS::EVT_FULL_RESET:
  198. ::PostMessage(m_hFullResetWnd, WM_LGS_FULL_RESET, 1, 0);
  199. // notify recipients about reset
  200. OnNotifyReset( TRUE, bCommand );
  201. break;
  202. case CLgDeviceLGS::EVT_QUIT:
  203. // notify recipients about reset
  204. OnNotifyReset( TRUE, bCommand );
  205. break;
  206. case CLgDeviceLGS::EVT_BORDER:
  207. if( m_InMsg.GetBorder( &m_Border ) )
  208. {
  209. OnFinishDraw();
  210. ::PostMessage(m_hDrawMapWnd, WM_LGS_DRAWMAP, 0, 0);
  211. }
  212. break;
  213. case CLgDeviceLGS::EVT_BORDER_PREPARING:
  214. ::PostMessage( m_hDrawMapWnd, WM_LGS_DRAWMAP, 2, (LONG)0 );
  215. break;
  216. case CLgDeviceLGS::EVT_BORDER_PROGRESS:
  217. {
  218. INT dProgress;
  219. if( m_InMsg.GetBorderProgress( &dProgress ) )
  220. {
  221. ::PostMessage( m_hDrawMapWnd, WM_LGS_DRAWMAP, 1, dProgress );
  222. }
  223. }
  224. break;
  225. case CLgDeviceLGS::EVT_FULL_BORDER:
  226. {
  227. if( m_InMsg.GetFullBorder( &m_FullBorder ) )
  228. {
  229. OnFinishDraw();
  230. ::PostMessage(m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 0, 0);
  231. }
  232. }
  233. break;
  234. case CLgDeviceLGS::EVT_FULL_BORDER_PREPARING:
  235. {
  236. INT dPercent;
  237. if( m_InMsg.GetFullBorderPreparing( &dPercent ) )
  238. {
  239. ::PostMessage( m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 2, (LONG)dPercent );
  240. }
  241. }
  242. break;
  243. case CLgDeviceLGS::EVT_FULL_BORDER_PROGRESS:
  244. {
  245. INT dProgress;
  246. if( m_InMsg.GetFullBorderProgress( &dProgress ) )
  247. {
  248. ::PostMessage( m_hDrawFullMapWnd, WM_LGS_FULL_DRAWMAP, 1, (LONG)dProgress );
  249. }
  250. }
  251. break;
  252. case CLgDeviceLGS::EVT_BLIND:
  253. {
  254. CLgDeviceLGS::LGS_BLIND blind;
  255. if( m_InMsg.GetBlind( &blind ) )
  256. m_pApplication->GetTargetQueue()->PostEvent( 'm', blind.bReason, 0, blind.nDevice, 0, 0 );
  257. }
  258. break;
  259. case CLgDeviceLGS::EVT_FLIP:
  260. {
  261. CLgDeviceLGS::LGS_FLIP flip;
  262. if( m_InMsg.GetFlip( &flip ) )
  263. m_pApplication->GetTargetQueue()->PostEvent( 'i', flip.nLoops, 0, flip.nDevice, 0, 0 );
  264. }
  265. break;
  266. case CLgDeviceLGS::EVT_TARGET:
  267. {
  268. CLgDeviceLGS::LGS_TARGET target;
  269. if( m_InMsg.GetTarget( &target ) )
  270. {
  271. // LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDeviceLGS::EVT_TARGET for device %d", target.bDevice );
  272. char cType;
  273. if( target.bType == LGS::TT_WIDE ) cType = 'w';
  274. else
  275. if( target.bType == LGS::TT_NORMAL ) cType = target.bDevice ? 'b' : 'a';
  276. else
  277. // if( target.bType == LGS::TT_BLIND ) cType = 'm';
  278. // else
  279. // if( target.bType == LGS::TT_FLIP ) cType = 'i';
  280. // else
  281. if( target.bType == LGS::TT_TEST ) cType = 'l';
  282. else break;
  283. if( target.bType == LGS::TT_WIDE || target.bType == LGS::TT_NORMAL )
  284. {
  285. double range = target.dRange * m_dCoeficient;
  286. // if( range < 50.0 )
  287. // range += 1.0;
  288. m_pApplication->GetTargetQueue()->PostEvent( cType, target.dAngle, range, target.bDevice, NULL, target.nWidth );
  289. }
  290. else
  291. m_pApplication->GetTargetQueue()->PostEvent( cType, target.dAngle, target.dRange, target.bDevice, NULL, target.nWidth );
  292. }
  293. }
  294. break;
  295. case CLgDeviceLGS::EVT_DOPLER_ALARM:
  296. {
  297. CLgDeviceLGS::DOPLER_ALARM alarm;
  298. if( m_InMsg.GetDoplerAlarm( &alarm ) )
  299. {
  300. m_pApplication->GetTargetQueue()->PostEvent( 'q', alarm.dPan, -1, 0, NULL, 0 );
  301. }
  302. }
  303. break;
  304. case CLgDeviceLGS::EVT_SET_DOPLER:
  305. {
  306. m_bCameraReady = TRUE;
  307. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_DOPLER" );
  308. CLgDeviceLGS::DOPLER dopler;
  309. if( m_InMsg.GetDopler( &dopler ) )
  310. {
  311. // m_pApplication->GetTargetQueue()->PostEvent( 'q', alarm.dPan, -1, 0, NULL, 0 );
  312. }
  313. }
  314. break;
  315. case CLgDeviceLGS::EVT_GET_DOPLER:
  316. {
  317. m_bCameraReady = TRUE;
  318. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_DOPLER" );
  319. CLgDeviceLGS::DOPLER dopler;
  320. if( m_InMsg.GetDopler( &dopler ) )
  321. {
  322. }
  323. }
  324. break;
  325. case CLgDeviceLGS::EVT_GET_DOPLER_MASK:
  326. {
  327. m_bCameraReady = TRUE;
  328. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_GET_DOPLER_MASK" );
  329. CLgDeviceLGS::DOPLER_MASK_ARRAY mask;
  330. if( m_InMsg.GetDoplerMask( &mask ) )
  331. {
  332. }
  333. }
  334. break;
  335. case CLgDeviceLGS::EVT_SET_DOPLER_MASK:
  336. {
  337. m_bCameraReady = TRUE;
  338. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_SET_DOPLER" );
  339. CLgDeviceLGS::DOPLER_MASK_ARRAY dopler_mask;
  340. if( m_InMsg.GetDoplerMask( &dopler_mask ) )
  341. {
  342. }
  343. }
  344. break;
  345. case CLgDeviceLGS::EVT_CONNECTION:
  346. {
  347. BOOL bConnected = FALSE;
  348. if( m_InMsg.GetEvtConnection( &bConnected ) )
  349. m_pApplication->GetTargetQueue()->PostEvent( bConnected ? 'C' : 'c', 0, 0, 0, NULL, 0 );
  350. // notify about connection
  351. OnNotifyConnect( bConnected );
  352. }
  353. break;
  354. case CLgDeviceLGS::EVT_OPERATION_MODE:
  355. {
  356. CLgDeviceLGS::LGS_OPERATION_MODE eMode = CLgDeviceLGS::LGS_OM_UNKNOWN;
  357. if( !m_InMsg.GetEvtOperationMode( &eMode ) )
  358. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "m_InMsg.GetEvtOperationMode failed" );
  359. else
  360. {
  361. switch( eMode )
  362. {
  363. case CLgDeviceLGS::LGS_OM_STUDY:
  364. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_STUDY" );
  365. if( !m_pApplication->GetTargetQueue()->PostEvent( 'd', 0, 0, 0, NULL, 0 ) )
  366. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("CLgDevicePTZ::EVT_OPERATION_MODE m_pApplication->GetTargetQueue()->PostEvent failed") );
  367. break;
  368. case CLgDeviceLGS::LGS_OM_DETECTION:
  369. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_DETECTION" );
  370. if( !m_pApplication->GetTargetQueue()->PostEvent( 'D', 0, 0, 0, NULL, 0 ) )
  371. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("CLgDevicePTZ::EVT_OPERATION_MODE m_pApplication->GetTargetQueue()->PostEvent failed") );
  372. break;
  373. default:
  374. case CLgDeviceLGS::LGS_OM_UNKNOWN:
  375. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "CLgDevicePTZ::EVT_OPERATION_MODE CLgDeviceLGS::LGS_OM_UNKNOWN" );
  376. break;
  377. }
  378. }
  379. }
  380. break;
  381. case CLgDeviceLGS::EVT_VOLTAGE:
  382. {
  383. BOOL bPowered = FALSE;
  384. if( m_InMsg.GetEvtVoltage( &bPowered ) )
  385. m_pApplication->GetTargetQueue()->PostEvent( bPowered ? 'P' : 'p', 0, 0, 0, NULL, 0 );
  386. }
  387. break;
  388. case CLgDeviceLGS::EVT_ERROR:
  389. {
  390. CLgDeviceLGS::LGS_ERROR error;
  391. if( m_InMsg.GetEvtError( &error ) )
  392. m_pApplication->GetTargetQueue()->PostEvent( 'e', error.eErrorLevel, error.eErrorID, LGS::ER_SUNBIT, error.pErrorText, 0 );
  393. }
  394. break;
  395. case CLgDeviceLGS::EVT_COMMAND_ERROR:
  396. {
  397. CLgDevice::DEVICE_CMD_ERROR error;
  398. if( m_InMsg.GetEvtCommandError( &error ) )
  399. {
  400. // m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, error.pErrorText, 0 );
  401. OnNotifyCommandError( error.nCommand );
  402. }
  403. m_bCameraReady = TRUE;
  404. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgs::ThreadProc", "received CLgDevicePTZ::EVT_COMMAND_ERROR" );
  405. }
  406. break;
  407. case CLgDeviceLGS::EVT_COMMUNICATION_ERROR:
  408. if( m_bShowCommunicationErrors )
  409. {
  410. INT nCount;
  411. if( m_InMsg.GetEvtCommunicationError( &nCount ) )
  412. {
  413. m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "COMMUNICATION ERROR", 0 );
  414. }
  415. }
  416. break;
  417. case CLgDeviceLGS::EVT_GETFILE_RESULT:
  418. {
  419. BYTE bResult = 0;
  420. if( m_InMsg.GetGetFileResult( &bResult ) )
  421. {
  422. switch( bResult )
  423. {
  424. case CLgDeviceLGS::GET_FILE_ERROR_LGS:
  425. m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "ERROR DURING TRANSFER FILE", 0 );
  426. ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 0 );
  427. break;
  428. case CLgDeviceLGS::GET_FILE_ERROR_HOST:
  429. m_pApplication->GetTargetQueue()->PostEvent( 'e', 0, 0, 0, "ERROR DURING OPEN FILE", 0 );
  430. ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 0 );
  431. break;
  432. case CLgDeviceLGS::GET_FILE_SUCCESS:
  433. ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 0, 1 );
  434. break;
  435. }
  436. }
  437. // notify recipients about reset
  438. OnNotifyReset( TRUE, bCommand );
  439. }
  440. break;
  441. case CLgDeviceLGS::EVT_GETFILE_PROGRESS:
  442. {
  443. INT dProgress;
  444. if( m_InMsg.GetGetFileProgress( &dProgress ) )
  445. ::PostMessage( m_hSendFileWnd, WM_LGS_SENDFILE, 1, dProgress );
  446. }
  447. break;
  448. case CLgDeviceLGS::EVT_GET_CAMERA_PARAMETERS:
  449. {
  450. if( m_InMsg.GetCameraParameters( &m_CameraParameters ) )
  451. ::PostMessage( m_hGetCameraTypeWnd, WM_LGS_GET_CAMERA_PARAMETERS, 0, 0 );
  452. }
  453. break;
  454. case CLgDeviceLGS::EVT_SET_CAMERA_PARAMETERS:
  455. if( m_InMsg.GetCameraParameters( &m_CameraParameters ) )
  456. ::PostMessage( m_hSetCameraTypeWnd, WM_LGS_SET_CAMERA_PARAMETERS, 1, 0 );
  457. // notify recipients about reset
  458. OnNotifyReset( TRUE, bCommand );
  459. break;
  460. case CLgDeviceLGS::EVT_GET_RELAY_PARAMETERS:
  461. if( m_InMsg.GetRelayParameters( &m_RelayParameters ) )
  462. ::PostMessage( m_hGetRelayParametersWnd, WM_LGS_GET_RELAY_PARAMETERS, 0, 0 );
  463. break;
  464. case CLgDeviceLGS::EVT_SET_RELAY_PARAMETERS:
  465. if( m_InMsg.GetRelayParameters( &m_RelayParameters ) )
  466. ::PostMessage( m_hSetRelayParametersWnd, WM_LGS_SET_RELAY_PARAMETERS, 1, 0 );
  467. // notify recipients about reset
  468. OnNotifyReset( TRUE, bCommand );
  469. break;
  470. case CLgDeviceLGS::EVT_GET_VOLTAGE_PARAMETERS:
  471. if( m_InMsg.GetEvtGetVoltageParameters( &m_VoltageParameters ) )
  472. ::PostMessage( m_hGetVoltageParametersWnd, WM_LGS_GET_VOLTAGE_PARAMETERS, 0, 0 );
  473. break;
  474. case CLgDeviceLGS::EVT_SET_VOLTAGE_PARAMETERS:
  475. if( m_InMsg.GetEvtSetVoltageParameters( &m_VoltageParameters ) )
  476. ::PostMessage( m_hSetVoltageParametersWnd, WM_LGS_SET_VOLTAGE_PARAMETERS, 1, 0 );
  477. // notify recipients about reset
  478. OnNotifyReset( TRUE, bCommand );
  479. break;
  480. case CLgDeviceLGS::EVT_GET_LRF_DISABLE:
  481. if( m_InMsg.GetEvtGetLRFDisable( &m_LRFDisable ) )
  482. ::PostMessage( m_hGetLRFDisableWnd, WM_LGS_GET_LRF_DISABLE, 0, 0 );
  483. break;
  484. case CLgDeviceLGS::EVT_SET_LRF_DISABLE:
  485. if( m_InMsg.GetEvtSetLRFDisable( &m_LRFDisable ) )
  486. ::PostMessage( m_hSetLRFDisableWnd, WM_LGS_SET_LRF_DISABLE, 1, 0 );
  487. // notify recipients about reset
  488. OnNotifyReset( TRUE, bCommand );
  489. break;
  490. case CLgDeviceLGS::EVT_GET_WIDTH_TABLE:
  491. if( m_InMsg.GetWidthTable( &m_WidthTable ) )
  492. ::PostMessage( m_hGetWidthTableWnd, WM_LGS_GET_WIDTH_TABLE, 0, 0 );
  493. break;
  494. case CLgDeviceLGS::EVT_SET_WIDTH_TABLE:
  495. if( m_InMsg.GetWidthTable( &m_WidthTable ) )
  496. ::PostMessage( m_hSetWidthTableWnd, WM_LGS_SET_WIDTH_TABLE, 1, 0 );
  497. // notify recipients about reset
  498. OnNotifyReset( TRUE, bCommand );
  499. break;
  500. case CLgDeviceLGS::EVT_GET_ZOOM_TABLE:
  501. if( m_InMsg.GetZoomTable( &m_ZoomTable ) )
  502. ::PostMessage( m_hGetZoomTableWnd, WM_LGS_GET_ZOOM_TABLE, 0, 0 );
  503. break;
  504. case CLgDeviceLGS::EVT_SET_ZOOM_TABLE:
  505. if( m_InMsg.GetZoomTable( &m_ZoomTable ) )
  506. ::PostMessage( m_hSetZoomTableWnd, WM_LGS_SET_ZOOM_TABLE, 1, 0 );
  507. // notify recipients about reset
  508. OnNotifyReset( TRUE, bCommand );
  509. break;
  510. case CLgDeviceLGS::EVT_GET_TILT_TABLE:
  511. if( m_InMsg.GetTiltTable( &m_TiltTable ) )
  512. ::PostMessage( m_hGetTiltTableWnd, WM_LGS_GET_TILT_TABLE, 0, 0 );
  513. break;
  514. case CLgDeviceLGS::EVT_SET_TILT_TABLE:
  515. if( m_InMsg.GetTiltTable( &m_TiltTable ) )
  516. ::PostMessage( m_hSetTiltTableWnd, WM_LGS_SET_TILT_TABLE, 1, 0 );
  517. // notify recipients about reset
  518. OnNotifyReset( TRUE, bCommand );
  519. break;
  520. case CLgDeviceLGS::EVT_GET_PARAMETERS:
  521. {
  522. CLgDeviceLGS::LGS_PARAMETERS_EX parameters;
  523. if( m_InMsg.GetEvtGetParameters( &parameters ) )
  524. {
  525. m_Parameters[parameters.bDevice] = parameters;
  526. if( m_hGetParametersWnd[parameters.bDevice] )
  527. {
  528. if( !::PostMessage( m_hGetParametersWnd[parameters.bDevice], WM_LGS_PARAMETERS, 0, parameters.bDevice ) )
  529. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,0,%d) failed"), m_hGetParametersWnd[parameters.bDevice], parameters.bDevice );
  530. else
  531. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,0,%d)"), m_hGetParametersWnd[parameters.bDevice], parameters.bDevice );
  532. }
  533. }
  534. }
  535. break;
  536. case CLgDeviceLGS::EVT_SET_PARAMETERS:
  537. {
  538. CLgDeviceLGS::LGS_PARAMETERS_EX parameters;
  539. if( m_InMsg.GetEvtSetParameters( &parameters ) )
  540. {
  541. m_Parameters[parameters.bDevice] = parameters;
  542. if( m_hSetParametersWnd[parameters.bDevice] )
  543. {
  544. if( !::PostMessage( m_hSetParametersWnd[parameters.bDevice], WM_LGS_PARAMETERS, 1, parameters.bDevice ) )
  545. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,1,%d) failed"), m_hSetParametersWnd[parameters.bDevice], parameters.bDevice );
  546. else
  547. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::ThreadProc"), _T("PostMessage(%p,WM_LGS_PARAMETERS,1,%d)"), m_hSetParametersWnd[parameters.bDevice], parameters.bDevice );
  548. }
  549. }
  550. // notify recipients about reset
  551. OnNotifyReset( TRUE, bCommand );
  552. }
  553. break;
  554. case CLgDeviceLGS::EVT_GET_SERIAL_NUMBER:
  555. if( m_InMsg.GetGetSerialNumber( &m_SerialNumber ) )
  556. ::PostMessage( m_hGetSerialNumberWnd, WM_LGS_SERIALNUMBER, 0, 0 );
  557. break;
  558. case CLgDeviceLGS::EVT_SET_SERIAL_NUMBER:
  559. if( m_InMsg.GetSetSerialNumber( &m_SerialNumber ) )
  560. ::PostMessage( m_hSetAddressWnd, WM_LGS_SERIALNUMBER, 1, 0 );
  561. // notify recipients about reset
  562. OnNotifyReset( TRUE, bCommand );
  563. break;
  564. case CLgDeviceLGS::EVT_SET_ADDRESS:
  565. if( m_InMsg.GetSetAddress( &m_Address ) )
  566. ::PostMessage( m_hSetAddressWnd, WM_LGS_SET_ADDRESS, 1, 0 );
  567. // notify recipients about reset
  568. OnNotifyReset( TRUE, bCommand );
  569. break;
  570. case CLgDeviceLGS::EVT_GET_HZ_DATA_PROGRESS:
  571. {
  572. INT nProgress;
  573. if( m_InMsg.GetEvtGetHzDataProgress( &nProgress ) )
  574. ::PostMessage( m_hGetHzDataWnd, WM_LGS_GET_HZ_DATA_PROGRESS, 0, nProgress );
  575. }
  576. break;
  577. case CLgDeviceLGS::EVT_GET_HZ_DATA:
  578. {
  579. if( m_InMsg.GetEvtGetHzData( m_GetHzArray ) )
  580. ::PostMessage( m_hGetHzDataWnd, WM_LGS_GET_HZ_DATA, 0, 0 );
  581. }
  582. break;
  583. case CLgDeviceLGS::EVT_GET_CALIBRATION_TABLE:
  584. case CLgDeviceLGS::EVT_SET_CALIBRATION_TABLE:
  585. GeneralTestFunction();
  586. break;
  587. case CLgDeviceLGS::EVT_SET_HZ_DATA:
  588. if( m_InMsg.GetEvtSetHzData( m_SetHzArray ) )
  589. ::PostMessage( m_hSetHzDataWnd, WM_LGS_SET_HZ_DATA, 1, 0 );
  590. // notify recipients about reset
  591. OnNotifyReset( TRUE, bCommand );
  592. break;
  593. case CLgDeviceLGS::EVT_SET_HZ_DATA_PROGRESS:
  594. {
  595. INT nProgress;
  596. if( m_InMsg.GetEvtSetHzDataProgress( &nProgress ) )
  597. ::PostMessage( m_hSetHzDataWnd, WM_LGS_SET_HZ_DATA_PROGRESS, 0, nProgress );
  598. }
  599. break;
  600. case CLgDeviceLGS::EVT_SET_COMM_BAUDRATE:
  601. {
  602. INT nBaudrate;
  603. if( m_InMsg.GetBaudrate( &nBaudrate ) )
  604. {
  605. m_nSetCommSpeed = nBaudrate;
  606. ::PostMessage(m_hSetCommSpeedWnd, WM_LGS_SET_COMM_SPEED, 1, m_nSetCommSpeed );
  607. SetBaudrate( m_nSetCommSpeed );
  608. }
  609. // notify recipients about reset
  610. OnNotifyReset( TRUE, bCommand );
  611. }
  612. break;
  613. case CLgDeviceLGS::EVT_GET_SOFTWARE_VERSION:
  614. if( m_InMsg.GetSoftwareVersion( &m_SoftwareVersion ) )
  615. ::PostMessage(m_hSoftwareVersionWnd, WM_LGS_SOFTWARE_VERSION, 0, 0);
  616. break;
  617. case CLgDeviceLGS::EVT_SEND_BOARDDATA:
  618. break;
  619. }
  620. }
  621. }
  622. }
  623. // __except( EXCEPTION_EXECUTE_HANDLER )
  624. __except( LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "FATAL ERROR: Exception in CLgs::ThreadProc" ), ::Sleep(1), EXCEPTION_CONTINUE_EXECUTION )
  625. {
  626. MessageBox( NULL, "FATAL ERROR: Exception in CLgs::ThreadProc", NULL, MB_OK );
  627. }
  628. return 0;
  629. }
  630. void CLgs::GeneralTestFunction()
  631. {
  632. return;
  633. CLgNetMessageLGS msg;
  634. CLgDeviceLGS::LGS_CALIBRATION_TABLE ct;
  635. ct.nDevice = 1;
  636. msg.SetDistinationID( m_Device.GetID() );
  637. msg.SetSenderID( m_Socket.GetID() );
  638. msg.BuildCmdSetCalibrationTable( ct );
  639. m_Device.SendMessageToChild( msg );
  640. }
  641. void CLgs::CmdResetLgs( HWND hWnd )
  642. {
  643. m_hResetWnd = hWnd;
  644. CLgNetMessageLGS msg;
  645. msg.SetDistinationID( m_Device.GetID() );
  646. msg.SetSenderID( m_Socket.GetID() );
  647. msg.BuildCmdReset();
  648. m_Device.SendMessageToChild( msg );
  649. // notify about reset
  650. BYTE bCommand;
  651. msg.GetCommand( &bCommand );
  652. OnNotifyReset( FALSE, bCommand );
  653. }
  654. void CLgs::CmdRestartLgs( HWND hWnd )
  655. {
  656. m_hRestartWnd = hWnd;
  657. CLgNetMessageLGS msg;
  658. msg.SetDistinationID( m_Device.GetID() );
  659. msg.SetSenderID( m_Socket.GetID() );
  660. msg.BuildCmdRestart();
  661. m_Device.SendMessageToChild( msg );
  662. // notify about reset
  663. BYTE bCommand;
  664. msg.GetCommand( &bCommand );
  665. OnNotifyReset( FALSE, bCommand );
  666. }
  667. void CLgs::CmdFullResetLgs(HWND hWnd)
  668. {
  669. m_hFullResetWnd = hWnd;
  670. CLgNetMessageLGS msg;
  671. msg.SetDistinationID( m_Device.GetID() );
  672. msg.SetSenderID( m_Socket.GetID() );
  673. msg.BuildCmdFullReset();
  674. m_Device.SendMessageToChild( msg );
  675. // notify about reset
  676. BYTE bCommand;
  677. msg.GetCommand( &bCommand );
  678. OnNotifyReset( FALSE, bCommand );
  679. }
  680. void CLgs::CmdDrawMap( HWND hWnd )
  681. {
  682. m_hDrawMapWnd = hWnd;
  683. CLgNetMessageLGS msg;
  684. msg.SetDistinationID( m_Device.GetID() );
  685. msg.SetSenderID( m_Socket.GetID() );
  686. msg.BuildCmdBorder();
  687. m_Device.SendMessageToChild( msg );
  688. }
  689. void CLgs::CmdDrawFullMap( HWND hWnd )
  690. {
  691. m_hDrawFullMapWnd = hWnd;
  692. CLgNetMessageLGS msg;
  693. msg.SetDistinationID( m_Device.GetID() );
  694. msg.SetSenderID( m_Socket.GetID() );
  695. msg.BuildCmdFullBorder();
  696. m_Device.SendMessageToChild( msg );
  697. }
  698. void CLgs::CmdSetParameters( HWND hWnd, CLgDeviceLGS::PLGS_PARAMETERS_EX pParameters )
  699. {
  700. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::CmdSetParameters"), _T("Wnd %p, Device %d"), hWnd, pParameters->bDevice );
  701. m_hSetParametersWnd[pParameters->bDevice] = hWnd;
  702. CLgNetMessageLGS msg;
  703. msg.SetDistinationID( m_Device.GetID() );
  704. msg.SetSenderID( m_Socket.GetID() );
  705. msg.BuildCmdSetParameters( pParameters );
  706. m_Device.SendMessageToChild( msg );
  707. // notify about reset
  708. BYTE bCommand;
  709. msg.GetCommand( &bCommand );
  710. OnNotifyReset( FALSE, bCommand );
  711. }
  712. void CLgs::CmdGetParameters( HWND hWnd, INT nDevice )
  713. {
  714. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgs::CmdGetParameters"), _T("Wnd %p, Device %d"), hWnd, nDevice );
  715. m_hGetParametersWnd[nDevice] = hWnd;
  716. CLgNetMessageLGS msg;
  717. msg.SetDistinationID( m_Device.GetID() );
  718. msg.SetSenderID( m_Socket.GetID() );
  719. msg.BuildCmdGetParameters( nDevice );
  720. m_Device.SendMessageToChild( msg );
  721. }
  722. void CLgs::CmdSendFile( HWND hWnd, LPCTSTR pSrcFileName, LPCTSTR pDstFileName )
  723. {
  724. m_hSendFileWnd = hWnd;
  725. CLgNetMessageLGS msg;
  726. msg.SetDistinationID( m_Device.GetID() );
  727. msg.SetSenderID( m_Socket.GetID() );
  728. msg.BuildCmdGetFile( pSrcFileName, pDstFileName );
  729. m_Device.SendMessageToChild( msg );
  730. // notify about reset
  731. BYTE bCommand;
  732. msg.GetCommand( &bCommand );
  733. OnNotifyReset( FALSE, bCommand );
  734. }
  735. void CLgs::CmdSetAddress( HWND hWnd, CLgDeviceLGS::LGS_SERIAL_NUMBER *pAddress )
  736. {
  737. m_hSetAddressWnd = hWnd;
  738. CLgNetMessageLGS msg;
  739. msg.SetDistinationID( m_Device.GetID() );
  740. msg.SetSenderID( m_Socket.GetID() );
  741. msg.BuildCmdSetAddress( pAddress->bAddress, pAddress->pSerialNumber, pAddress->bSize );
  742. m_Device.SendMessageToChild( msg );
  743. // notify about reset
  744. BYTE bCommand;
  745. msg.GetCommand( &bCommand );
  746. OnNotifyReset( FALSE, bCommand );
  747. }
  748. void CLgs::CmdGetSerialNumber( HWND hWnd )
  749. {
  750. m_hGetSerialNumberWnd = hWnd;
  751. CLgNetMessageLGS msg;
  752. msg.SetDistinationID( m_Device.GetID() );
  753. msg.SetSenderID( m_Socket.GetID() );
  754. msg.BuildCmdGetSerialNumber( m_Device.GetAddressLGS() );
  755. m_Device.SendMessageToChild( msg );
  756. }
  757. void CLgs::CmdGetSoftwareVersion( HWND hWnd )
  758. {
  759. m_hSoftwareVersionWnd = hWnd;
  760. CLgNetMessageLGS msg;
  761. msg.SetDistinationID( m_Device.GetID() );
  762. msg.SetSenderID( m_Socket.GetID() );
  763. msg.BuildCmdGetSoftwareVersion();
  764. m_Device.SendMessageToChild( msg );
  765. }
  766. void CLgs::CmdSetCommSpeed( HWND hWnd, LONG nSpeed )
  767. {
  768. m_hSetCommSpeedWnd = hWnd;
  769. CLgNetMessageLGS msg;
  770. msg.SetDistinationID( m_Device.GetID() );
  771. msg.SetSenderID( m_Socket.GetID() );
  772. msg.BuildCmdSetCommBaudrate( nSpeed );
  773. m_Device.SendMessageToChild( msg );
  774. // notify about reset
  775. BYTE bCommand;
  776. msg.GetCommand( &bCommand );
  777. OnNotifyReset( FALSE, bCommand );
  778. }
  779. ////////////////////////////////////////////////////////////////////////////////////////////////
  780. void CLgs::CmdGetCameraParameters( HWND hWnd )
  781. {
  782. m_hGetCameraTypeWnd = hWnd;
  783. CLgNetMessageLGS msg;
  784. msg.SetDistinationID( m_Device.GetID() );
  785. msg.SetSenderID( m_Socket.GetID() );
  786. msg.BuildCmdGetCameraParameters();
  787. m_Device.SendMessageToChild( msg );
  788. }
  789. void CLgs::CmdSetCameraParameters( HWND hWnd, LGS::PCAMERA_PARAMETERS pParameters )
  790. {
  791. m_hSetCameraTypeWnd = hWnd;
  792. CLgNetMessageLGS msg;
  793. msg.SetDistinationID( m_Device.GetID() );
  794. msg.SetSenderID( m_Socket.GetID() );
  795. msg.BuildCmdSetCameraParameters( pParameters );
  796. m_Device.SendMessageToChild( msg );
  797. // notify about reset
  798. BYTE bCommand;
  799. msg.GetCommand( &bCommand );
  800. OnNotifyReset( FALSE, bCommand );
  801. }
  802. void CLgs::CmdGetRelayParameters( HWND hWnd )
  803. {
  804. m_hGetRelayParametersWnd = hWnd;
  805. CLgNetMessageLGS msg;
  806. msg.SetDistinationID( m_Device.GetID() );
  807. msg.SetSenderID( m_Socket.GetID() );
  808. msg.BuildCmdGetRelayParameters();
  809. m_Device.SendMessageToChild( msg );
  810. }
  811. void CLgs::CmdSetRelayParameters( HWND hWnd, LGS::PRELAY_PARAMETERS pParameters )
  812. {
  813. m_hSetRelayParametersWnd = hWnd;
  814. CLgNetMessageLGS msg;
  815. msg.SetDistinationID( m_Device.GetID() );
  816. msg.SetSenderID( m_Socket.GetID() );
  817. msg.BuildCmdSetRelayParameters( pParameters );
  818. m_Device.SendMessageToChild( msg );
  819. // notify about reset
  820. BYTE bCommand;
  821. msg.GetCommand( &bCommand );
  822. OnNotifyReset( FALSE, bCommand );
  823. }
  824. void CLgs::CmdGetWidthTable( HWND hWnd )
  825. {
  826. m_hGetWidthTableWnd = hWnd;
  827. CLgNetMessageLGS msg;
  828. msg.SetDistinationID( m_Device.GetID() );
  829. msg.SetSenderID( m_Socket.GetID() );
  830. msg.BuildCmdGetWidthTable();
  831. m_Device.SendMessageToChild( msg );
  832. }
  833. void CLgs::CmdSetWidthTable( HWND hWnd, LGS::PWIDTH_TABLE pTable )
  834. {
  835. m_hSetWidthTableWnd = hWnd;
  836. CLgNetMessageLGS msg;
  837. msg.SetDistinationID( m_Device.GetID() );
  838. msg.SetSenderID( m_Socket.GetID() );
  839. msg.BuildCmdSetWidthTable( pTable );
  840. m_Device.SendMessageToChild( msg );
  841. // notify about reset
  842. BYTE bCommand;
  843. msg.GetCommand( &bCommand );
  844. OnNotifyReset( FALSE, bCommand );
  845. }
  846. void CLgs::CmdGetZoomTable( HWND hWnd )
  847. {
  848. m_hGetZoomTableWnd = hWnd;
  849. CLgNetMessageLGS msg;
  850. msg.SetDistinationID( m_Device.GetID() );
  851. msg.SetSenderID( m_Socket.GetID() );
  852. msg.BuildCmdGetZoomTable();
  853. m_Device.SendMessageToChild( msg );
  854. }
  855. void CLgs::CmdSetZoomTable( HWND hWnd, LGS::PZOOM_TABLE pTable )
  856. {
  857. m_hSetZoomTableWnd = hWnd;
  858. CLgNetMessageLGS msg;
  859. msg.SetDistinationID( m_Device.GetID() );
  860. msg.SetSenderID( m_Socket.GetID() );
  861. msg.BuildCmdSetZoomTable( pTable );
  862. m_Device.SendMessageToChild( msg );
  863. // notify about reset
  864. BYTE bCommand;
  865. msg.GetCommand( &bCommand );
  866. OnNotifyReset( FALSE, bCommand );
  867. }
  868. void CLgs::CmdGetTiltTable( HWND hWnd )
  869. {
  870. m_hGetTiltTableWnd = hWnd;
  871. CLgNetMessageLGS msg;
  872. msg.SetDistinationID( m_Device.GetID() );
  873. msg.SetSenderID( m_Socket.GetID() );
  874. msg.BuildCmdGetTiltTable();
  875. m_Device.SendMessageToChild( msg );
  876. }
  877. void CLgs::CmdSetTiltTable( HWND hWnd, LGS::PTILT_TABLE pTable )
  878. {
  879. m_hSetTiltTableWnd = hWnd;
  880. CLgNetMessageLGS msg;
  881. msg.SetDistinationID( m_Device.GetID() );
  882. msg.SetSenderID( m_Socket.GetID() );
  883. msg.BuildCmdSetTiltTable( pTable );
  884. m_Device.SendMessageToChild( msg );
  885. // notify about reset
  886. BYTE bCommand;
  887. msg.GetCommand( &bCommand );
  888. OnNotifyReset( FALSE, bCommand );
  889. }
  890. void CLgs::CmdGetVoltageParameters( HWND hWnd )
  891. {
  892. m_hGetVoltageParametersWnd = hWnd;
  893. CLgNetMessageLGS msg;
  894. msg.SetDistinationID( m_Device.GetID() );
  895. msg.SetSenderID( m_Socket.GetID() );
  896. msg.BuildCmdGetVoltageParameters();
  897. m_Device.SendMessageToChild( msg );
  898. }
  899. void CLgs::CmdSetVoltageParameters( HWND hWnd, LGS::PVOLTAGE_PARAMETERS pParameters )
  900. {
  901. m_hSetVoltageParametersWnd = hWnd;
  902. CLgNetMessageLGS msg;
  903. msg.SetDistinationID( m_Device.GetID() );
  904. msg.SetSenderID( m_Socket.GetID() );
  905. msg.BuildCmdSetVoltageParameters( pParameters );
  906. m_Device.SendMessageToChild( msg );
  907. // notify about reset
  908. BYTE bCommand;
  909. msg.GetCommand( &bCommand );
  910. OnNotifyReset( FALSE, bCommand );
  911. }
  912. void CLgs::CmdGetLRFDisable( HWND hWnd )
  913. {
  914. m_hGetLRFDisableWnd = hWnd;
  915. CLgNetMessageLGS msg;
  916. msg.SetDistinationID( m_Device.GetID() );
  917. msg.SetSenderID( m_Socket.GetID() );
  918. msg.BuildCmdGetLRFDisable();
  919. m_Device.SendMessageToChild( msg );
  920. }
  921. void CLgs::CmdSetLRFDisable( HWND hWnd, LGS::PLRF_DISABLE pParameters )
  922. {
  923. m_hSetLRFDisableWnd = hWnd;
  924. CLgNetMessageLGS msg;
  925. msg.SetDistinationID( m_Device.GetID() );
  926. msg.SetSenderID( m_Socket.GetID() );
  927. msg.BuildCmdSetLRFDisable( pParameters );
  928. m_Device.SendMessageToChild( msg );
  929. // notify about reset
  930. BYTE bCommand;
  931. msg.GetCommand( &bCommand );
  932. OnNotifyReset( FALSE, bCommand );
  933. }
  934. BOOL CLgs::CmdGetHzData( HWND hWnd, BOOL bRowInclude )
  935. {
  936. m_hGetHzDataWnd = hWnd;
  937. CLgNetMessageLGS msg;
  938. msg.SetDistinationID( m_Device.GetID() );
  939. msg.SetSenderID( m_Socket.GetID() );
  940. msg.BuildCmdGetHzData( bRowInclude );
  941. return m_Device.SendMessageToChild( msg );
  942. }
  943. BOOL CLgs::CmdSetHzData( HWND hWnd, CLgDeviceLGS::LGS_HZ_ARRAY& HzArray )
  944. {
  945. m_hSetHzDataWnd = hWnd;
  946. CLgNetMessageLGS msg;
  947. msg.SetDistinationID( m_Device.GetID() );
  948. msg.SetSenderID( m_Socket.GetID() );
  949. msg.BuildCmdSetHzData( HzArray );
  950. BOOL bResult = m_Device.SendMessageToChild( msg );
  951. // notify about reset
  952. BYTE bCommand;
  953. msg.GetCommand( &bCommand );
  954. OnNotifyReset( FALSE, bCommand );
  955. return bResult;
  956. }
  957. /////////////////////////////////////////////////////////////////////////////////////////////////
  958. // auxilarity subroutines
  959. /////////////////////////////////////////////////////////////////////////////////////////////////
  960. void CLgs::OnFinishDraw()
  961. {
  962. typedef struct
  963. {
  964. double dAngle[2];
  965. double dRange[2];
  966. int bExist[2];
  967. }BORDER, *PBORDER;
  968. HANDLE hFile = ::CreateFile( "DrawMap.dat", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  969. if( hFile )
  970. {
  971. DWORD dwNumberOfBytesWritten;
  972. DWORD dwNumberOfStructs = LGS_MAX_BORDER_ANGLES;
  973. ::WriteFile( hFile, &dwNumberOfStructs, sizeof( dwNumberOfStructs ), &dwNumberOfBytesWritten, NULL );
  974. for( int i = 0; i < dwNumberOfStructs; i++ )
  975. {
  976. BORDER border;
  977. border.bExist[0] = border.bExist[1] = TRUE;
  978. border.dAngle[0] = border.dAngle[1] = i;
  979. border.dRange[0] = m_Border.pMaster[i];
  980. border.dRange[1] = m_Border.pSlave[i];
  981. ::WriteFile( hFile, &border, sizeof( border ), &dwNumberOfBytesWritten, NULL );
  982. }
  983. ::CloseHandle( hFile );
  984. }
  985. }
  986. BOOL CLgs::SetBaudrate( INT nSpeed )
  987. {
  988. return m_Socket.SetBaudrate( nSpeed );
  989. }
  990. /////////////////////////////////////////////////////////////////////////////////////////////////
  991. // camera commands
  992. /////////////////////////////////////////////////////////////////////////////////////////////////
  993. BOOL CLgs::IsCameraReady()
  994. {
  995. return m_bCameraReady;
  996. }
  997. BOOL CLgs::CmdCameraPan( BOOL bRight, double dSpeed )
  998. {
  999. if( !IsCameraReady() )
  1000. return FALSE;
  1001. m_bCameraReady = FALSE;
  1002. CLgNetMessagePTZ msg;
  1003. msg.SetDistinationID( m_Device.GetID() );
  1004. msg.SetSenderID( m_Socket.GetID() );
  1005. msg.BuildCmdMovePan( bRight, dSpeed );
  1006. m_Device.SendMessageToChild( msg );
  1007. return TRUE;
  1008. }
  1009. BOOL CLgs::CmdCameraTilt( BOOL bUp, double dSpeed )
  1010. {
  1011. if( !IsCameraReady() )
  1012. return FALSE;
  1013. m_bCameraReady = FALSE;
  1014. CLgNetMessagePTZ msg;
  1015. msg.SetDistinationID( m_Device.GetID() );
  1016. msg.SetSenderID( m_Socket.GetID() );
  1017. msg.BuildCmdMoveTilt( bUp, dSpeed );
  1018. m_Device.SendMessageToChild( msg );
  1019. return TRUE;
  1020. }
  1021. BOOL CLgs::CmdCameraZoom( BOOL bTele, double dSpeed )
  1022. {
  1023. if( !IsCameraReady() )
  1024. return FALSE;
  1025. m_bCameraReady = FALSE;
  1026. CLgNetMessagePTZ msg;
  1027. msg.SetDistinationID( m_Device.GetID() );
  1028. msg.SetSenderID( m_Socket.GetID() );
  1029. msg.BuildCmdMoveZoom( bTele, dSpeed );
  1030. m_Device.SendMessageToChild( msg );
  1031. return TRUE;
  1032. }
  1033. BOOL CLgs::CmdCameraFocus( BOOL bFar, double dSpeed )
  1034. {
  1035. if( !IsCameraReady() )
  1036. return FALSE;
  1037. m_bCameraReady = FALSE;
  1038. CLgNetMessagePTZ msg;
  1039. msg.SetDistinationID( m_Device.GetID() );
  1040. msg.SetSenderID( m_Socket.GetID() );
  1041. msg.BuildCmdMoveFocus( bFar, dSpeed );
  1042. m_Device.SendMessageToChild( msg );
  1043. return TRUE;
  1044. }
  1045. BOOL CLgs::CmdCameraIris( double iris )
  1046. {
  1047. if( !IsCameraReady() )
  1048. return FALSE;
  1049. m_bCameraReady = FALSE;
  1050. CLgNetMessagePTZ msg;
  1051. msg.SetDistinationID( m_Device.GetID() );
  1052. msg.SetSenderID( m_Socket.GetID() );
  1053. msg.BuildCmdSetIris( iris );
  1054. m_Device.SendMessageToChild( msg );
  1055. return TRUE;
  1056. }
  1057. BOOL CLgs::CmdCameraGotoPosition( double pan, double tilt, double zoom, double focus )
  1058. {
  1059. if( !IsCameraReady() )
  1060. return FALSE;
  1061. m_bCameraReady = FALSE;
  1062. CLgNetMessagePTZ msg;
  1063. msg.SetDistinationID( m_Device.GetID() );
  1064. msg.SetSenderID( m_Socket.GetID() );
  1065. msg.BuildCmdSetPTZ( pan, tilt, zoom );
  1066. m_Device.SendMessageToChild( msg );
  1067. msg.BuildCmdSetFocus( focus );
  1068. m_Device.SendMessageToChild( msg );
  1069. return TRUE;
  1070. }
  1071. BOOL CLgs::CmdCameraGetPosition()
  1072. {
  1073. if( !IsCameraReady() )
  1074. return FALSE;
  1075. m_bCameraReady = FALSE;
  1076. CLgNetMessagePTZ msg;
  1077. msg.SetDistinationID( m_Device.GetID() );
  1078. msg.SetSenderID( m_Socket.GetID() );
  1079. msg.BuildCmdGetFocus();
  1080. m_Device.SendMessageToChild( msg );
  1081. msg.BuildCmdGetPTZ();
  1082. m_Device.SendMessageToChild( msg );
  1083. return TRUE;
  1084. }
  1085. BOOL CLgs::CmdCameraDoplerOn( BOOL bOn, INT nDegree, DWORD dwTimeout )
  1086. {
  1087. if( !IsCameraReady() )
  1088. return FALSE;
  1089. m_bCameraReady = FALSE;
  1090. CLgNetMessageDopler msg;
  1091. msg.SetDistinationID( m_Device.GetID() );
  1092. msg.SetSenderID( m_Socket.GetID() );
  1093. msg.BuildCmdSetDopler( bOn, nDegree, dwTimeout );
  1094. m_Device.SendMessageToChild( msg );
  1095. return TRUE;
  1096. }
  1097. BOOL CLgs::CmdCameraSetDoplerMask( CLgDeviceDopler::PDOPLER_MASK_ARRAY pMask )
  1098. {
  1099. if( !IsCameraReady() )
  1100. return FALSE;
  1101. m_bCameraReady = FALSE;
  1102. CLgNetMessageDopler msg;
  1103. msg.SetDistinationID( m_Device.GetID() );
  1104. msg.SetSenderID( m_Socket.GetID() );
  1105. msg.BuildCmdSetDoplerMask( pMask );
  1106. m_Device.SendMessageToChild( msg );
  1107. return TRUE;
  1108. }
  1109. BOOL CLgs::CmdCameraGetDoplerMask()
  1110. {
  1111. if( !IsCameraReady() )
  1112. return FALSE;
  1113. m_bCameraReady = FALSE;
  1114. CLgNetMessageDopler msg;
  1115. msg.SetDistinationID( m_Device.GetID() );
  1116. msg.SetSenderID( m_Socket.GetID() );
  1117. msg.BuildCmdGetDoplerMask();
  1118. m_Device.SendMessageToChild( msg );
  1119. return TRUE;
  1120. }
  1121. BOOL CLgs::CmdCameraWiperOn( BOOL bOn )
  1122. {
  1123. if( !IsCameraReady() )
  1124. return FALSE;
  1125. m_bCameraReady = FALSE;
  1126. CLgNetMessagePTZ msg;
  1127. msg.SetDistinationID( m_Device.GetID() );
  1128. msg.SetSenderID( m_Socket.GetID() );
  1129. msg.BuildCmdWiper( bOn );
  1130. m_Device.SendMessageToChild( msg );
  1131. return TRUE;
  1132. }
  1133. BOOL CLgs::GetCameraPosition( CLgDevicePTZ::PTZ_DEGREE *pPan, CLgDevicePTZ::PTZ_DEGREE *pTilt, CLgDevicePTZ::PTZ_PERCENT *pZoom, CLgDevicePTZ::PTZ_PERCENT *pFocus )
  1134. {
  1135. if( !IsCameraReady() )
  1136. return FALSE;
  1137. if( pPan ) *pPan = m_CameraPosition.dPan;
  1138. if( pTilt ) *pTilt = m_CameraPosition.dTilt;
  1139. if( pZoom ) *pZoom = m_CameraPosition.dZoom;
  1140. if( pFocus ) *pFocus = m_CameraFocus;
  1141. return TRUE;
  1142. }
  1143. BOOL CLgs::RegisterNotify( INT eType, HWND hWnd )
  1144. {
  1145. CLgLocker Lock( &m_NotifyArray );
  1146. for( INT i = 0; i < m_NotifyArray.GetCount(); i++ )
  1147. {
  1148. if( m_NotifyArray[i].hWnd == hWnd )
  1149. {
  1150. m_NotifyArray[i].eType = m_NotifyArray[i].eType || eType;
  1151. return TRUE;
  1152. }
  1153. }
  1154. NOTIFY_RECIPIENT nr;
  1155. nr.eType = eType;
  1156. nr.hWnd = hWnd;
  1157. return m_NotifyArray.Add( nr );
  1158. }
  1159. void CLgs::OnNotifyConnect( BOOL bConnected )
  1160. {
  1161. CLgLocker Lock( &m_NotifyArray );
  1162. for( INT i = 0; i < m_NotifyArray.GetCount(); )
  1163. {
  1164. // garbage collection
  1165. if( !::IsWindow( m_NotifyArray[i].hWnd ) )
  1166. {
  1167. m_NotifyArray.Remove(i);
  1168. continue;
  1169. }
  1170. // send notification
  1171. if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_CONNECT ) == NOTIFY_TYPE_CONNECT )
  1172. ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_CONNECT, bConnected, 0 );
  1173. // get next
  1174. i++;
  1175. }
  1176. }
  1177. void CLgs::OnNotifyReset( BOOL bFinished, INT nResetCommand )
  1178. {
  1179. CLgLocker Lock( &m_NotifyArray );
  1180. for( INT i = 0; i < m_NotifyArray.GetCount(); )
  1181. {
  1182. // garbage collection
  1183. if( !::IsWindow( m_NotifyArray[i].hWnd ) )
  1184. {
  1185. m_NotifyArray.Remove(i);
  1186. continue;
  1187. }
  1188. // send notification
  1189. if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_RESET ) == NOTIFY_TYPE_RESET )
  1190. ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_RESET, bFinished, nResetCommand );
  1191. // get next
  1192. i++;
  1193. }
  1194. }
  1195. void CLgs::OnNotifyCommandError( INT nCommand )
  1196. {
  1197. CLgLocker Lock( &m_NotifyArray );
  1198. for( INT i = 0; i < m_NotifyArray.GetCount(); )
  1199. {
  1200. // garbage collection
  1201. if( !::IsWindow( m_NotifyArray[i].hWnd ) )
  1202. {
  1203. m_NotifyArray.Remove(i);
  1204. continue;
  1205. }
  1206. // send notification
  1207. if( ( m_NotifyArray[i].eType & NOTIFY_TYPE_COMMAND_ERROR ) == NOTIFY_TYPE_COMMAND_ERROR )
  1208. ::PostMessage( m_NotifyArray[i].hWnd, WM_LGS_NOTIFY_COMMAND_ERROR, nCommand, 0 );
  1209. // get next
  1210. i++;
  1211. }
  1212. }