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.

216 lines
5.9 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: 13/04/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgNetDevicePTZ.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDevicePTZ.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include "LgNetDevicePTZ.h"
  17. #include "LgNetSocketPTZ.h"
  18. CLgNetDevicePTZ::CLgNetDevicePTZ()
  19. {
  20. }
  21. CLgNetDevicePTZ::~CLgNetDevicePTZ()
  22. {
  23. // nessesary to do it, because "vtable" will be cleared before
  24. // parent's destructor will be called
  25. CLgNetSocketDevice::DetachSocket();
  26. }
  27. BOOL CLgNetDevicePTZ::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
  28. {
  29. // cast to related socket type
  30. CLgNetSocketPTZ *pSocketPTZ = (CLgNetSocketPTZ*)pSocket;
  31. CLgDevicePTZ *pDevicePTZ = NULL;
  32. switch( pSocketPTZ->GetType() )
  33. {
  34. case CLgNetSocketPTZ::NET_SOCKET_PTZ_PG3AD: pDevicePTZ = (CLgDevicePTZ*)(CLgDevicePTZPG3AD*)this; break;
  35. case CLgNetSocketPTZ::NET_SOCKET_PTZ_TKS576: pDevicePTZ = (CLgDevicePTZ*)(CLgDevicePTZTKS576*)this; break;
  36. case CLgNetSocketPTZ::NET_SOCKET_PTZ_MIGVAN: pDevicePTZ = (CLgDevicePTZ*)(CLgDevicePTZMigvan*)this; break;
  37. case CLgNetSocketPTZ::NET_SOCKET_PTZ_MIC1300: pDevicePTZ = (CLgDevicePTZ*)(CLgDevicePTZMic1300*)this; break;
  38. }
  39. // check input command
  40. if( pDevicePTZ->IsReadyForCmd() && CLgNetObject::PopMessage( m_InMsg ) )
  41. {
  42. m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
  43. m_OutMsg.SetSenderID( GetID() );
  44. // depend on command
  45. BYTE bCommand;
  46. if( m_InMsg.GetCommand( &bCommand ) )
  47. {
  48. PTZ_POSITION pos;
  49. PTZ_PAN pan;
  50. PTZ_TILT tilt;
  51. PTZ_ZOOM zoom;
  52. PTZ_SERIAL_NUMBER sn;
  53. PTZ_PERCENT iris;
  54. PTZ_PERCENT focus;
  55. BYTE address;
  56. switch( bCommand )
  57. {
  58. // common messages
  59. case CLgNetMessagePTZ::CMD_GET_POSITION:
  60. pDevicePTZ->CmdGetPosition();
  61. break;
  62. case CLgNetMessagePTZ::CMD_GOTO_POSITION:
  63. if( m_InMsg.GetPosition( &pos ) )
  64. pDevicePTZ->CmdGotoPosition( pos.dPan, pos.dTilt, pos.dZoom );
  65. break;
  66. case CLgNetMessagePTZ::CMD_TILT:
  67. if( m_InMsg.GetTilt( &tilt ) )
  68. pDevicePTZ->CmdTilt( tilt.bUp, tilt.dSpeed );
  69. break;
  70. case CLgNetMessagePTZ::CMD_PAN:
  71. if( m_InMsg.GetPan( &pan ) )
  72. pDevicePTZ->CmdPan( pan.bRight, pan.dSpeed );
  73. break;
  74. case CLgNetMessagePTZ::CMD_ZOOM:
  75. if( m_InMsg.GetZoom( &zoom ) )
  76. pDevicePTZ->CmdZoom( zoom.bTele, zoom.dSpeed );
  77. break;
  78. case CLgNetMessagePTZ::CMD_IRIS:
  79. if( m_InMsg.GetIris( &iris ) )
  80. pDevicePTZ->CmdIris( iris );
  81. break;
  82. case CLgNetMessagePTZ::CMD_FOCUS:
  83. if( m_InMsg.GetFocus( &focus ) )
  84. pDevicePTZ->CmdFocus( focus );
  85. break;
  86. // migvan messages
  87. case CLgNetMessagePTZ::CMD_GET_SERIAL_NUMBER:
  88. CmdGetSerialNumber();
  89. break;
  90. case CLgNetMessagePTZ::CMD_AUTO_INIT:
  91. CmdAutoInit();
  92. break;
  93. case CLgNetMessagePTZ::CMD_WARM_BOOT:
  94. CmdWarmBoot();
  95. break;
  96. case CLgNetMessagePTZ::CMD_SET_ADDRESS:
  97. if( m_InMsg.GetSerialNumber( &sn ) )
  98. CLgDevicePTZMigvan::CmdSetAddress( sn.pSerialNumber, sn.bAddress );
  99. break;
  100. // mic1300
  101. case CLgNetMessagePTZ::CMD_INIT:
  102. CLgDevicePTZMic1300::CmdInit();
  103. break;
  104. case CLgNetMessagePTZ::CMD_SET_ADDRESS:
  105. if( m_InMsg.GetAddress( &address ) )
  106. CLgDevicePTZMic1300::CmdSetAddress( address );
  107. break;
  108. // tks576
  109. case CLgNetMessagePTZ::CMD_INIT:
  110. CLgDevicePTZTKS576::CmdInit();
  111. break;
  112. // common
  113. default:
  114. OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
  115. break;
  116. }
  117. }
  118. }
  119. // write command
  120. LONG lTimeout = 0L;
  121. BOOL bRead = pDevicePTZ->WriteProc( pProtocol, &lTimeout );
  122. // read responce if nessessary
  123. if( bRead )
  124. bRead = pDevicePTZ->ReadProc( pProtocol, lTimeout, TRUE );
  125. else
  126. {
  127. bRead = TRUE;
  128. ::Sleep( lTimeout );
  129. }
  130. return bRead;
  131. }
  132. void CLgNetDevicePTZ::OnEvtGetPosition( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  133. {
  134. m_OutMsg.BuildEvtGetPosition( dPan, dTilt, dZoom );
  135. SendMessageToParent( m_OutMsg );
  136. }
  137. void CLgNetDevicePTZ::OnEvtGotoPosition( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  138. {
  139. m_OutMsg.BuildEvtGotoPosition( dPan, dTilt, dZoom );
  140. SendMessageToParent( m_OutMsg );
  141. }
  142. void CLgNetDevicePTZ::OnEvtTilt( BOOL bUp, PTZ_PERCENT dSpeed )
  143. {
  144. m_OutMsg.BuildEvtTilt( bUp, dSpeed );
  145. SendMessageToParent( m_OutMsg );
  146. }
  147. void CLgNetDevicePTZ::OnEvtPan( BOOL bRight, PTZ_PERCENT dSpeed )
  148. {
  149. m_OutMsg.BuildEvtPan( bRight, dSpeed );
  150. SendMessageToParent( m_OutMsg );
  151. }
  152. void CLgNetDevicePTZ::OnEvtZoom( BOOL bTele, PTZ_PERCENT dSpeed )
  153. {
  154. m_OutMsg.BuildEvtZoom( bTele, dSpeed );
  155. SendMessageToParent( m_OutMsg );
  156. }
  157. void CLgNetDevicePTZ::OnEvtIris( PTZ_PERCENT dIris )
  158. {
  159. m_OutMsg.BuildEvtIris( dIris );
  160. SendMessageToParent( m_OutMsg );
  161. }
  162. void CLgNetDevicePTZ::OnEvtFocus( PTZ_PERCENT dFocus )
  163. {
  164. m_OutMsg.BuildEvtFocus( dFocus );
  165. SendMessageToParent( m_OutMsg );
  166. }
  167. void CLgNetDevicePTZ::OnEvtAutoInit( PBYTE pSerialNumber, BYTE bAddress )
  168. {
  169. m_InMsg.BuildEvtAutoInit( pSerialNumber, bAddress );
  170. SendMessageToParent( m_OutMsg );
  171. }
  172. void CLgNetDevicePTZ::OnEvtWarmBoot()
  173. {
  174. m_InMsg.BuildEvtWarmBoot();
  175. SendMessageToParent( m_OutMsg );
  176. }
  177. void CLgNetDevicePTZ::OnEvtGetSerialNumber( PBYTE pSerialNumber )
  178. {
  179. m_InMsg.BuildEvtGetSerialNumber( pSerialNumber );
  180. SendMessageToParent( m_OutMsg );
  181. }
  182. void CLgNetDevicePTZ::OnEvtSetAddress( BYTE bAddress, PBYTE pSerialNumber )
  183. {
  184. m_InMsg.BuildEvtSetAddress( bAddress, pSerialNumber );
  185. SendMessageToParent( m_OutMsg );
  186. }
  187. void CLgNetDevicePTZ::OnEvtWiper( BOOL bOn )
  188. {
  189. m_OutMsg.BuildEvtWiper( bOn );
  190. SendMessageToParent( m_OutMsg );
  191. }