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.

267 lines
7.4 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: LgNetDevicePTZHebron.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDevicePTZHebron.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgNetDevicePTZHebron.h"
  16. #include "LgNetDeviceMD.h"
  17. #include "LgNetSocketMD.h"
  18. CLgNetDevicePTZHebron::CLgNetDevicePTZHebron()
  19. {
  20. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::CLgNetDevicePTZHebron") );
  21. }
  22. CLgNetDevicePTZHebron::~CLgNetDevicePTZHebron()
  23. {
  24. // nessesary to do it, because "vtable" will be cleared before
  25. // parent's destructor will be called
  26. CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::Unlink();
  27. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::~CLgNetDevicePTZHebron") );
  28. }
  29. BOOL CLgNetDevicePTZHebron::Link( CLgLink<CLgNetObject,CLgNetObject,CLgNetObjectChild> *pLink )
  30. {
  31. if( !CLgNetDevice::Link( pLink ) )
  32. return FALSE;
  33. m_OutMsg.SetDistinationID( pLink->GetThis()->GetID() );
  34. return TRUE;
  35. }
  36. void CLgNetDevicePTZHebron::OnEvtGetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  37. {
  38. m_OutMsg.BuildEvtGetPTZ( dPan, dTilt, dZoom );
  39. SendMessageToParent( m_OutMsg );
  40. }
  41. void CLgNetDevicePTZHebron::OnEvtSetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  42. {
  43. m_OutMsg.BuildEvtSetPTZ( dPan, dTilt, dZoom );
  44. SendMessageToParent( m_OutMsg );
  45. }
  46. void CLgNetDevicePTZHebron::OnEvtMoveTilt( BOOL bUp, PTZ_PERCENT dSpeed )
  47. {
  48. m_OutMsg.BuildEvtMoveTilt( bUp, dSpeed );
  49. SendMessageToParent( m_OutMsg );
  50. }
  51. void CLgNetDevicePTZHebron::OnEvtMovePan( BOOL bRight, PTZ_PERCENT dSpeed )
  52. {
  53. m_OutMsg.BuildEvtMovePan( bRight, dSpeed );
  54. SendMessageToParent( m_OutMsg );
  55. }
  56. void CLgNetDevicePTZHebron::OnEvtMoveZoom( BOOL bTele, PTZ_PERCENT dSpeed )
  57. {
  58. m_OutMsg.BuildEvtMoveZoom( bTele, dSpeed );
  59. SendMessageToParent( m_OutMsg );
  60. }
  61. void CLgNetDevicePTZHebron::OnEvtMoveFocus( BOOL bFar, PTZ_PERCENT dSpeed )
  62. {
  63. m_OutMsg.BuildEvtMoveFocus( bFar, dSpeed );
  64. SendMessageToParent( m_OutMsg );
  65. }
  66. void CLgNetDevicePTZHebron::OnEvtSetIris( PTZ_PERCENT dIris )
  67. {
  68. m_OutMsg.BuildEvtSetIris( dIris );
  69. SendMessageToParent( m_OutMsg );
  70. }
  71. void CLgNetDevicePTZHebron::OnEvtSetFocus( PTZ_PERCENT dFocus )
  72. {
  73. m_OutMsg.BuildEvtSetFocus( dFocus );
  74. SendMessageToParent( m_OutMsg );
  75. }
  76. void CLgNetDevicePTZHebron::OnEvtGetFocus( PTZ_PERCENT dFocus )
  77. {
  78. m_OutMsg.BuildEvtGetFocus( dFocus );
  79. SendMessageToParent( m_OutMsg );
  80. }
  81. void CLgNetDevicePTZHebron::OnEvtWiper( BOOL bOn )
  82. {
  83. m_OutMsg.BuildEvtWiper( bOn );
  84. SendMessageToParent( m_OutMsg );
  85. }
  86. void CLgNetDevicePTZHebron::OnEvtInit()
  87. {
  88. m_OutMsg.BuildEvtInit();
  89. SendMessageToParent( m_OutMsg );
  90. }
  91. void CLgNetDevicePTZHebron::OnEvtSetDopler( BOOL bEnable, PTZ_DEGREE dPanStep, DWORD dwTimeout )
  92. {
  93. m_OutMsg.BuildEvtSetDopler( bEnable, dPanStep, dwTimeout );
  94. SendMessageToParent( m_OutMsg );
  95. }
  96. void CLgNetDevicePTZHebron::OnEvtGetDopler( BOOL bEnable, PTZ_DEGREE dPanStep, DWORD dwTimeout )
  97. {
  98. m_OutMsg.BuildEvtGetDopler( bEnable, dPanStep, dwTimeout );
  99. SendMessageToParent( m_OutMsg );
  100. }
  101. void CLgNetDevicePTZHebron::OnEvtDoplerAlarm( BOOL bAlarm, PTZ_DEGREE dPan )
  102. {
  103. m_OutMsg.BuildEvtDoplerAlarm( bAlarm, dPan );
  104. SendMessageToParent( m_OutMsg );
  105. }
  106. void CLgNetDevicePTZHebron::OnEvtSetDoplerMask( PDOPLER_MASK_ARRAY pMask )
  107. {
  108. m_OutMsg.BuildEvtSetDoplerMask( pMask);
  109. SendMessageToParent( m_OutMsg );
  110. }
  111. void CLgNetDevicePTZHebron::OnEvtGetDoplerMask( PDOPLER_MASK_ARRAY pMask )
  112. {
  113. m_OutMsg.BuildEvtGetDoplerMask( pMask);
  114. SendMessageToParent( m_OutMsg );
  115. }
  116. void CLgNetDevicePTZHebron::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
  117. {
  118. va_list marker;
  119. va_start( marker, pFormat );
  120. m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
  121. va_end( marker );
  122. CLgNetObject::SendMessageToParent( m_OutMsg );
  123. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDevicePTZHebron::OnEvtCommandError" );
  124. }
  125. BOOL CLgNetDevicePTZHebron::SetBaudrate( DWORD nBaudRate )
  126. {
  127. // protect link
  128. CLgLocker Lock( &CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::GetLock() );
  129. // if no socket it is an error!!!
  130. CLgNetSocketMD *pSocket = static_cast<CLgNetSocketMD*>(CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::GetLinkThis());
  131. if( !pSocket )
  132. return FALSE;
  133. return pSocket->SetBaudrate( nBaudRate );
  134. }
  135. BOOL CLgNetDevicePTZHebron::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
  136. {
  137. BOOL bResult = FALSE;
  138. __try
  139. {
  140. bResult = DeviceProc_( pSocket, pProtocol );
  141. }
  142. __except( EXCEPTION_EXECUTE_HANDLER )
  143. {
  144. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgNetDevicePTZHebron::DeviceProc"), _T("Exception 0x%08X"), _exception_code() );
  145. }
  146. return bResult;
  147. }
  148. BOOL CLgNetDevicePTZHebron::DeviceProc_( CLgNetSocket *pSocket, CProtocol *pProtocol )
  149. {
  150. // cast to related protocol
  151. CProtocolLGS *pProtocolLGS = (CProtocolLGS*) pProtocol;
  152. // check input command
  153. if( CLgDevicePTZHebron::IsReadyForCmd() && CLgNetObject::PopMessage( m_InMsg ) )
  154. {
  155. m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
  156. m_OutMsg.SetSenderID( GetID() );
  157. // depend on command
  158. BYTE bCommand;
  159. if( m_InMsg.GetCommand( &bCommand ) )
  160. {
  161. PTZ_POSITION pos;
  162. PTZ_PAN pan;
  163. PTZ_TILT tilt;
  164. PTZ_ZOOM zoom;
  165. PTZ_PERCENT iris;
  166. PTZ_PERCENT focus;
  167. DOPLER dopler;
  168. DOPLER_MASK_ARRAY mask;
  169. switch( bCommand )
  170. {
  171. case CLgDevicePTZHebron::CMD_GET_PTZ:
  172. CmdGetPTZ();
  173. break;
  174. case CLgDevicePTZHebron::CMD_SET_PTZ:
  175. if( m_InMsg.GetPTZ( &pos ) )
  176. CmdSetPTZ( pos.dPan, pos.dTilt, pos.dZoom );
  177. break;
  178. case CLgDevicePTZHebron::CMD_MOVE_TILT:
  179. if( m_InMsg.GetTilt( &tilt ) )
  180. CmdMoveTilt( tilt.bUp, tilt.dSpeed );
  181. break;
  182. case CLgDevicePTZHebron::CMD_MOVE_PAN:
  183. if( m_InMsg.GetPan( &pan ) )
  184. CmdMovePan( pan.bRight, pan.dSpeed );
  185. break;
  186. case CLgDevicePTZHebron::CMD_MOVE_ZOOM:
  187. if( m_InMsg.GetZoom( &zoom ) )
  188. CmdMoveZoom( zoom.bTele, zoom.dSpeed );
  189. break;
  190. case CLgDevicePTZHebron::CMD_SET_IRIS:
  191. if( m_InMsg.GetIris( &iris ) )
  192. CmdSetIris( iris );
  193. break;
  194. case CLgDevicePTZHebron::CMD_SET_FOCUS:
  195. if( m_InMsg.GetFocus( &focus ) )
  196. CmdSetFocus( focus );
  197. break;
  198. case CLgDevicePTZHebron::CMD_GET_FOCUS:
  199. CmdGetFocus();
  200. break;
  201. case CLgDevicePTZHebron::CMD_SET_DOPLER:
  202. if( m_InMsg.GetDopler( &dopler ) )
  203. CmdSetDopler( dopler.bEnable, dopler.dPanStep, dopler.dwTimeout );
  204. break;
  205. case CLgDevicePTZHebron::CMD_SET_DOPLER_MASK:
  206. if( m_InMsg.GetDoplerMask( &mask ) )
  207. CmdSetDoplerMask( &mask );
  208. break;
  209. case CLgDevicePTZHebron::CMD_GET_DOPLER_MASK:
  210. CmdGetDoplerMask();
  211. break;
  212. case CLgDevicePTZHebron::CMD_GET_DOPLER:
  213. CmdGetDopler();
  214. break;
  215. default:
  216. OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
  217. break;
  218. }
  219. }
  220. }
  221. // write command
  222. LONG lTimeout = 0L;
  223. BOOL bRead = WriteProc( pProtocolLGS, &lTimeout );
  224. // read responce if nessessary
  225. if( bRead )
  226. bRead = ReadProc( pProtocolLGS, lTimeout, TRUE );
  227. else
  228. {
  229. bRead = TRUE;
  230. ::Sleep( lTimeout );
  231. }
  232. return bRead;
  233. }