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.

388 lines
9.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: Laserguard libraries
  7. // SUBSYSTEM: Communication support library
  8. // FILE: PTKS576.h
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of CProtocolPTZTKS576
  13. //----------------------------------------------------------------------------
  14. #ifndef __PROTOCOL__PTZ__TK__S__576__H__INCLUDED__
  15. #define __PROTOCOL__PTZ__TK__S__576__H__INCLUDED__
  16. #if _MSC_VER > 1000
  17. #pragma once
  18. #endif // _MSC_VER > 1000
  19. #ifdef __BORLANDC__
  20. #include "..\LgLib\Comm\Connect.h"
  21. #include "..\LgLib\Comm\Protocol.h"
  22. #include "..\LgLib\Device\LgDevPTZ.h"
  23. #else
  24. #include "Connect.h"
  25. #include "Protocol.h"
  26. #include "..\Device\LgDevPTZ.h"
  27. #endif
  28. class CProtocolPTZTKS576 :
  29. public CProtocol
  30. {
  31. public:
  32. CProtocolPTZTKS576();
  33. virtual ~CProtocolPTZTKS576();
  34. public:
  35. BOOL Create( CConnection *pConnection );
  36. void Destroy();
  37. public:
  38. void SetAddress( BYTE bAddress );
  39. void SetReadAnyAddress( BOOL bReadAnyAddress ) { m_bReadAnyAddress = bReadAnyAddress; }
  40. void SetReadOnlyHeaderMode( BOOL bReadOnlyHeader ) { m_bReadOnlyHeader = bReadOnlyHeader; }
  41. public:
  42. virtual BOOL Read( PBYTE *ppBuffer, PINT pCount, DWORD dwTimeout, BOOL bHost );
  43. virtual BOOL Write( PBYTE pBuffer, INT nCount, DWORD dwTimeout, BOOL bHost );
  44. public:
  45. enum
  46. {
  47. MAX_COMMAND_SIZE = 31,
  48. };
  49. private:
  50. CConnection*m_pConnection;
  51. BYTE m_pBuffer[MAX_COMMAND_SIZE];
  52. PBYTE m_pBufferPtr;
  53. INT m_nCount;
  54. private:
  55. BYTE m_bAddress;
  56. private:
  57. BOOL m_bReadAnyAddress;
  58. BOOL m_bReadOnlyHeader;
  59. };
  60. #ifdef __BCPLUSPLUS__
  61. #pragma warn -inl
  62. #endif
  63. struct PTZ_JVC_TK_S576
  64. {
  65. // commands
  66. public:
  67. static INT BuildSetPanPosition( LPBYTE pBuffer, BYTE bAddress, WORD wPan )
  68. {
  69. pBuffer[ 0] = 0xB1; // ???
  70. pBuffer[ 1] = 0x01; // group
  71. pBuffer[ 2] = bAddress; // address
  72. pBuffer[ 3] = 0x84; // ???
  73. pBuffer[ 4] = 0x43; // ???
  74. pBuffer[ 5] = 0x04; //
  75. pBuffer[ 6] = ToByte1( wPan ); // pan hi part
  76. pBuffer[ 7] = ToByte2( wPan ); // pan low part
  77. return 8;
  78. }
  79. static INT BuildSetTiltPosition( LPBYTE pBuffer, BYTE bAddress, WORD wTilt )
  80. {
  81. pBuffer[ 0] = 0xB1; // ???
  82. pBuffer[ 1] = 0x01; // group
  83. pBuffer[ 2] = bAddress; // address
  84. pBuffer[ 3] = 0x84; // ???
  85. pBuffer[ 4] = 0x43; // ???
  86. pBuffer[ 5] = 0x05; // command code
  87. pBuffer[ 6] = ToByte1( wTilt ); // tilt hi part
  88. pBuffer[ 7] = ToByte2( wTilt ); // tilt low part
  89. return 8;
  90. }
  91. static INT BuildSetZoomPosition( LPBYTE pBuffer, BYTE bAddress, WORD wZoom )
  92. {
  93. pBuffer[ 0] = 0xB1; // ???
  94. pBuffer[ 1] = 0x01; // group
  95. pBuffer[ 2] = bAddress; // address
  96. pBuffer[ 3] = 0x84; // ???
  97. pBuffer[ 4] = 0x43; // ???
  98. pBuffer[ 5] = 0x02; // command code
  99. pBuffer[ 6] = ToByte1( wZoom ); // zoom hi part
  100. pBuffer[ 7] = ToByte2( wZoom ); // zoom low part
  101. return 8;
  102. }
  103. static INT BuildSetFocusPosition( LPBYTE pBuffer, BYTE bAddress, WORD wFocus )
  104. {
  105. pBuffer[ 0] = 0xB1; // ???
  106. pBuffer[ 1] = 0x01; // group
  107. pBuffer[ 2] = bAddress; // address
  108. pBuffer[ 3] = 0x84; // ???
  109. pBuffer[ 4] = 0x43; // ???
  110. pBuffer[ 5] = 0x03; // command code
  111. pBuffer[ 6] = ToByte1( wFocus ); // zoom hi part
  112. pBuffer[ 7] = ToByte2( wFocus ); // zoom low part
  113. return 8;
  114. }
  115. static INT BuildGetPanPosition( LPBYTE pBuffer, BYTE bAddress )
  116. {
  117. pBuffer[ 0] = 0xB1; // ???
  118. pBuffer[ 1] = 0x01; // group
  119. pBuffer[ 2] = bAddress; // address
  120. pBuffer[ 3] = 0x82; // ???
  121. pBuffer[ 4] = 0x03; // ???
  122. pBuffer[ 5] = 0x04; //
  123. return 6;
  124. }
  125. static INT BuildGetTiltPosition( LPBYTE pBuffer, BYTE bAddress )
  126. {
  127. pBuffer[ 0] = 0xB1; // ???
  128. pBuffer[ 1] = 0x01; // group
  129. pBuffer[ 2] = bAddress; // address
  130. pBuffer[ 3] = 0x82; // ???
  131. pBuffer[ 4] = 0x03; // ???
  132. pBuffer[ 5] = 0x05; // command code
  133. return 6;
  134. }
  135. static INT BuildGetZoomPosition( LPBYTE pBuffer, BYTE bAddress )
  136. {
  137. pBuffer[0] = 0xB1; // ???
  138. pBuffer[1] = 0x01; // group
  139. pBuffer[2] = bAddress; // address
  140. pBuffer[3] = 0x82; // ???
  141. pBuffer[4] = 0x03; // ???
  142. pBuffer[5] = 0x02; // command code
  143. return 6;
  144. }
  145. static INT BuildGetFocusPosition( LPBYTE pBuffer, BYTE bAddress )
  146. {
  147. pBuffer[0] = 0xB1; // ???
  148. pBuffer[1] = 0x01; // group
  149. pBuffer[2] = bAddress; // address
  150. pBuffer[3] = 0x82; // ???
  151. pBuffer[4] = 0x03; // ???
  152. pBuffer[5] = 0x03; // command code
  153. return 6;
  154. }
  155. enum { PAN_STOP = 0x00, PAN_RIGHT = 0x01, PAN_LEFT = 0x03 };
  156. static INT BuildPan( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
  157. {
  158. pBuffer[0] = 0xB1; // header
  159. pBuffer[1] = 0x01; // group
  160. pBuffer[2] = bAddress; // address
  161. pBuffer[3] = (bDirection == PAN_STOP) ? 0x82 : 0x83;
  162. pBuffer[4] = 0x45; // ???
  163. switch( bDirection )
  164. {
  165. case PAN_RIGHT:
  166. pBuffer[5] = 0x00;
  167. pBuffer[6] = bSpeed;
  168. return 7;
  169. case PAN_LEFT:
  170. pBuffer[5] = 0x01;
  171. pBuffer[6] = bSpeed;
  172. return 7;
  173. case PAN_STOP:
  174. pBuffer[5] = 0x02;
  175. return 6;
  176. }
  177. return 0;
  178. }
  179. enum { TILT_STOP = 0x00, TILT_UP = 0x04, TILT_DOWN = 0x0C };
  180. static INT BuildTilt( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
  181. {
  182. pBuffer[0] = 0xB1; // header
  183. pBuffer[1] = 0x01; // group
  184. pBuffer[2] = bAddress; // address
  185. pBuffer[3] = (bDirection == TILT_STOP) ? 0x82 : 0x83;
  186. pBuffer[4] = 0x45;
  187. switch( bDirection )
  188. {
  189. case TILT_UP:
  190. pBuffer[5] = 0x03;
  191. pBuffer[6] = bSpeed;
  192. return 7;
  193. case TILT_DOWN:
  194. pBuffer[5] = 0x04;
  195. pBuffer[6] = bSpeed;
  196. return 7;
  197. case TILT_STOP:
  198. pBuffer[5] = 0x05;
  199. return 6;
  200. }
  201. return 0;
  202. }
  203. enum { ZOOM_STOP = 0x00, ZOOM_WIDE = 0x10, ZOOM_TELE = 0x30 };
  204. static INT BuildZoom( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
  205. {
  206. pBuffer[0] = 0xB1; // header
  207. pBuffer[1] = 0x01; // group
  208. pBuffer[2] = bAddress; // address
  209. pBuffer[3] = (bDirection == ZOOM_STOP) ? 0x82 : 0x83;
  210. pBuffer[4] = 0x45; // ???
  211. switch( bDirection )
  212. {
  213. case ZOOM_TELE:
  214. pBuffer[5] = 0x0C;
  215. pBuffer[6] = bSpeed;
  216. return 7;
  217. case ZOOM_WIDE:
  218. pBuffer[5] = 0x0D;
  219. pBuffer[6] = bSpeed;
  220. return 7;
  221. case ZOOM_STOP:
  222. pBuffer[5] = 0x0E;
  223. return 6;
  224. }
  225. return 0;
  226. }
  227. enum { FOCUS_STOP = 0x00, FOCUS_FAR = 0x40, FOCUS_NEAR = 0xC0 };
  228. static INT BuildMoveFocus( LPBYTE pBuffer, BYTE bAddress, BYTE bDirection, BYTE bSpeed )
  229. {
  230. pBuffer[0] = 0xB1; // header
  231. pBuffer[1] = 0x01; // group
  232. pBuffer[2] = bAddress; // address
  233. pBuffer[3] = (bDirection == FOCUS_STOP) ? 0x82 : 0x83;
  234. pBuffer[4] = 0x45; // ???
  235. switch( bDirection )
  236. {
  237. case FOCUS_FAR:
  238. pBuffer[5] = 0x09;
  239. pBuffer[6] = bSpeed;
  240. return 7;
  241. case FOCUS_NEAR:
  242. pBuffer[5] = 0x0A;
  243. pBuffer[6] = bSpeed;
  244. return 7;
  245. case FOCUS_STOP:
  246. pBuffer[5] = 0x0B;
  247. return 6;
  248. }
  249. return 0;
  250. }
  251. static INT BuildSetAutoFocus( LPBYTE pBuffer, BYTE bAddress )
  252. {
  253. pBuffer[0] = 0xB1; // ???
  254. pBuffer[1] = 0x01; // group
  255. pBuffer[2] = bAddress; // address
  256. pBuffer[3] = 0x81; // ???
  257. pBuffer[4] = 0x1F; // ???
  258. return 5;
  259. }
  260. // conversion
  261. public:
  262. // pan
  263. static CLgDevicePTZ::PTZ_DEGREE Pan2Degree( WORD wPan )
  264. {
  265. return wPan * 360L / 0x18FFL;
  266. }
  267. static WORD Degree2Pan( CLgDevicePTZ::PTZ_DEGREE Angle )
  268. {
  269. return (WORD)( ( Angle * 0x18FFL ) / 360L );
  270. }
  271. // tilt
  272. static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree( WORD wTilt )
  273. {
  274. return wTilt * 180L / 0x1900L;
  275. }
  276. static WORD Degree2Tilt( CLgDevicePTZ::PTZ_DEGREE dAngle )
  277. {
  278. return (WORD)( dAngle * 0x1900L / 180L );
  279. }
  280. // zoom
  281. static WORD Percent2Zoom( CLgDevicePTZ::PTZ_PERCENT dPercent )
  282. {
  283. return (WORD)( ( dPercent * ( 0x17E8L - 0x20L ) ) / 100L + 0x20L );
  284. }
  285. static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent( WORD wZoom )
  286. {
  287. return ( wZoom - 0x20L ) * 100L / ( 0x17E8L - 0x20L );
  288. }
  289. // focus
  290. static WORD Percent2Focus( CLgDevicePTZ::PTZ_PERCENT dPercent )
  291. {
  292. return (WORD)( ( (100L - dPercent) * ( 0x0580L - 0x20L ) ) / 100L + 0x20L );
  293. }
  294. static CLgDevicePTZ::PTZ_PERCENT Focus2Percent( WORD wFocus )
  295. {
  296. return 100L - ( ( wFocus - 0x20L ) * 100L / ( 0x0580L - 0x20L ) );
  297. }
  298. // pan speed
  299. static BYTE Percent2PanSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
  300. {
  301. return (BYTE)( dPercent * 15L / 100L + 0x10L );
  302. }
  303. static CLgDevicePTZ::PTZ_PERCENT PanSpeed2Percent( BYTE bSpeed )
  304. {
  305. return ( bSpeed - 0x10L ) * 100L / 15L;
  306. }
  307. // tilt speed
  308. static BYTE Percent2TiltSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
  309. {
  310. return (BYTE)( dPercent * 15L / 100L + 0x10L );
  311. }
  312. static CLgDevicePTZ::PTZ_PERCENT TiltSpeed2Percent( BYTE bSpeed )
  313. {
  314. return (bSpeed - 0x10L ) * 100L / 15L;
  315. }
  316. // zoom speed
  317. static BYTE Percent2ZoomSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
  318. {
  319. return (BYTE)( dPercent * 0x03L / 100L );
  320. }
  321. static CLgDevicePTZ::PTZ_PERCENT ZoomSpeed2Percent( BYTE bSpeed )
  322. {
  323. return bSpeed * 100L / 0x03L;
  324. }
  325. // focus speed
  326. static BYTE Percent2FocusSpeed( CLgDevicePTZ::PTZ_PERCENT dPercent )
  327. {
  328. return (BYTE)( dPercent * 0x03L / 100L );
  329. }
  330. static CLgDevicePTZ::PTZ_PERCENT FocusSpeed2Percent( BYTE bSpeed )
  331. {
  332. return bSpeed * 100L / 0x03L;
  333. }
  334. // value conversion
  335. static WORD ToValue( BYTE bTag, BYTE b1, BYTE b2 )
  336. {
  337. return ( (bTag & 0x0F) == 4 ) ? ( b1 * (WORD)0x80 + b2 ) : b1;
  338. }
  339. static BYTE ToByte1( WORD wValue )
  340. {
  341. return wValue / 0x80;
  342. }
  343. static BYTE ToByte2( WORD wValue )
  344. {
  345. return wValue % 0x80;
  346. }
  347. };
  348. #ifdef __BCPLUSPLUS__
  349. #pragma warn .inl
  350. #endif
  351. #endif