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.

549 lines
16 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: DTKS576.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of DTKS576.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #ifdef __BORLANDC__
  16. #include "..\LgLib\Device\DTKS576.h"
  17. #else
  18. #include "DTKS576.h"
  19. #endif
  20. #define POSITION_QUALYTY 2
  21. #define MAX_NO_REPLY_COUNT 20
  22. #define MAX_NOT_IN_POSITION_COUNT 1
  23. #define DELAY_BETWEEN_COMMANDS 150
  24. #define ONLY_WAIT_AFTER_MOVEMENT 250
  25. CLgDevicePTZTKS576::CLgDevicePTZTKS576()
  26. {
  27. m_nMode = CMD_NONE;
  28. m_nStage = STAGE_GET_PAN;
  29. m_nNoReplyCount = 0;
  30. m_nNotInPositionCount = 0;
  31. m_bReadOnlyHeader = TRUE;
  32. }
  33. CLgDevicePTZTKS576::~CLgDevicePTZTKS576()
  34. {
  35. }
  36. void CLgDevicePTZTKS576::OnPerformCmd()
  37. {
  38. // ready for new message
  39. ReleaseCmd();
  40. // ready to process new message
  41. m_nMode = CMD_NONE;
  42. }
  43. BOOL CLgDevicePTZTKS576::CmdInit()
  44. {
  45. // check availibility
  46. return DoCmd( CMD_INIT );
  47. }
  48. BOOL CLgDevicePTZTKS576::WriteProc( void *pProtocol, PLONG pTimeout )
  49. {
  50. BYTE pSendBuffer[ CProtocolPTZTKS576::MAX_COMMAND_SIZE ];
  51. BYTE nSendCount = 0;
  52. // cast to protocol
  53. CProtocolPTZTKS576 *pProtocolPTZ = (CProtocolPTZTKS576*)pProtocol;
  54. // set working address
  55. pProtocolPTZ->SetAddress( GetAddress() );
  56. // check input command
  57. if( m_nMode == CMD_NONE )
  58. {
  59. switch( GetCmd() )
  60. {
  61. case CMD_INIT:
  62. m_nMode = CMD_INIT;
  63. m_nStage = STAGE_SET_AUTO_FOCUS;
  64. break;
  65. case CMD_GET_PTZ:
  66. m_nMode = CMD_GET_PTZ;
  67. m_nStage = STAGE_GET_PAN;
  68. break;
  69. case CMD_SET_PTZ:
  70. m_nMode = CMD_SET_PTZ;
  71. m_nStage = STAGE_SET_PAN;
  72. m_nNotInPositionCount = 0;
  73. break;
  74. case CMD_MOVE_TILT:
  75. m_nMode = CMD_MOVE_TILT;
  76. m_nStage = STAGE_TILT;
  77. break;
  78. case CMD_MOVE_PAN:
  79. m_nMode = CMD_MOVE_PAN;
  80. m_nStage = STAGE_PAN;
  81. break;
  82. case CMD_MOVE_ZOOM:
  83. m_nMode = CMD_MOVE_ZOOM;
  84. m_nStage = STAGE_ZOOM;
  85. break;
  86. case CMD_MOVE_FOCUS:
  87. m_nMode = CMD_MOVE_FOCUS;
  88. m_nStage = STAGE_FOCUS;
  89. break;
  90. case CMD_SET_FOCUS:
  91. m_nMode = CMD_SET_FOCUS;
  92. m_nStage = STAGE_FOCUS;
  93. break;
  94. case CMD_GET_FOCUS:
  95. m_nMode = CMD_GET_FOCUS;
  96. m_nStage = STAGE_FOCUS;
  97. break;
  98. case CMD_NONE:
  99. // no new commands
  100. break;
  101. case CMD_WIPER:
  102. case CMD_SET_IRIS:
  103. default:
  104. //command unsupported
  105. OnPerformCmd();
  106. OnEvtCommandError( m_nMode, _T("UNSUPPORTED") );
  107. break;
  108. }
  109. }
  110. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  111. BOOL bOnlyWait = FALSE;
  112. #endif
  113. // fill packet depend on command
  114. switch( m_nMode )
  115. {
  116. case CMD_SET_PTZ:
  117. switch( m_nStage )
  118. {
  119. case STAGE_SET_PAN:
  120. // ask for pan position
  121. nSendCount += PTZ_JVC_TK_S576::BuildSetPanPosition( pSendBuffer, GetAddress(), PTZ_JVC_TK_S576::Degree2Pan( m_Position.dPan ) );
  122. // short response
  123. m_bReadOnlyHeader = TRUE;
  124. break;
  125. case STAGE_SET_TILT:
  126. // ask for pan position
  127. nSendCount += PTZ_JVC_TK_S576::BuildSetTiltPosition( pSendBuffer, GetAddress(), PTZ_JVC_TK_S576::Degree2Tilt( m_Position.dTilt ) );
  128. // short response
  129. m_bReadOnlyHeader = TRUE;
  130. break;
  131. case STAGE_SET_ZOOM:
  132. // ask for pan position
  133. nSendCount += PTZ_JVC_TK_S576::BuildSetZoomPosition( pSendBuffer, GetAddress(), PTZ_JVC_TK_S576::Percent2Zoom( m_Position.dZoom ) );
  134. // short response
  135. m_bReadOnlyHeader = TRUE;
  136. break;
  137. case STAGE_SET_PAN_DELAY:
  138. m_nStage = STAGE_SET_TILT;
  139. *pTimeout = DELAY_BETWEEN_COMMANDS;
  140. return FALSE;
  141. case STAGE_SET_TILT_DELAY:
  142. m_nStage = STAGE_SET_ZOOM;
  143. *pTimeout = DELAY_BETWEEN_COMMANDS;
  144. return FALSE;
  145. case STAGE_SET_ZOOM_DELAY:
  146. m_nStage = STAGE_GET_PAN;
  147. *pTimeout = DELAY_BETWEEN_COMMANDS;// * 6;
  148. return FALSE;
  149. case STAGE_GET_PAN:
  150. // ready to process new message
  151. OnPerformCmd();
  152. //notify
  153. OnEvtSetPTZ( m_Position.dPan, m_Position.dTilt, m_Position.dZoom );
  154. // default delay
  155. *pTimeout = 10;
  156. return FALSE;
  157. }
  158. break;
  159. case CMD_INIT:
  160. switch( m_nStage )
  161. {
  162. case STAGE_SET_AUTO_FOCUS:
  163. // ask for pan position
  164. nSendCount += PTZ_JVC_TK_S576::BuildSetAutoFocus( pSendBuffer, GetAddress() );
  165. // long response
  166. m_bReadOnlyHeader = TRUE;
  167. break;
  168. }
  169. // next steps like in "get position"
  170. case CMD_GET_PTZ:
  171. switch( m_nStage )
  172. {
  173. case STAGE_GET_PAN:
  174. // ask for pan position
  175. nSendCount += PTZ_JVC_TK_S576::BuildGetPanPosition( pSendBuffer, GetAddress() );
  176. // long response
  177. m_bReadOnlyHeader = FALSE;
  178. break;
  179. case STAGE_GET_TILT:
  180. // ask for pan position
  181. nSendCount += PTZ_JVC_TK_S576::BuildGetTiltPosition( pSendBuffer, GetAddress() );
  182. // long response
  183. m_bReadOnlyHeader = FALSE;
  184. break;
  185. case STAGE_GET_ZOOM:
  186. // ask for pan position
  187. nSendCount += PTZ_JVC_TK_S576::BuildGetZoomPosition( pSendBuffer, GetAddress() );
  188. // long response
  189. m_bReadOnlyHeader = FALSE;
  190. break;
  191. case STAGE_GET_PAN_DELAY:
  192. m_nStage = STAGE_GET_TILT;
  193. *pTimeout = DELAY_BETWEEN_COMMANDS;
  194. return FALSE;
  195. case STAGE_GET_TILT_DELAY:
  196. m_nStage = STAGE_GET_ZOOM;
  197. *pTimeout = DELAY_BETWEEN_COMMANDS;
  198. return FALSE;
  199. }
  200. break;
  201. case CMD_MOVE_PAN:
  202. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  203. switch( m_nStage )
  204. {
  205. case STAGE_PAN:
  206. // write command
  207. nSendCount += PTZ_JVC_TK_S576::BuildPan( pSendBuffer, GetAddress(), m_MovePan.dSpeed > 0 ? ( m_MovePan.bRight ? PTZ_JVC_TK_S576::PAN_RIGHT : PTZ_JVC_TK_S576::PAN_LEFT ) : PTZ_JVC_TK_S576::PAN_STOP, PTZ_JVC_TK_S576::Percent2PanSpeed( m_MovePan.dSpeed ) );
  208. // set next stage
  209. m_nStage = STAGE_PAN_DELAY;
  210. // don't read reply
  211. bOnlyWait = TRUE;
  212. break;
  213. case STAGE_PAN_DELAY:
  214. // ready to process new message
  215. OnPerformCmd();
  216. //notify
  217. OnEvtMovePan( m_MovePan.bRight, m_MovePan.dSpeed );
  218. // no timeout
  219. *pTimeout = 0;
  220. return FALSE;
  221. }
  222. #else
  223. // write command
  224. nSendCount += PTZ_JVC_TK_S576::BuildPan( pSendBuffer, GetAddress(), m_MovePan.dSpeed > 0 ? ( m_MovePan.bRight ? PTZ_JVC_TK_S576::PAN_RIGHT : PTZ_JVC_TK_S576::PAN_LEFT ) : PTZ_JVC_TK_S576::PAN_STOP, PTZ_JVC_TK_S576::Percent2PanSpeed( m_MovePan.dSpeed ) );
  225. // short response
  226. m_bReadOnlyHeader = TRUE;
  227. #endif
  228. break;
  229. case CMD_MOVE_TILT:
  230. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  231. switch( m_nStage )
  232. {
  233. case STAGE_TILT:
  234. // write command
  235. nSendCount += PTZ_JVC_TK_S576::BuildTilt( pSendBuffer, GetAddress(), m_MoveTilt.dSpeed > 0 ? ( m_MoveTilt.bUp ? PTZ_JVC_TK_S576::TILT_UP : PTZ_JVC_TK_S576::TILT_DOWN ) : PTZ_JVC_TK_S576::TILT_STOP, PTZ_JVC_TK_S576::Percent2TiltSpeed( m_MoveTilt.dSpeed ) );
  236. // set next stage
  237. m_nStage = STAGE_TILT_DELAY;
  238. // don't read reply
  239. bOnlyWait = TRUE;
  240. break;
  241. case STAGE_TILT_DELAY:
  242. // ready to process new message
  243. OnPerformCmd();
  244. //notify
  245. OnEvtMoveTilt( m_MoveTilt.bUp, m_MoveTilt.dSpeed );
  246. // no timeout
  247. *pTimeout = 0;
  248. return FALSE;
  249. }
  250. #else
  251. // write command
  252. nSendCount += PTZ_JVC_TK_S576::BuildTilt( pSendBuffer, GetAddress(), m_MoveTilt.dSpeed > 0 ? ( m_MoveTilt.bUp ? PTZ_JVC_TK_S576::TILT_UP : PTZ_JVC_TK_S576::TILT_DOWN ) : PTZ_JVC_TK_S576::TILT_STOP, PTZ_JVC_TK_S576::Percent2TiltSpeed( m_MoveTilt.dSpeed ) );
  253. // short response
  254. m_bReadOnlyHeader = TRUE;
  255. #endif
  256. break;
  257. case CMD_MOVE_ZOOM:
  258. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  259. switch( m_nStage )
  260. {
  261. case STAGE_ZOOM:
  262. // write command
  263. nSendCount += PTZ_JVC_TK_S576::BuildZoom( pSendBuffer, GetAddress(), m_MoveZoom.dSpeed > 0 ? ( m_MoveZoom.bTele ? PTZ_JVC_TK_S576::ZOOM_TELE : PTZ_JVC_TK_S576::ZOOM_WIDE ) : PTZ_JVC_TK_S576::ZOOM_STOP, PTZ_JVC_TK_S576::Percent2ZoomSpeed( m_MoveZoom.dSpeed ) );
  264. // set next stage
  265. m_nStage = STAGE_ZOOM_DELAY;
  266. // don't read reply
  267. bOnlyWait = TRUE;
  268. break;
  269. case STAGE_ZOOM_DELAY:
  270. // ready to process new message
  271. OnPerformCmd();
  272. //notify
  273. OnEvtMoveZoom( m_MoveZoom.bTele, m_MoveZoom.dSpeed );
  274. // no timeout
  275. *pTimeout = 0;
  276. return FALSE;
  277. }
  278. #else
  279. // write command
  280. nSendCount += PTZ_JVC_TK_S576::BuildZoom( pSendBuffer, GetAddress(), m_MoveZoom.dSpeed > 0 ? ( m_MoveZoom.bTele ? PTZ_JVC_TK_S576::ZOOM_TELE : PTZ_JVC_TK_S576::ZOOM_WIDE ) : PTZ_JVC_TK_S576::ZOOM_STOP, PTZ_JVC_TK_S576::Percent2ZoomSpeed( m_MoveZoom.dSpeed ) );
  281. // short response
  282. m_bReadOnlyHeader = TRUE;
  283. #endif
  284. break;
  285. case CMD_MOVE_FOCUS:
  286. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  287. switch( m_nStage )
  288. {
  289. case STAGE_FOCUS:
  290. // write command
  291. nSendCount += PTZ_JVC_TK_S576::BuildMoveFocus( pSendBuffer, GetAddress(), m_MoveFocus.dSpeed > 0 ? ( m_MoveFocus.bFar ? PTZ_JVC_TK_S576::FOCUS_FAR : PTZ_JVC_TK_S576::FOCUS_NEAR ) : PTZ_JVC_TK_S576::FOCUS_STOP, PTZ_JVC_TK_S576::Percent2FocusSpeed( m_MoveFocus.dSpeed ) );
  292. // set next stage
  293. m_nStage = STAGE_FOCUS_DELAY;
  294. // don't read reply
  295. bOnlyWait = TRUE;
  296. break;
  297. case STAGE_FOCUS_DELAY:
  298. // ready to process new message
  299. OnPerformCmd();
  300. //notify
  301. OnEvtMoveFocus( m_MoveFocus.bFar, m_MoveFocus.dSpeed );
  302. // no timeout
  303. *pTimeout = 0;
  304. return FALSE;
  305. }
  306. #else
  307. // write command
  308. nSendCount += PTZ_JVC_TK_S576::BuildMoveFocus( pSendBuffer, GetAddress(), m_MoveFocus.dSpeed > 0 ? ( m_MoveFocus.bFar ? PTZ_JVC_TK_S576::FOCUS_FAR : PTZ_JVC_TK_S576::FOCUS_NEAR ) : PTZ_JVC_TK_S576::FOCUS_STOP, PTZ_JVC_TK_S576::Percent2FocusSpeed( m_MoveFocus.dSpeed ) );
  309. // short response
  310. m_bReadOnlyHeader = TRUE;
  311. #endif
  312. break;
  313. case CMD_SET_FOCUS:
  314. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  315. switch( m_nStage )
  316. {
  317. case STAGE_FOCUS:
  318. // write data
  319. nSendCount += PTZ_JVC_TK_S576::BuildSetFocusPosition( pSendBuffer, GetAddress(), PTZ_JVC_TK_S576::Percent2Focus( m_Focus ) );
  320. // set next stage
  321. m_nStage = STAGE_FOCUS_DELAY;
  322. // don't read reply
  323. bOnlyWait = TRUE;
  324. break;
  325. case STAGE_FOCUS_DELAY:
  326. // ready to process new message
  327. OnPerformCmd();
  328. //notify
  329. OnEvtSetFocus( m_Focus );
  330. // no timeout
  331. *pTimeout = 0;
  332. return FALSE;
  333. }
  334. #else
  335. // write data
  336. nSendCount += PTZ_JVC_TK_S576::BuildSetFocusPosition( pSendBuffer, GetAddress(), PTZ_JVC_TK_S576::Percent2Focus( m_Focus ) );
  337. // short response
  338. m_bReadOnlyHeader = TRUE;
  339. #endif
  340. break;
  341. case CMD_GET_FOCUS:
  342. // write command
  343. nSendCount += PTZ_JVC_TK_S576::BuildGetFocusPosition( pSendBuffer, GetAddress() );
  344. // short response
  345. m_bReadOnlyHeader = FALSE;
  346. break;
  347. case CMD_NONE:
  348. default:
  349. *pTimeout = 10L;
  350. return FALSE;
  351. }
  352. // write packet
  353. if( !pProtocolPTZ->Write( pSendBuffer, nSendCount, 1000UL, TRUE ) )
  354. return FALSE;
  355. #ifdef ONLY_WAIT_AFTER_MOVEMENT
  356. if( bOnlyWait )
  357. // only wait
  358. *pTimeout = ONLY_WAIT_AFTER_MOVEMENT;
  359. else
  360. #endif
  361. *pTimeout = m_bReadOnlyHeader ? 250L : 1000L; // TX + RX
  362. return TRUE;
  363. }
  364. BOOL CLgDevicePTZTKS576::ReadProc( void *pProtocol, LONG lTimeout, BOOL bLastChance )
  365. {
  366. CProtocolPTZTKS576 *pProtocolPTZ = (CProtocolPTZTKS576*) pProtocol;
  367. // set protocol read mode
  368. pProtocolPTZ->SetReadOnlyHeaderMode( m_bReadOnlyHeader );
  369. // read reply
  370. PBYTE pReadBuffer = NULL;
  371. INT nReadCount = 0;
  372. if( !pProtocolPTZ->Read( &pReadBuffer, &nReadCount, lTimeout, TRUE ) || !pReadBuffer || !nReadCount )
  373. {
  374. if( !bLastChance )
  375. return FALSE;
  376. m_nNoReplyCount++;
  377. if( m_nNoReplyCount > MAX_NO_REPLY_COUNT )
  378. {
  379. // perform reinitialization
  380. m_nMode = CMD_INIT;
  381. m_nStage = STAGE_SET_AUTO_FOCUS;
  382. }
  383. return FALSE;
  384. }
  385. // reset retry counter
  386. m_nNoReplyCount = 0;
  387. // switch mode
  388. switch( m_nMode )
  389. {
  390. case CMD_INIT:
  391. switch( m_nStage )
  392. {
  393. case STAGE_SET_AUTO_FOCUS:
  394. // next stage
  395. m_nStage = STAGE_GET_PAN;
  396. return TRUE;
  397. }
  398. // next steps like in get position
  399. case CMD_GET_PTZ:
  400. switch( m_nStage )
  401. {
  402. case STAGE_GET_PAN:
  403. // store position
  404. m_Position.dPan = PTZ_JVC_TK_S576::Pan2Degree( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  405. // next stage
  406. m_nStage = STAGE_GET_PAN_DELAY;
  407. return TRUE;
  408. case STAGE_GET_TILT:
  409. // store position
  410. m_Position.dTilt = PTZ_JVC_TK_S576::Tilt2Degree( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  411. // next stage
  412. m_nStage = STAGE_GET_TILT_DELAY;
  413. return TRUE;
  414. case STAGE_GET_ZOOM:
  415. // store position
  416. m_Position.dZoom = PTZ_JVC_TK_S576::Zoom2Percent( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  417. // ready to process new message
  418. OnPerformCmd();
  419. //notify
  420. if( m_nMode == CMD_INIT )
  421. OnEvtInit();
  422. else
  423. OnEvtGetPTZ( m_Position.dPan, m_Position.dTilt, m_Position.dZoom );
  424. break;
  425. }
  426. break;
  427. case CMD_SET_PTZ:
  428. switch( m_nStage )
  429. {
  430. case STAGE_SET_PAN: m_nStage = STAGE_SET_PAN_DELAY; return TRUE;
  431. case STAGE_SET_TILT: m_nStage = STAGE_SET_TILT_DELAY; return TRUE;
  432. case STAGE_SET_ZOOM: m_nStage = STAGE_SET_ZOOM_DELAY; return TRUE;
  433. /*
  434. case STAGE_GET_PAN:
  435. // store position
  436. m_TempPosition.dPan = PTZ_JVC_TK_S576::Pan2Degree( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  437. // next stage
  438. m_nStage = STAGE_GET_PAN_DELAY;
  439. return TRUE;
  440. case STAGE_GET_TILT:
  441. // store position
  442. m_TempPosition.dTilt = PTZ_JVC_TK_S576::Tilt2Degree( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  443. // next stage
  444. m_nStage = STAGE_GET_TILT_DELAY;
  445. return TRUE;
  446. case STAGE_GET_ZOOM:
  447. // store position
  448. m_TempPosition.dZoom = PTZ_JVC_TK_S576::Zoom2Percent( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  449. // calculate difference between desired position and current position
  450. if( PTZ_JVC_TK_S576::QualifyPosition( m_TempPosition.dPan - m_Position.dPan,
  451. m_TempPosition.dTilt - m_Position.dTilt,
  452. m_TempPosition.dZoom - m_Position.dZoom,
  453. POSITION_QUALYTY ) ||
  454. m_nNotInPositionCount >= MAX_NOT_IN_POSITION_COUNT )
  455. {
  456. // store position
  457. m_Position.dPan = m_TempPosition.dPan;
  458. m_Position.dTilt = m_TempPosition.dTilt;
  459. m_Position.dZoom = m_TempPosition.dZoom;
  460. // ready to process new message
  461. OnPerformCmd();
  462. //notify
  463. OnEvtGotoPosition( m_Position.dPan, m_Position.dTilt, m_Position.dZoom );
  464. }
  465. else
  466. {
  467. // does not in posiiton
  468. m_nStage = STAGE_SET_PAN;
  469. // increate fault counter
  470. m_nNotInPositionCount++;
  471. return TRUE;
  472. }
  473. break;
  474. */
  475. }
  476. break;
  477. case CMD_MOVE_PAN:
  478. // ready to process new message
  479. OnPerformCmd();
  480. //notify
  481. OnEvtMovePan( m_MovePan.bRight, m_MovePan.dSpeed );
  482. break;
  483. case CMD_MOVE_TILT:
  484. // ready to process new message
  485. OnPerformCmd();
  486. //notify
  487. OnEvtMoveTilt( m_MoveTilt.bUp, m_MoveTilt.dSpeed );
  488. break;
  489. case CMD_MOVE_ZOOM:
  490. // ready to process new message
  491. OnPerformCmd();
  492. //notify
  493. OnEvtMoveZoom( m_MoveZoom.bTele, m_MoveZoom.dSpeed );
  494. break;
  495. case CMD_MOVE_FOCUS:
  496. // ready to process new message
  497. OnPerformCmd();
  498. //notify
  499. OnEvtMoveFocus( m_MoveFocus.bFar, m_MoveFocus.dSpeed );
  500. break;
  501. case CMD_SET_FOCUS:
  502. // ready to process new message
  503. OnPerformCmd();
  504. //notify
  505. OnEvtSetFocus( m_Focus );
  506. break;
  507. case CMD_GET_FOCUS:
  508. // store position
  509. m_Focus = PTZ_JVC_TK_S576::Focus2Percent( PTZ_JVC_TK_S576::ToValue( pReadBuffer[1], pReadBuffer[4], pReadBuffer[5] ) );
  510. // ready to process new message
  511. OnPerformCmd();
  512. //notify
  513. OnEvtGetFocus( m_Focus );
  514. break;
  515. }
  516. return TRUE;
  517. }