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.

192 lines
5.0 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: LgNetDevicePTZTKS576.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgNetDevicePTZTKS576.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include "LgNetDevicePTZTKS576.h"
  17. #include "LgNetSocketPTZTKS576.h"
  18. #define POSITION_QUALYTY 2
  19. #define MAX_NO_REPLY_COUNT 20
  20. #define MAX_NOT_IN_POSITION_COUNT 10
  21. CLgNetDevicePTZTKS576::CLgNetDevicePTZTKS576()
  22. {
  23. }
  24. CLgNetDevicePTZTKS576::~CLgNetDevicePTZTKS576()
  25. {
  26. // nessesary to do it, because "vtable" will be cleared before
  27. // parent's destructor will be called
  28. CLgLinkSP<CLgNetSocketDevice,CLgNetSocket>::Unlink();
  29. }
  30. void CLgNetDevicePTZTKS576::OnEvtGetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  31. {
  32. m_OutMsg.BuildEvtGetPTZ( dPan, dTilt, dZoom );
  33. SendMessageToParent( m_OutMsg );
  34. }
  35. void CLgNetDevicePTZTKS576::OnEvtSetPTZ( PTZ_DEGREE dPan, PTZ_DEGREE dTilt, PTZ_PERCENT dZoom )
  36. {
  37. m_OutMsg.BuildEvtSetPTZ( dPan, dTilt, dZoom );
  38. SendMessageToParent( m_OutMsg );
  39. }
  40. void CLgNetDevicePTZTKS576::OnEvtMoveTilt( BOOL bUp, PTZ_PERCENT dSpeed )
  41. {
  42. m_OutMsg.BuildEvtMoveTilt( bUp, dSpeed );
  43. SendMessageToParent( m_OutMsg );
  44. }
  45. void CLgNetDevicePTZTKS576::OnEvtMovePan( BOOL bRight, PTZ_PERCENT dSpeed )
  46. {
  47. m_OutMsg.BuildEvtMovePan( bRight, dSpeed );
  48. SendMessageToParent( m_OutMsg );
  49. }
  50. void CLgNetDevicePTZTKS576::OnEvtMoveZoom( BOOL bTele, PTZ_PERCENT dSpeed )
  51. {
  52. m_OutMsg.BuildEvtMoveZoom( bTele, dSpeed );
  53. SendMessageToParent( m_OutMsg );
  54. }
  55. void CLgNetDevicePTZTKS576::OnEvtMoveFocus( BOOL bFar, PTZ_PERCENT dSpeed )
  56. {
  57. m_OutMsg.BuildEvtMoveFocus( bFar, dSpeed );
  58. SendMessageToParent( m_OutMsg );
  59. }
  60. void CLgNetDevicePTZTKS576::OnEvtSetIris( PTZ_PERCENT dIris )
  61. {
  62. m_OutMsg.BuildEvtSetIris( dIris );
  63. SendMessageToParent( m_OutMsg );
  64. }
  65. void CLgNetDevicePTZTKS576::OnEvtSetFocus( PTZ_PERCENT dFocus )
  66. {
  67. m_OutMsg.BuildEvtSetFocus( dFocus );
  68. SendMessageToParent( m_OutMsg );
  69. }
  70. void CLgNetDevicePTZTKS576::OnEvtGetFocus( PTZ_PERCENT dFocus )
  71. {
  72. m_OutMsg.BuildEvtGetFocus( dFocus );
  73. SendMessageToParent( m_OutMsg );
  74. }
  75. void CLgNetDevicePTZTKS576::OnEvtInit()
  76. {
  77. m_OutMsg.BuildEvtInit();
  78. SendMessageToParent( m_OutMsg );
  79. }
  80. void CLgNetDevicePTZTKS576::OnEvtWiper( BOOL bOn )
  81. {
  82. m_OutMsg.BuildEvtWiper( bOn );
  83. SendMessageToParent( m_OutMsg );
  84. }
  85. void CLgNetDevicePTZTKS576::OnEvtCommandError( INT nCommand, LPCTSTR pFormat, ... )
  86. {
  87. va_list marker;
  88. va_start( marker, pFormat );
  89. m_OutMsg.BuildEvtCommandError( nCommand, pFormat, marker );
  90. va_end( marker );
  91. CLgNetObject::SendMessageToParent( m_OutMsg );
  92. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, "CLgNetDevicePTZTKS576::OnEvtCommandError" );
  93. }
  94. BOOL CLgNetDevicePTZTKS576::DeviceProc( CLgNetSocket *pSocket, CProtocol *pProtocol )
  95. {
  96. // cast to related protocol
  97. CProtocolPTZTKS576 *pProtocolPTZ = (CProtocolPTZTKS576*) pProtocol;
  98. // check input command
  99. if( CLgDevicePTZTKS576::IsReadyForCmd() && CLgNetObject::PopMessage( m_InMsg ) )
  100. {
  101. m_OutMsg.SetDistinationID( m_InMsg.GetSenderID() );
  102. m_OutMsg.SetSenderID( GetID() );
  103. // depend on command
  104. BYTE bCommand;
  105. if( m_InMsg.GetCommand( &bCommand ) )
  106. {
  107. PTZ_POSITION pos;
  108. PTZ_PAN pan;
  109. PTZ_TILT tilt;
  110. PTZ_ZOOM zoom;
  111. PTZ_PERCENT iris;
  112. PTZ_PERCENT focus;
  113. switch( bCommand )
  114. {
  115. case CLgDevicePTZTKS576::CMD_INIT:
  116. CmdInit();
  117. break;
  118. case CLgDevicePTZTKS576::CMD_GET_PTZ:
  119. CmdGetPTZ();
  120. break;
  121. case CLgDevicePTZTKS576::CMD_SET_PTZ:
  122. if( m_InMsg.GetPTZ( &pos ) )
  123. CmdSetPTZ( pos.dPan, pos.dTilt, pos.dZoom );
  124. break;
  125. case CLgDevicePTZTKS576::CMD_MOVE_TILT:
  126. if( m_InMsg.GetTilt( &tilt ) )
  127. CmdMoveTilt( tilt.bUp, tilt.dSpeed );
  128. break;
  129. case CLgDevicePTZTKS576::CMD_MOVE_PAN:
  130. if( m_InMsg.GetPan( &pan ) )
  131. CmdMovePan( pan.bRight, pan.dSpeed );
  132. break;
  133. case CLgDevicePTZTKS576::CMD_MOVE_ZOOM:
  134. if( m_InMsg.GetZoom( &zoom ) )
  135. CmdMoveZoom( zoom.bTele, zoom.dSpeed );
  136. break;
  137. case CLgDevicePTZTKS576::CMD_SET_IRIS:
  138. if( m_InMsg.GetIris( &iris ) )
  139. CmdSetIris( iris );
  140. break;
  141. case CLgDevicePTZTKS576::CMD_SET_FOCUS:
  142. if( m_InMsg.GetFocus( &focus ) )
  143. CmdSetFocus( focus );
  144. break;
  145. case CLgDevicePTZTKS576::CMD_GET_FOCUS:
  146. CmdGetFocus();
  147. break;
  148. // case CLgDevicePTZTKS576::CMD_INIT:
  149. // CmdInit();
  150. // break;
  151. default:
  152. OnEvtCommandError( -1, _T("UNKNOWN COMMAND") );
  153. break;
  154. }
  155. }
  156. }
  157. // write command
  158. LONG lTimeout = 0L;
  159. BOOL bRead = WriteProc( pProtocolPTZ, &lTimeout );
  160. // read responce if nessessary
  161. if( bRead )
  162. bRead = ReadProc( pProtocolPTZ, lTimeout, TRUE );
  163. else
  164. {
  165. bRead = TRUE;
  166. ::Sleep( lTimeout );
  167. }
  168. return bRead;
  169. }