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.

456 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: Laserguard libraries
  7. // SUBSYSTEM: Communication support library
  8. // FILE: MIC1300m.h
  9. // AUTHOR: Chizhevskiy Sergey
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of PTZ_MIC_1_300
  13. //----------------------------------------------------------------------------
  14. #ifdef __BCPLUSPLUS__
  15. #pragma warn -inl
  16. #endif
  17. #ifndef __MIC_1_300__PTZ__H__INCLUDED__
  18. #define __MIC_1_300__PTZ__H__INCLUDED__
  19. #ifdef __BORLANDC__
  20. #include "..\LgLib\Device\LgDevPTZ.h"
  21. #else
  22. #include "..\Device\LgDevPTZ.h"
  23. #endif
  24. struct PTZ_MIC_1_300
  25. {
  26. // types
  27. public:
  28. typedef struct
  29. {
  30. BOOL bZoomOn;
  31. BOOL bZoomWide;
  32. BOOL bTiltOn;
  33. BOOL bTiltDown;
  34. BOOL bPanOn;
  35. BOOL bPanRight;
  36. BYTE bPanSpeed;
  37. BYTE bTiltSpeed;
  38. BOOL bLampsOn;
  39. BOOL bWiperOn;
  40. }CONTROL_STATUS, *PCONTROL_STATUS;
  41. // constants
  42. public:
  43. enum { CF_FULL_DUPLEX = '6', CF_HALF_DUPLEX = '4', CF_SIMPLEX = '2' };
  44. // commands
  45. public:
  46. static INT BuildGotoPosition( LPBYTE pBuffer, BYTE bAddress, WORD wPan, WORD wTilt, WORD wZoom )
  47. {
  48. pBuffer[ 0] = 0x0A; // line feed (header)
  49. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  50. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  51. pBuffer[ 3] = ToAscii( 20, 1 ); // length
  52. pBuffer[ 4] = ToAscii( 20, 0 ); // --||--
  53. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  54. pBuffer[ 6] = 'N'; // control code (command)
  55. pBuffer[ 7] = ToAscii( wPan, 2 ); // pan
  56. pBuffer[ 8] = ToAscii( wPan, 1 ); // --||--
  57. pBuffer[ 9] = ToAscii( wPan, 0 ); // --||--
  58. pBuffer[10] = ToAscii( wTilt, 2 ); // tilt
  59. pBuffer[11] = ToAscii( wTilt, 1 ); // --||--
  60. pBuffer[12] = ToAscii( wTilt, 0 ); // --||--
  61. pBuffer[13] = ToAscii( wZoom, 2 ); // zoom
  62. pBuffer[14] = ToAscii( wZoom, 1 ); // --||--
  63. pBuffer[15] = ToAscii( wZoom, 0 ); // --||--
  64. pBuffer[16] = '0'; // unsupported
  65. pBuffer[17] = '0'; // --||--
  66. pBuffer[18] = '0'; // --||--
  67. return CheckSum( pBuffer, 20 );
  68. }
  69. static INT BuildGetPosition( LPBYTE pBuffer, BYTE bAddress )
  70. {
  71. pBuffer[ 0] = 0x0A; // line feed (header)
  72. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  73. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  74. pBuffer[ 3] = ToAscii( 8, 1 ); // length
  75. pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
  76. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  77. pBuffer[ 6] = 'O'; // control code (command)
  78. return CheckSum( pBuffer, 8 );
  79. }
  80. static INT BuildGetConfig( LPBYTE pBuffer, BYTE bAddress )
  81. {
  82. pBuffer[ 0] = 0x0A; // line feed (header)
  83. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  84. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  85. pBuffer[ 3] = ToAscii( 8, 1 ); // length
  86. pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
  87. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  88. pBuffer[ 6] = 'a'; // control code (command)
  89. return CheckSum( pBuffer, 8 );
  90. }
  91. static INT BuildSetConfig( LPBYTE pBuffer, BYTE bAddress, BYTE bConfig )
  92. {
  93. pBuffer[ 0] = 0x0A; // line feed (header)
  94. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  95. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  96. pBuffer[ 3] = ToAscii( 10, 1 ); // length
  97. pBuffer[ 4] = ToAscii( 10, 0 ); // --||--
  98. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  99. pBuffer[ 6] = 'q'; // control code (command)
  100. pBuffer[ 7] = ToAscii( bConfig, 1 ); // config
  101. pBuffer[ 8] = ToAscii( bConfig, 0 ); // --||--
  102. return CheckSum( pBuffer, 10 );
  103. }
  104. static INT BuildSetAddress( LPBYTE pBuffer, BYTE bAddress, BYTE bNewAddress )
  105. {
  106. pBuffer[ 0] = 0x0A; // line feed (header)
  107. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  108. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  109. pBuffer[ 3] = ToAscii( 10, 1 ); // length
  110. pBuffer[ 4] = ToAscii( 10, 0 ); // --||--
  111. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  112. pBuffer[ 6] = 's'; // control code (command)
  113. pBuffer[ 7] = ToAscii( bNewAddress, 1 );// new address
  114. pBuffer[ 8] = ToAscii( bNewAddress, 0 );// --||--
  115. return CheckSum( pBuffer, 10 );
  116. }
  117. static INT BuildGetStatus( LPBYTE pBuffer, BYTE bAddress )
  118. {
  119. pBuffer[ 0] = 0x0A; // line feed (header)
  120. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  121. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  122. pBuffer[ 3] = ToAscii( 8, 1 ); // length
  123. pBuffer[ 4] = ToAscii( 8, 0 ); // --||--
  124. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  125. pBuffer[ 6] = 'H'; // control code (command)
  126. return CheckSum( pBuffer, 8 );
  127. }
  128. static INT BuildSetManualControl( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus )
  129. {
  130. pBuffer[ 0] = 0x0A; // line feed (header)
  131. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  132. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  133. pBuffer[ 3] = ToAscii( 18, 1 ); // length
  134. pBuffer[ 4] = ToAscii( 18, 0 ); // --||--
  135. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  136. pBuffer[ 6] = 'G'; // control code (command)
  137. BYTE bCmd = 0;
  138. if( pStatus->bPanRight ) bCmd |= 0x01;
  139. if( pStatus->bPanOn ) bCmd |= 0x02;
  140. if( pStatus->bTiltDown ) bCmd |= 0x04;
  141. if( pStatus->bTiltOn ) bCmd |= 0x08;
  142. if( pStatus->bZoomWide ) bCmd |= 0x10;
  143. if( pStatus->bZoomOn ) bCmd |= 0x20;
  144. pBuffer[ 7] = ToAscii( bCmd, 1 ); // command
  145. pBuffer[ 8] = ToAscii( bCmd, 0 ); // --||--
  146. pBuffer[ 9] = ToAscii( 0xB2, 1 ); // auto iris + fast zoom
  147. pBuffer[10] = ToAscii( 0xB2, 0 ); // --||--
  148. bCmd = 0x02;
  149. if( pStatus->bLampsOn ) bCmd |= 0x18;
  150. if( pStatus->bWiperOn ) bCmd |= 0x40;
  151. pBuffer[11] = ToAscii( bCmd, 1 ); // digital zoom
  152. pBuffer[12] = ToAscii( bCmd, 0 ); // --||--
  153. pBuffer[13] = ToAscii( pStatus->bPanSpeed, 1 ); // pan speed
  154. pBuffer[14] = ToAscii( pStatus->bPanSpeed, 0 ); // --||--
  155. pBuffer[15] = ToAscii( pStatus->bTiltSpeed, 1 ); // unused
  156. pBuffer[16] = ToAscii( pStatus->bTiltSpeed, 0 ); // --||--
  157. return CheckSum( pBuffer, 18 );
  158. }
  159. static INT BuildSetManualControlPZ( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus, WORD wZoom )
  160. {
  161. pBuffer[ 0] = 0x0A; // line feed (header)
  162. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  163. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  164. pBuffer[ 3] = ToAscii( 24, 1 ); // length
  165. pBuffer[ 4] = ToAscii( 24, 0 ); // --||--
  166. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  167. pBuffer[ 6] = 'w'; // control code (command)
  168. BYTE bCmd = 0;
  169. if( pStatus->bPanRight ) bCmd |= 0x01;
  170. if( pStatus->bPanOn ) bCmd |= 0x02;
  171. if( pStatus->bTiltDown ) bCmd |= 0x04;
  172. if( pStatus->bTiltOn ) bCmd |= 0x08;
  173. if( pStatus->bZoomWide ) bCmd |= 0x10;
  174. if( pStatus->bZoomOn ) bCmd |= 0x20;
  175. pBuffer[ 7] = ToAscii( bCmd, 1 ); // command
  176. pBuffer[ 8] = ToAscii( bCmd, 0 ); // --||--
  177. pBuffer[ 9] = ToAscii( 0x32, 1 ); // auto iris + fast zoom
  178. pBuffer[10] = ToAscii( 0x32, 0 ); // --||--
  179. bCmd = 0x02;
  180. if( pStatus->bLampsOn ) bCmd |= 0x18;
  181. if( pStatus->bWiperOn ) bCmd |= 0x40;
  182. pBuffer[11] = ToAscii( bCmd, 1 ); // digital zoom
  183. pBuffer[12] = ToAscii( bCmd, 0 ); // --||--
  184. pBuffer[13] = ToAscii( pStatus->bPanSpeed, 1 ); // pan speed
  185. pBuffer[14] = ToAscii( pStatus->bPanSpeed, 0 ); // --||--
  186. pBuffer[15] = ToAscii( pStatus->bTiltSpeed, 1 ); // unused
  187. pBuffer[16] = ToAscii( pStatus->bTiltSpeed, 0 ); // --||--
  188. pBuffer[17] = ToAscii( wZoom, 2 ); // absolute zoom position
  189. pBuffer[18] = ToAscii( wZoom, 1 ); // --||--
  190. pBuffer[19] = ToAscii( wZoom, 0 ); // --||--
  191. pBuffer[20] = ToAscii( 0x000, 2 ); // focus position (unsupported)
  192. pBuffer[21] = ToAscii( 0x000, 1 ); // --||--
  193. pBuffer[22] = ToAscii( 0x000, 0 ); // --||--
  194. return CheckSum( pBuffer, 24 );
  195. }
  196. static INT BuildPan( LPBYTE pBuffer, BYTE bAddress, BOOL bRight, BYTE bSpeed, PCONTROL_STATUS pStatus )
  197. {
  198. pStatus->bPanOn = bSpeed ? TRUE : FALSE;
  199. pStatus->bPanRight = bRight;
  200. pStatus->bPanSpeed = bSpeed;
  201. return BuildSetManualControl( pBuffer, bAddress, pStatus );
  202. }
  203. static INT BuildTilt( LPBYTE pBuffer, BYTE bAddress, BOOL bUp, BYTE bSpeed, PCONTROL_STATUS pStatus )
  204. {
  205. pStatus->bTiltOn = bSpeed ? TRUE : FALSE;
  206. pStatus->bTiltDown = !bUp;
  207. pStatus->bTiltSpeed = bSpeed;
  208. return BuildSetManualControl( pBuffer, bAddress, pStatus );
  209. }
  210. static INT BuildZoom( LPBYTE pBuffer, BYTE bAddress, BOOL bTele, BYTE bSpeed, PCONTROL_STATUS pStatus )
  211. {
  212. pStatus->bZoomOn = bSpeed ? TRUE : FALSE;
  213. pStatus->bZoomWide = !bTele;
  214. return BuildSetManualControl( pBuffer, bAddress, pStatus );
  215. }
  216. static INT BuildSetDefaultSettings( LPBYTE pBuffer, BYTE bAddress, PCONTROL_STATUS pStatus )
  217. {
  218. memset( pStatus, 0, sizeof(CONTROL_STATUS) );
  219. return BuildSetManualControl( pBuffer, bAddress, pStatus );
  220. }
  221. static INT BuildVisca( LPBYTE pBuffer, BYTE bAddress, PBYTE pCommand, INT nCount )
  222. {
  223. pBuffer[ 0] = 0x0A; // line feed (header)
  224. pBuffer[ 1] = ToAscii( bAddress, 1 ); // address
  225. pBuffer[ 2] = ToAscii( bAddress, 0 ); // --||--
  226. nCount <<= 1;
  227. pBuffer[ 3] = ToAscii( 8 + nCount, 1 ); // length
  228. pBuffer[ 4] = ToAscii( 8 + nCount, 0 ); // --||--
  229. pBuffer[ 5] = CF_HALF_DUPLEX; // control flag
  230. pBuffer[ 6] = 'r'; // control code (command)
  231. for( INT i = 0; i < nCount; i += 2 )
  232. {
  233. pBuffer[ i + 7 ] = ToAscii( *pCommand , 1 );
  234. pBuffer[ i + 8 ] = ToAscii( *pCommand++, 0 );
  235. }
  236. return CheckSum( pBuffer, 8 + nCount );
  237. }
  238. static INT BuildSetSlowShutter( LPBYTE pBuffer, BYTE bAddress, BOOL bAuto )
  239. {
  240. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x5A, bAuto ? 0x02 : 0x03, 0xFF };
  241. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  242. }
  243. static INT BuildSetBackLight( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
  244. {
  245. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x33, bOn ? 0x02 : 0x03, 0xFF };
  246. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  247. }
  248. static INT BuildSetLowLux( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
  249. {
  250. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x01, bOn ? 0x02 : 0x03, 0xFF };
  251. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  252. }
  253. static INT BuildSetIRled( LPBYTE pBuffer, BYTE bAddress, BOOL bOn )
  254. {
  255. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x31, bOn ? 0x02 : 0x03, 0xFF };
  256. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  257. }
  258. /*
  259. static BYTE SonyChar( BYTE bAscii )
  260. {
  261. return bAscii - 'A';
  262. }
  263. static INT BuildSetTitleClear( LPBYTE pBuffer, BYTE bAddress )
  264. {
  265. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x74, 0x00, 0xFF };
  266. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  267. }
  268. static INT BuildSetTitleLowLight( LPBYTE pBuffer, BYTE bAddress )
  269. {
  270. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x01, SonyChar( 'L' ), SonyChar( 'O' ), SonyChar( 'W' ),
  271. 0x1B, SonyChar( 'L' ), SonyChar( 'I' ),
  272. SonyChar( 'G' ), SonyChar( 'H' ), SonyChar( 'T' ),
  273. 0x1B, 0xFF };
  274. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  275. }
  276. static INT BuildSetTitleNormalLight1( LPBYTE pBuffer, BYTE bAddress )
  277. {
  278. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x01, SonyChar( 'N' ), SonyChar( 'O' ), SonyChar( 'R' ),
  279. SonyChar( 'M' ), SonyChar( 'A' ), SonyChar( 'L' ),
  280. 0x1B, 0x1B, 0x1B,
  281. 0x1B, 0xFF };
  282. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  283. }
  284. static INT BuildSetTitleNormalLight2( LPBYTE pBuffer, BYTE bAddress )
  285. {
  286. BYTE pCommand[] = { 0x81, 0x01, 0x04, 0x73, 0x02, SonyChar( 'L' ), SonyChar( 'I' ), SonyChar( 'G' ),
  287. SonyChar( 'H' ), SonyChar( 'T' ), 0x1B,
  288. 0x1B, 0x1B, 0x1B,
  289. 0x1B, 0xFF };
  290. return BuildVisca( pBuffer, bAddress, pCommand, sizeof(pCommand) );
  291. }
  292. static INT BuildSetLowLight( LPBYTE pBuffer, BYTE bAddress, BOOL bLowLight, PCONTROL_STATUS pStatus )
  293. {
  294. pStatus->bLampsOn = bLowLight;
  295. if( bLowLight )
  296. {
  297. INT nCount = 0;
  298. nCount += BuildSetSlowShutter( pBuffer + nCount, bAddress, TRUE );
  299. nCount += BuildSetBackLight( pBuffer + nCount, bAddress, TRUE );
  300. nCount += BuildSetLowLux( pBuffer + nCount, bAddress, TRUE );
  301. nCount += BuildSetIRled( pBuffer + nCount, bAddress, TRUE );
  302. // nCount += BuildSetTitleClear( pBuffer + nCount, bAddress );
  303. // nCount += BuildSetTitleLowLight( pBuffer + nCount, bAddress );
  304. return nCount;
  305. }
  306. INT nCount = 0;
  307. nCount += BuildSetSlowShutter( pBuffer + nCount, bAddress, FALSE );
  308. nCount += BuildSetBackLight( pBuffer + nCount, bAddress, FALSE );
  309. nCount += BuildSetLowLux( pBuffer + nCount, bAddress, FALSE );
  310. nCount += BuildSetIRled( pBuffer + nCount, bAddress, FALSE );
  311. // nCount += BuildSetTitleClear( pBuffer + nCount, bAddress );
  312. // nCount += BuildSetTitleNormalLight1( pBuffer + nCount, bAddress );
  313. // nCount += BuildSetTitleNormalLight2( pBuffer + nCount, bAddress );
  314. return nCount;
  315. }
  316. */
  317. static INT BuildSetPictureEffect( LPBYTE pBuffer, BYTE bAddress, INT nEffect )
  318. {
  319. // picture effects
  320. BYTE pCommand[][6] =
  321. {
  322. { 0x81, 0x01, 0x04, 0x63, 0x00, 0xFF }, // no effect
  323. { 0x81, 0x01, 0x04, 0x63, 0x01, 0xFF }, // pastel effect
  324. { 0x81, 0x01, 0x04, 0x63, 0x02, 0xFF }, // negative effect
  325. { 0x81, 0x01, 0x04, 0x63, 0x03, 0xFF }, // sepia effect
  326. { 0x81, 0x01, 0x04, 0x63, 0x04, 0xFF }, // B/W effect
  327. { 0x81, 0x01, 0x04, 0x63, 0x05, 0xFF }, // solarize effect
  328. { 0x81, 0x01, 0x04, 0x63, 0x06, 0xFF }, // mosaic effect
  329. { 0x81, 0x01, 0x04, 0x63, 0x07, 0xFF }, // slim effect
  330. { 0x81, 0x01, 0x04, 0x63, 0x08, 0xFF } // stretch effect
  331. };
  332. return BuildVisca( pBuffer, bAddress, pCommand[nEffect], sizeof(pCommand[0]) );
  333. }
  334. // conversion
  335. public:
  336. // pan
  337. static CLgDevicePTZ::PTZ_DEGREE Pan2Degree( WORD wPan )
  338. {
  339. return (wPan - 0x001L) * 360L / ( 0x0FFFL - 0x001 );
  340. }
  341. static WORD Degree2Pan( CLgDevicePTZ::PTZ_DEGREE Angle )
  342. {
  343. return (WORD)( Angle * ( 0xFFFL - 0x001L ) / 360L + 0x001L );
  344. }
  345. // tilt
  346. static CLgDevicePTZ::PTZ_DEGREE Tilt2Degree( WORD wTilt )
  347. {
  348. // return ((double)wTilt - 0x484) * 360.0 / 0xFFF;
  349. return 360L - ( wTilt - 0x484L ) * 360L / 0xFFFL;
  350. }
  351. static WORD Degree2Tilt( CLgDevicePTZ::PTZ_DEGREE dAngle )
  352. {
  353. // return (WORD)(dAngle * 0xFFF / 360.0 + 0x484);
  354. return (WORD)( (360L - dAngle) * 0xFFFL / 360L + 0x484L );
  355. }
  356. // zoom
  357. static WORD Percent2Zoom( CLgDevicePTZ::PTZ_PERCENT dPercent )
  358. {
  359. return (WORD)( dPercent * 0x0923L / 100L );
  360. }
  361. static CLgDevicePTZ::PTZ_PERCENT Zoom2Percent( WORD wZoom )
  362. {
  363. return ( wZoom * 100L ) / 0x0923L;
  364. }
  365. // speed
  366. static BYTE Percent2Speed( CLgDevicePTZ::PTZ_PERCENT dPercent )
  367. {
  368. return (BYTE)( dPercent * 255L / 100L );
  369. }
  370. static CLgDevicePTZ::PTZ_PERCENT Speed2Percent( BYTE bSpeed )
  371. {
  372. return bSpeed * 100L / 255L;
  373. }
  374. // helpers
  375. public:
  376. static BYTE ToAscii( WORD wValue, BYTE nDigit )
  377. {
  378. static BYTE pHexTable[] = "0123456789ABCDEF";
  379. return pHexTable[ ( wValue >> (nDigit << 2) ) & 0x0F ];
  380. }
  381. static WORD ToValue( PBYTE pAscii, INT nCount )
  382. {
  383. WORD bValue = 0;
  384. for( INT i = 0; i < nCount; i++ )
  385. {
  386. bValue <<= 4;
  387. if( pAscii[i] >= '0' && pAscii[i] <= '9' ) bValue += (pAscii[i] - '0');
  388. else
  389. if( pAscii[i] >= 'A' && pAscii[i] <= 'F' ) bValue += (pAscii[i] - 'A' + 10);
  390. else
  391. if( pAscii[i] >= 'a' && pAscii[i] <= 'f' ) bValue += (pAscii[i] - 'a' + 10);
  392. }
  393. return bValue;
  394. }
  395. private:
  396. static INT CheckSum( LPBYTE pBuffer, INT nLength )
  397. {
  398. INT nCount = nLength - 1;
  399. PBYTE pCheckSum = pBuffer + nCount;
  400. // XOR all bytes in packet
  401. *pCheckSum = *pBuffer++;
  402. while( --nCount )
  403. *pCheckSum ^= *pBuffer++;
  404. // set top bit into '1'
  405. *pCheckSum |= 0x80;
  406. return nLength;
  407. }
  408. };
  409. #endif
  410. #ifdef __BCPLUSPLUS__
  411. #pragma warn .inl
  412. #endif