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.

670 lines
14 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolPTZ_PELCO.h"
  2. #define LOG(X) m_pLog->Log("Proto[PELCO]", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("Proto[PELCO]", this, _LOG_ERROR, X)
  4. protocolPTZ_PELCO::protocolPTZ_PELCO(config_setting_t * Settings) :
  5. protocolPTZ(),
  6. m_mInquiryMutex()
  7. {
  8. m_pLog = basicLogCollection::getInstance();
  9. m_pSettings = Settings;
  10. m_bReplyRequired = false;
  11. m_bDPlusEna = false;
  12. m_bProtocolDeviceID = 1;
  13. m_bLastCommandIssued = CMD_PTZ_NOOP;
  14. }
  15. protocolPTZ_PELCO::protocolPTZ_PELCO(uint8_t CAM_ID) :
  16. protocolPTZ(),
  17. m_mInquiryMutex()
  18. {
  19. m_pLog = basicLogCollection::getInstance();
  20. m_pSettings = NULL;
  21. m_bReplyRequired = false;
  22. m_bDPlusEna = false;
  23. m_bProtocolDeviceID = CAM_ID;
  24. m_bLastCommandIssued = CMD_PTZ_NOOP;
  25. }
  26. protocolPTZ_PELCO::~protocolPTZ_PELCO() {}
  27. U8 protocolPTZ_PELCO::finishUpPackage(U8 * pBuffer)
  28. {
  29. U8 nChecksum = 0;
  30. pBuffer[SYNC_IDX] = 0xFF;
  31. pBuffer[ADR_IDX] = m_bProtocolDeviceID;
  32. for (U8 i = ADR_IDX; i < CHKSUM_IDX; i++)
  33. {
  34. nChecksum += pBuffer[i];
  35. }
  36. pBuffer[CHKSUM_IDX] = nChecksum;
  37. return 7;
  38. }
  39. int protocolPTZ_PELCO::packetChecker(U8 * Buffer, size_t BufferSize)
  40. {
  41. if (Buffer[0] == 0xFF)
  42. {
  43. if (BufferSize > 1)
  44. {
  45. if (Buffer[1] == 0x00 || Buffer[1] == m_bProtocolDeviceID)
  46. {
  47. U8 tChSumm;
  48. // Check 4 Bytes Responce
  49. if (BufferSize > 3)
  50. {
  51. tChSumm = 0;
  52. for (U8 i = 1; i < 4; i++)
  53. {
  54. tChSumm += Buffer[i];
  55. }
  56. if (Buffer[4] == tChSumm)
  57. {
  58. #ifdef DEBUG
  59. LOG("PacketChecker: 4 Byte Packet Is Recognized");
  60. #endif
  61. return 0;
  62. };
  63. };
  64. // Check 7 Bytes Responce
  65. if (BufferSize > 6)
  66. {
  67. U8 tChSumm = 0;
  68. for (U8 i = 1; i < 6; i++)
  69. {
  70. tChSumm += Buffer[i];
  71. }
  72. if (Buffer[6] == tChSumm)
  73. {
  74. #ifdef DEBUG
  75. LOG("PacketChecker: 7 Byte Packet Is Recognized");
  76. #endif
  77. return 0;
  78. };
  79. };
  80. // Check 18 Bytes Responce
  81. if (BufferSize > 17)
  82. {
  83. U8 tChSumm = 0;
  84. for (U8 i = 1; i < 17; i++)
  85. {
  86. tChSumm += Buffer[i];
  87. }
  88. if (Buffer[17] == tChSumm)
  89. {
  90. #ifdef DEBUG
  91. LOG("PacketChecker: 18 Byte Packet Is Recognized");
  92. #endif
  93. return 0;
  94. };
  95. };
  96. }
  97. else
  98. {
  99. return -1;
  100. }
  101. };
  102. return 1;
  103. };
  104. #ifdef DEBUG
  105. LOG("PacketChecker: Packet Not Recognized");
  106. #endif
  107. return -1;
  108. }
  109. protocolPackage * protocolPTZ_PELCO::packetExtractor(unsigned char * Buffer, size_t BufferSize)
  110. {
  111. protocolPackage * RetVal;
  112. if (BufferSize < 4)
  113. {
  114. return NULL;
  115. }
  116. RetVal = (protocolPackage *) malloc(sizeof(protocolPackage));
  117. if (RetVal != NULL)
  118. {
  119. RetVal->m_pData = (U8 *) malloc(18);
  120. if (RetVal->m_pData != NULL)
  121. {
  122. U8 tChSumm = 0;
  123. U8 i;
  124. RetVal->m_pData[tChSumm] = Buffer[tChSumm];
  125. for (i = 1; i < 18; i++)
  126. {
  127. tChSumm += RetVal->m_pData[i] = Buffer[i];
  128. if ((i == 17 || i == 6 || i == 3) && (Buffer[i] == tChSumm))
  129. {
  130. RetVal->m_nSize = i + 1;
  131. return RetVal;
  132. };
  133. };
  134. free(RetVal->m_pData);
  135. };
  136. free(RetVal);
  137. };
  138. return NULL;
  139. }
  140. bool protocolPTZ_PELCO::packetHandler(protocolPackage * Package)
  141. {
  142. //U8 Com_Mode;
  143. //U8 Cat_Code;
  144. #ifdef DEBUG_EXTRA
  145. LOG("PacketHandler: Packet Is Handling");
  146. #endif
  147. //Com_Mode = Package->m_pData[1];
  148. //Cat_Code = Package->m_pData[2];
  149. m_bLastCommandIssued = CMD_PTZ_NOOP;
  150. free(Package->m_pData);
  151. free(Package);
  152. return true;
  153. }
  154. bool protocolPTZ_PELCO::create(void)
  155. {
  156. config_setting_t * pSetting;
  157. int tPort, tSpeed;
  158. m_bStatus = 0;
  159. if (! protocolPTZ::create())
  160. {
  161. return false;
  162. }
  163. if (m_oDataTransport == NULL)
  164. {
  165. LOG_ERROR("Transport Not Assigned!");
  166. return false;
  167. };
  168. if (m_pSettings != NULL)
  169. {
  170. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_COM_PORT);
  171. if (pSetting == NULL)
  172. {
  173. return false;
  174. }
  175. tPort = config_setting_get_int(pSetting);
  176. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_COM_SPEED);
  177. if (pSetting == NULL)
  178. {
  179. return false;
  180. }
  181. tSpeed = config_setting_get_int(pSetting);
  182. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_CAM_ID);
  183. if (pSetting == NULL)
  184. {
  185. return false;
  186. }
  187. m_bProtocolDeviceID = (U8) config_setting_get_int(pSetting);
  188. pSetting = config_setting_get_member(m_pSettings, PELCO_D_PLUS_ENABLE);
  189. if (pSetting != NULL)
  190. {
  191. m_bDPlusEna = (bool) config_setting_get_bool(pSetting);
  192. };
  193. char tBuf[128];
  194. #ifdef __linux__
  195. sprintf( tBuf,"/dev/ttyS%d %d",tPort, tSpeed);
  196. #else
  197. sprintf(tBuf, "com%d %d", tPort, tSpeed);
  198. #endif
  199. LOG( tBuf );
  200. /*
  201. m_oDataTransport = new serialPort(tBuf,tSpeed);
  202. if (m_oDataTransport != NULL){
  203. if (m_oDataTransport->addRecipient(this)){
  204. setConnectionStatus(CS_CONNECTED);
  205. m_bStatus = 1;
  206. return true;
  207. };
  208. };
  209. */
  210. };
  211. m_bStatus = 1;
  212. return true;
  213. }
  214. bool protocolPTZ_PELCO::initCamera(void)
  215. {
  216. return setPowerSaveMode(false);
  217. }
  218. bool protocolPTZ_PELCO::setPowerSaveMode(bool nMode)
  219. {
  220. U8 Buffer[8];
  221. if (m_bStatus == 0)
  222. {
  223. return false;
  224. }
  225. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  226. m_bPowerSave_Mode = ! nMode;
  227. m_bLastCommandIssued = (m_bPowerSave_Mode) ? CMD_PTZ_POWER_ON : CMD_PTZ_POWER_OFF;
  228. memset(Buffer, 0, 8);
  229. Buffer[DCMD1_IDX] = (m_bPowerSave_Mode) ? 0x88 : 0x08;
  230. LOG("Sending POWER ON/OFF");
  231. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  232. }
  233. bool protocolPTZ_PELCO::getPowerSaveMode(void)
  234. {
  235. U8 Buffer[16];
  236. if (m_bStatus == 0)
  237. {
  238. return false;
  239. }
  240. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  241. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  242. Buffer[1] = 0x09;
  243. Buffer[2] = 0x04;
  244. Buffer[3] = 0x00;
  245. Buffer[4] = 0xFF;
  246. m_mInquiryMutex.lock();
  247. LOG("Ask POWER mode");
  248. m_oDataTransport->sendData(Buffer, 5);
  249. m_mInquiryMutex.lock();
  250. m_mInquiryMutex.unlock();
  251. LOG("Ask POWER mode -> Done");
  252. return m_bPowerSave_Mode;
  253. }
  254. bool protocolPTZ_PELCO::startZoomWide(void)
  255. {
  256. U8 Buffer[16];
  257. if (m_bStatus == 0)
  258. {
  259. return false;
  260. }
  261. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  262. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  263. Buffer[1] = 0x01;
  264. Buffer[2] = 0x04;
  265. Buffer[3] = 0x07;
  266. Buffer[4] = 0x03;
  267. Buffer[5] = 0xFF;
  268. LOG("Start Zoom Wide(standard)");
  269. m_oDataTransport->sendData(Buffer, 6);
  270. return true;
  271. }
  272. bool protocolPTZ_PELCO::startZoomTele(void)
  273. {
  274. U8 Buffer[16];
  275. if (m_bStatus == 0)
  276. {
  277. return false;
  278. }
  279. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  280. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  281. Buffer[1] = 0x01;
  282. Buffer[2] = 0x04;
  283. Buffer[3] = 0x07;
  284. Buffer[4] = 0x02;
  285. Buffer[5] = 0xFF;
  286. LOG("Start Zoom Tele(standard)");
  287. m_oDataTransport->sendData(Buffer, 6);
  288. return true;
  289. }
  290. bool protocolPTZ_PELCO::startZoomWide(double nSpeed)
  291. {
  292. U8 Buffer[16];
  293. if (m_bStatus == 0)
  294. {
  295. return false;
  296. }
  297. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  298. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  299. Buffer[1] = 0x01;
  300. Buffer[2] = 0x04;
  301. Buffer[3] = 0x07;
  302. U8 Param;
  303. Param = ((U8) (2 + nSpeed * 5)) & 0x07;
  304. Buffer[4] = 0x30 | Param;
  305. Buffer[5] = 0xFF;
  306. LOG("Start Zoom Wide(parameter)");
  307. m_oDataTransport->sendData(Buffer, 6);
  308. return true;
  309. }
  310. bool protocolPTZ_PELCO::startZoomTele(double nSpeed)
  311. {
  312. U8 Buffer[16];
  313. if (m_bStatus == 0)
  314. {
  315. return false;
  316. }
  317. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  318. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  319. Buffer[1] = 0x01;
  320. Buffer[2] = 0x04;
  321. Buffer[3] = 0x07;
  322. U8 Param;
  323. Param = ((U8) (2 + nSpeed * 5)) & 0x07;
  324. Buffer[4] = 0x20 | Param;
  325. Buffer[5] = 0xFF;
  326. LOG("Start Zoom Tele(parameter)");
  327. m_oDataTransport->sendData(Buffer, 6);
  328. return true;
  329. }
  330. bool protocolPTZ_PELCO::stopZoom(void)
  331. {
  332. U8 Buffer[16];
  333. if (m_bStatus == 0)
  334. {
  335. return false;
  336. }
  337. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  338. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  339. Buffer[1] = 0x01;
  340. Buffer[2] = 0x04;
  341. Buffer[3] = 0x07;
  342. Buffer[4] = 0x00;
  343. Buffer[5] = 0xFF;
  344. LOG("Stop Zoom");
  345. m_oDataTransport->sendData(Buffer, 6);
  346. return true;
  347. }
  348. /*double protocolPTZ_PELCO::getZoom( void ){
  349. U8 Buffer[16];
  350. if (m_bStatus == 0) return false;
  351. if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  352. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  353. Buffer[1]=0x09;
  354. Buffer[2]=0x04;
  355. Buffer[3]=0x47;
  356. Buffer[4]=0xFF;
  357. m_mInquiryMutex.lock();
  358. LOG("Ask Zoom");
  359. m_oDataTransport->sendData( Buffer, 5 );
  360. m_mInquiryMutex.lock();
  361. m_mInquiryMutex.unlock();
  362. LOG("Ask Zoom -> Done");
  363. return m_dZoom;
  364. };
  365. */
  366. bool protocolPTZ_PELCO::resetPTZDrive(void)
  367. {
  368. U8 Buffer[16];
  369. if (m_bStatus == 0)
  370. {
  371. return false;
  372. }
  373. memset(Buffer, 0, 16);
  374. Buffer[DCMD1_IDX] = 0x00;
  375. Buffer[DCMD2_IDX] = 0x0F;
  376. Buffer[DATA1_IDX] = 0x00;
  377. Buffer[DATA2_IDX] = 0x00;
  378. LOG("Reset PTZ");
  379. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  380. }
  381. bool protocolPTZ_PELCO::goHomePosition(void)
  382. {
  383. U8 Buffer[8];
  384. if (m_bStatus == 0)
  385. {
  386. return false;
  387. }
  388. memset(Buffer, 0, 8);
  389. Buffer[DCMD2_IDX] = 0x07;
  390. Buffer[DATA2_IDX] = 0x22;
  391. LOG("Go Home");
  392. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  393. }
  394. bool protocolPTZ_PELCO::setPanPos(double dPan)
  395. {
  396. uint8_t Buffer[16];
  397. uint16_t SPan;
  398. // -1 == 0 deg ... 1 = 360 deg
  399. SPan = ((uint16_t) (18000.0 + 18000.0 * dPan)) % 36000;
  400. memset(Buffer, 0, 16);
  401. Buffer[DCMD2_IDX] = 0x4B;
  402. Buffer[DATA1_IDX] = (SPan >> 8) & 0xFF;
  403. Buffer[DATA2_IDX] = SPan & 0xFF;
  404. #ifdef DEBUG
  405. char tBuffer[64];
  406. sprintf(tBuffer, "setPanPos %.3f", dPan);
  407. LOG(tBuffer);
  408. #endif
  409. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  410. }
  411. bool protocolPTZ_PELCO::setTiltPos(double dTilt)
  412. {
  413. uint8_t Buffer[16];
  414. uint16_t STlt;
  415. // STlt = ((U16)(18000.0 + 18000.0 * ((dTilt + 1.f) / 2.f))) % 18000;
  416. STlt = ((uint16_t) (18000.0 + 18000.0 * dTilt)) % 18000;
  417. memset(Buffer, 0, 16);
  418. Buffer[DCMD2_IDX] = 0x4D;
  419. Buffer[DATA1_IDX] = (STlt >> 8) & 0xFF;
  420. Buffer[DATA2_IDX] = STlt & 0xFF;
  421. #ifdef DEBUG
  422. char tBuffer[64];
  423. sprintf(tBuffer, "setTiltPos %.3f -> %d", dTilt, STlt);
  424. LOG(tBuffer);
  425. #endif
  426. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  427. }
  428. bool protocolPTZ_PELCO::setZoom(double dZoom)
  429. {
  430. U8 Buffer[16];
  431. U16 SZum;
  432. SZum = (U16) (65535 * dZoom);
  433. memset(Buffer, 0, 16);
  434. Buffer[DCMD2_IDX] = 0x4F;
  435. Buffer[DATA1_IDX] = (SZum >> 8) & 0xFF;
  436. Buffer[DATA2_IDX] = SZum & 0xFF;
  437. #ifdef DEBUG
  438. char tBuffer[64];
  439. sprintf(tBuffer, "setZoomPos %.3f", dZoom);
  440. LOG(tBuffer);
  441. #endif
  442. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  443. }
  444. bool protocolPTZ_PELCO::move(uint32_t MoveMatrix)
  445. {
  446. U8 Buffer[16];
  447. U8 Param1, Param2;
  448. if (m_bStatus == 0)
  449. {
  450. return false;
  451. }
  452. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  453. Param1 = (U8) (m_dPanSpeed * 64.0) & 0xFF;
  454. Param2 = (U8) (m_dTiltSpeed * 64.0) & 0xFF;
  455. memset(Buffer, 0, 16);
  456. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) != 0)
  457. {
  458. if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  459. {
  460. Buffer[DCMD2_IDX] |= 0x04;
  461. }
  462. else
  463. {
  464. Buffer[DCMD2_IDX] |= 0x02;
  465. };
  466. };
  467. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) != 0)
  468. {
  469. if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  470. {
  471. Buffer[DCMD2_IDX] |= 0x08;
  472. }
  473. else
  474. {
  475. Buffer[DCMD2_IDX] |= 0x10;
  476. };
  477. };
  478. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  479. {
  480. if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  481. {
  482. Buffer[DCMD2_IDX] |= 0x40;
  483. }
  484. else
  485. {
  486. Buffer[DCMD2_IDX] |= 0x20;
  487. };
  488. };
  489. Buffer[DATA1_IDX] = Param1; // Max = 3f Turbo Pan = FF
  490. Buffer[DATA2_IDX] = Param2;
  491. LOG("Make move");
  492. bool tv = m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  493. if (tv)
  494. {
  495. SLEEP(500);
  496. }
  497. return tv;
  498. }
  499. bool protocolPTZ_PELCO::goAbsolute(float dPan, float dTilt, float dZoom)
  500. {
  501. if (m_bStatus == 0)
  502. {
  503. return false;
  504. }
  505. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  506. if (m_bDPlusEna)
  507. {
  508. U8 Buffer[16];
  509. //U8 Param1, Param2;
  510. memset(Buffer, 0, 16);
  511. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  512. Buffer[1] = 0x01;
  513. Buffer[2] = 0x06;
  514. Buffer[3] = 0x02;
  515. Buffer[4] = 0x18; // Max Pan Speed
  516. Buffer[5] = 0x14; // Max Tilt Speed
  517. uint16_t pPos, tPos;
  518. //-880 .. 880
  519. pPos = (uint16_t) (880.0 * dPan);
  520. Buffer[6] = 0x0F & (pPos >> 12);
  521. Buffer[7] = 0x0F & (pPos >> 8);
  522. Buffer[8] = 0x0F & (pPos >> 4);
  523. Buffer[9] = 0x0F & pPos;
  524. //-300 .. 300
  525. tPos = (uint16_t) (300.0 * dTilt);
  526. Buffer[10] = 0x0F & (tPos >> 12);
  527. Buffer[11] = 0x0F & (tPos >> 8);
  528. Buffer[12] = 0x0F & (tPos >> 4);
  529. Buffer[13] = 0x0F & tPos;
  530. Buffer[14] = 0xFF;
  531. LOG("ABS move");
  532. bool tv = m_oDataTransport->sendData(Buffer, 15);
  533. if (tv)
  534. {
  535. SLEEP(500);
  536. }
  537. return tv;
  538. }
  539. else
  540. {
  541. LOG("ABS move");
  542. if (setPanPos(dPan))
  543. {
  544. SLEEP(500);
  545. if (setTiltPos(dTilt))
  546. {
  547. SLEEP(500);
  548. if (setZoom(dZoom))
  549. {
  550. SLEEP(500);
  551. return true;
  552. };
  553. };
  554. };
  555. };
  556. return false;
  557. }
  558. bool protocolPTZ_PELCO::setAutoFocus(bool nMode)
  559. {
  560. m_bAutoFocus_Mode = nMode;
  561. U8 Buffer[8];
  562. if (m_bStatus == 0)
  563. {
  564. return false;
  565. }
  566. memset(Buffer, 0, 8);
  567. Buffer[DCMD2_IDX] = 0x2B;
  568. Buffer[DATA2_IDX] = (m_bAutoFocus_Mode) ? 0x01 : 0x02;
  569. LOG("setAutoFocus");
  570. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  571. }
  572. bool protocolPTZ_PELCO::setOSD(bool nMode)
  573. {
  574. U8 Buffer[16];
  575. if (m_bStatus == 0)
  576. {
  577. return false;
  578. }
  579. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  580. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  581. Buffer[1] = 0x01;
  582. Buffer[2] = 0x06;
  583. Buffer[3] = 0x06;
  584. Buffer[4] = (nMode) ? 0x02 : 0x03;
  585. Buffer[5] = 0xFF;
  586. LOG("Set On Screen Display mode");
  587. m_oDataTransport->sendData(Buffer, 6);
  588. return true;
  589. }
  590. /*
  591. bool protocolPTZ_PELCO::setPSpeed(double Speed) {
  592. m_dPanSpeed = Speed;
  593. LOG("setPanSpeed");
  594. return move(0);
  595. };
  596. bool protocolPTZ_PELCO::setTSpeed(double Speed) {
  597. m_dTiltSpeed = Speed;
  598. LOG("setTiltSpeed");
  599. return move(0);
  600. };
  601. bool protocolPTZ_PELCO::setPTZSpeed(double pSpeed, double tSpeed, double zSpeed) {
  602. m_dPanSpeed = pSpeed;
  603. m_dTiltSpeed = tSpeed;
  604. m_dZoomSpeed = zSpeed;
  605. LOG("setPTZSpeed");
  606. return move(0);
  607. };
  608. bool protocolPTZ_PELCO::setZSpeed(double Speed) {
  609. m_dZoomSpeed = Speed;
  610. U8 Buffer[8];
  611. if (m_bStatus == 0) return false;
  612. memset(Buffer, 0, 8);
  613. Buffer[DCMD2_IDX] = 0x25;
  614. U8 sValue = (U8)floor(m_dZoomSpeed * 3.f);
  615. Buffer[DATA2_IDX] = sValue;
  616. LOG("setZoomSpeed");
  617. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  618. };
  619. bool protocolPTZ_PELCO::setFSpeed(double Speed) {
  620. m_dZoomSpeed = Speed;
  621. U8 Buffer[8];
  622. if (m_bStatus == 0) return false;
  623. memset(Buffer, 0, 8);
  624. Buffer[DCMD2_IDX] = 0x27;
  625. U8 sValue = (U8)floor( m_dZoomSpeed * 3.f );
  626. Buffer[DATA2_IDX] = sValue;
  627. LOG("setFocusSpeed");
  628. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  629. };
  630. */
  631. #undef LOG
  632. #undef LOG_ERROR