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.

262 lines
8.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: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: DNesher.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DNesher.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #ifdef __BORLANDC__
  16. #include "..\LgLib\Device\DNesher.h"
  17. #include "..\LgLib\Comm\lgsm.h"
  18. #else
  19. #include "DNesher.h"
  20. #include "..\Comm\lgsm.h"
  21. #endif
  22. #define TIMEOUT_BETWEEN_COMMANDS 500
  23. CLgDevicePTZNesher::CLgDevicePTZNesher()
  24. {
  25. m_nMode = CMD_GET_PTZ;
  26. m_RealPosition.dPan = 0;
  27. m_nTimeoutCommand = 100;
  28. m_nTimeoutAfterCommand = 500;
  29. m_nTimeoutEnterSwitch = 5000;
  30. m_nTimeoutInterSwitch = 5000;
  31. m_nSwitchMode = -1;
  32. m_bPause = FALSE;
  33. m_nSwitchEnterRemain = m_nTimeoutEnterSwitch;
  34. m_nSwitchInterRemain = m_nTimeoutInterSwitch;
  35. }
  36. CLgDevicePTZNesher::~CLgDevicePTZNesher()
  37. {
  38. }
  39. void CLgDevicePTZNesher::OnPerformCmd()
  40. {
  41. // ready for new message
  42. ReleaseCmd();
  43. // ready to process new message
  44. m_nMode = CMD_NONE;
  45. }
  46. BOOL CLgDevicePTZNesher::WriteProc( void *pProtocol, PLONG pTimeout )
  47. {
  48. // cast to protocol
  49. CProtocolPTZNesher *pProtocolPTZ = (CProtocolPTZNesher*)pProtocol;
  50. CConnection *pConnection = pProtocolPTZ->GetConnection();
  51. // after command timeout
  52. if( m_bPause )
  53. {
  54. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER PAUSE"), _T("") );
  55. *pTimeout = m_nTimeoutAfterCommand;
  56. m_bPause = FALSE;
  57. // do not read, just wait for timeout
  58. return FALSE;
  59. }
  60. // check input command
  61. if( m_nMode == CMD_NONE )
  62. {
  63. switch( GetCmd() )
  64. {
  65. case CMD_GET_PTZ:
  66. m_nMode = CMD_GET_PTZ;
  67. break;
  68. case CMD_SET_PTZ:
  69. // validate positions
  70. /*
  71. PTZ_NESHER::ValidatePan( m_Position.dPan );
  72. PTZ_NESHER::ValidateTilt( m_Position.dTilt );
  73. PTZ_NESHER::ValidateZoom( m_Position.dZoom );
  74. */
  75. m_nMode = CMD_SET_PTZ;
  76. break;
  77. case CMD_MOVE_PAN:
  78. m_nMode = CMD_MOVE_PAN;
  79. break;
  80. case CMD_NONE:
  81. // no new commands
  82. break;
  83. case CMD_SET_IRIS:
  84. case CMD_SET_FOCUS:
  85. case CMD_WIPER:
  86. default:
  87. //command unsupported
  88. OnPerformCmd();
  89. OnEvtCommandError( m_nMode, _T("UNSUPPORTED") );
  90. break;
  91. }
  92. }
  93. INT nRtsDtr;
  94. // fill packet depend on command
  95. switch( m_nMode )
  96. {
  97. case CMD_SET_PTZ:
  98. // validate postion
  99. if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 ) { nRtsDtr = 0x00; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  100. else if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 ) { nRtsDtr = 0x01; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  101. else if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 ) { nRtsDtr = 0x02; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  102. else { nRtsDtr = 0x03; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 0 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  103. pConnection->SetRTS( nRtsDtr & 0x01 );
  104. pConnection->SetDTR( nRtsDtr & 0x02 );
  105. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER SET PTZ"), _T("RTS:%d DTR:%d POS:%d"), nRtsDtr & 0x01, (nRtsDtr & 0x02) == 0x02, m_RealPosition.dPan );
  106. break;
  107. case CMD_GET_PTZ:
  108. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER GET PTZ"), _T("") );
  109. break;
  110. case CMD_MOVE_PAN:
  111. // update position
  112. if( m_MovePan.dSpeed )
  113. {
  114. if( m_MovePan.bRight ) m_RealPosition.dPan -= LGS_MIRROR_ANGLE_OF_VIEW / 4;
  115. else m_RealPosition.dPan += LGS_MIRROR_ANGLE_OF_VIEW / 4;
  116. // validate
  117. if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 ) { nRtsDtr = 0x00; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  118. else if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 ) { nRtsDtr = 0x01; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  119. else if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 ) { nRtsDtr = 0x02; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  120. else { nRtsDtr = 0x03; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 0 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  121. pConnection->SetRTS( nRtsDtr & 0x01 );
  122. pConnection->SetDTR( nRtsDtr & 0x02 );
  123. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER PAN MOVE"), _T("RTS:%d DTR:%d POS:%d"), nRtsDtr & 0x01, (nRtsDtr & 0x02) == 0x02, m_RealPosition.dPan );
  124. }
  125. else
  126. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER PAN STOP"), _T("") );
  127. break;
  128. case CMD_NONE:
  129. default:
  130. // start new mode
  131. if( m_nSwitchEnterRemain <= 0 )
  132. {
  133. if( m_nSwitchInterRemain <= 0 )
  134. {
  135. // switch according to mode
  136. switch( m_nSwitchMode )
  137. {
  138. case 0:
  139. // always move right
  140. if( m_nSwitchInterDir ) m_RealPosition.dPan += LGS_MIRROR_ANGLE_OF_VIEW / 4;
  141. else m_RealPosition.dPan -= LGS_MIRROR_ANGLE_OF_VIEW / 4;
  142. // validate
  143. if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 ) { nRtsDtr = 0x00; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; m_nSwitchInterDir = !m_nSwitchInterDir; }
  144. else if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 ) { nRtsDtr = 0x01; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  145. else if ( m_RealPosition.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 ) { nRtsDtr = 0x02; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  146. else { nRtsDtr = 0x03; m_RealPosition.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 0 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; m_nSwitchInterDir = !m_nSwitchInterDir; }
  147. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER PAN AUTO"), _T("RTS:%d DTR:%d POS:%d"), nRtsDtr & 0x01, (nRtsDtr & 0x02) == 0x02, m_RealPosition.dPan );
  148. break;
  149. default:
  150. // set camera in default position
  151. m_Position.dPan = m_nSwitchMode * LGS_MIRROR_ANGLE_OF_VIEW / 4 - LGS_MIRROR_ANGLE_OF_VIEW / 8;
  152. // validate postion
  153. if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 ) { nRtsDtr = 0x00; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 3 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  154. else if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 ) { nRtsDtr = 0x01; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 2 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  155. else if ( m_Position.dPan > LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 ) { nRtsDtr = 0x02; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 1 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  156. else { nRtsDtr = 0x03; m_RealPosition.dPan = m_Position.dPan = LGS_MIRROR_ANGLE_OF_VIEW * 0 / 4 + LGS_MIRROR_ANGLE_OF_VIEW / 8; }
  157. break;
  158. }
  159. pConnection->SetRTS( nRtsDtr & 0x01 );
  160. pConnection->SetDTR( nRtsDtr & 0x02 );
  161. // reintialize inter remaining time
  162. m_nSwitchInterRemain = m_nTimeoutInterSwitch;
  163. }
  164. else
  165. // decrease time remain between consecutive switches
  166. m_nSwitchInterRemain = m_nSwitchInterRemain - 50L;
  167. }
  168. else
  169. // decrease time remaining to enter to switch mode
  170. m_nSwitchEnterRemain = m_nSwitchEnterRemain - 50L;
  171. *pTimeout = 50L;
  172. // LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER NO COMMAND"), _T("") );
  173. return FALSE;
  174. }
  175. // till next switch remain ...
  176. m_nSwitchEnterRemain = m_nTimeoutEnterSwitch;
  177. m_nSwitchInterRemain = m_nTimeoutInterSwitch;
  178. // after the time confirmation will be sent
  179. *pTimeout = m_nTimeoutCommand;
  180. // do perform read
  181. return TRUE;
  182. }
  183. BOOL CLgDevicePTZNesher::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChance )
  184. {
  185. // only at the end of timeout
  186. if( !bLastChance )
  187. return FALSE;
  188. switch( m_nMode )
  189. {
  190. case CMD_SET_PTZ:
  191. OnPerformCmd();
  192. //notify
  193. OnEvtSetPTZ( m_Position.dPan, m_Position.dTilt, m_Position.dZoom );
  194. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER SET PTZ"), _T("CONFIRMATION") );
  195. break;
  196. case CMD_GET_PTZ:
  197. // ready to process new message
  198. OnPerformCmd();
  199. //notify
  200. OnEvtGetPTZ( m_Position.dPan = m_RealPosition.dPan,
  201. m_Position.dTilt = m_RealPosition.dTilt,
  202. m_Position.dZoom = m_RealPosition.dZoom );
  203. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER GET PTZ"), _T("CONFIRMATION") );
  204. break;
  205. case CMD_MOVE_PAN:
  206. OnPerformCmd();
  207. OnEvtMovePan( m_MovePan.bRight, m_MovePan.dSpeed );
  208. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_INFO, this, _T("NESHER PAN"), _T("CONFIRMATION") );
  209. break;
  210. }
  211. // after/inter command timeout
  212. m_bPause = TRUE;
  213. return TRUE;
  214. }