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.

668 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. /*
  194. char tBuf[16];
  195. #ifdef __linux__
  196. sprintf( tBuf,"/dev/ttyS%d",tPort);
  197. #else
  198. sprintf(tBuf, "com%d", tPort);
  199. #endif
  200. m_oDataTransport = new serialPort(tBuf,tSpeed);
  201. if (m_oDataTransport != NULL){
  202. if (m_oDataTransport->addRecipient(this)){
  203. setConnectionStatus(CS_CONNECTED);
  204. m_bStatus = 1;
  205. return true;
  206. };
  207. };
  208. */
  209. };
  210. m_bStatus = 1;
  211. return true;
  212. }
  213. bool protocolPTZ_PELCO::initCamera(void)
  214. {
  215. return setPowerSaveMode(false);
  216. }
  217. bool protocolPTZ_PELCO::setPowerSaveMode(bool nMode)
  218. {
  219. U8 Buffer[8];
  220. if (m_bStatus == 0)
  221. {
  222. return false;
  223. }
  224. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  225. m_bPowerSave_Mode = ! nMode;
  226. m_bLastCommandIssued = (m_bPowerSave_Mode) ? CMD_PTZ_POWER_ON : CMD_PTZ_POWER_OFF;
  227. memset(Buffer, 0, 8);
  228. Buffer[DCMD1_IDX] = (m_bPowerSave_Mode) ? 0x88 : 0x08;
  229. LOG("Sending POWER ON/OFF");
  230. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  231. }
  232. bool protocolPTZ_PELCO::getPowerSaveMode(void)
  233. {
  234. U8 Buffer[16];
  235. if (m_bStatus == 0)
  236. {
  237. return false;
  238. }
  239. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  240. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  241. Buffer[1] = 0x09;
  242. Buffer[2] = 0x04;
  243. Buffer[3] = 0x00;
  244. Buffer[4] = 0xFF;
  245. m_mInquiryMutex.lock();
  246. LOG("Ask POWER mode");
  247. m_oDataTransport->sendData(Buffer, 5);
  248. m_mInquiryMutex.lock();
  249. m_mInquiryMutex.unlock();
  250. LOG("Ask POWER mode -> Done");
  251. return m_bPowerSave_Mode;
  252. }
  253. bool protocolPTZ_PELCO::startZoomWide(void)
  254. {
  255. U8 Buffer[16];
  256. if (m_bStatus == 0)
  257. {
  258. return false;
  259. }
  260. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  261. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  262. Buffer[1] = 0x01;
  263. Buffer[2] = 0x04;
  264. Buffer[3] = 0x07;
  265. Buffer[4] = 0x03;
  266. Buffer[5] = 0xFF;
  267. LOG("Start Zoom Wide(standard)");
  268. m_oDataTransport->sendData(Buffer, 6);
  269. return true;
  270. }
  271. bool protocolPTZ_PELCO::startZoomTele(void)
  272. {
  273. U8 Buffer[16];
  274. if (m_bStatus == 0)
  275. {
  276. return false;
  277. }
  278. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  279. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  280. Buffer[1] = 0x01;
  281. Buffer[2] = 0x04;
  282. Buffer[3] = 0x07;
  283. Buffer[4] = 0x02;
  284. Buffer[5] = 0xFF;
  285. LOG("Start Zoom Tele(standard)");
  286. m_oDataTransport->sendData(Buffer, 6);
  287. return true;
  288. }
  289. bool protocolPTZ_PELCO::startZoomWide(double nSpeed)
  290. {
  291. U8 Buffer[16];
  292. if (m_bStatus == 0)
  293. {
  294. return false;
  295. }
  296. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  297. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  298. Buffer[1] = 0x01;
  299. Buffer[2] = 0x04;
  300. Buffer[3] = 0x07;
  301. U8 Param;
  302. Param = ((U8) (2 + nSpeed * 5)) & 0x07;
  303. Buffer[4] = 0x30 | Param;
  304. Buffer[5] = 0xFF;
  305. LOG("Start Zoom Wide(parameter)");
  306. m_oDataTransport->sendData(Buffer, 6);
  307. return true;
  308. }
  309. bool protocolPTZ_PELCO::startZoomTele(double nSpeed)
  310. {
  311. U8 Buffer[16];
  312. if (m_bStatus == 0)
  313. {
  314. return false;
  315. }
  316. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  317. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  318. Buffer[1] = 0x01;
  319. Buffer[2] = 0x04;
  320. Buffer[3] = 0x07;
  321. U8 Param;
  322. Param = ((U8) (2 + nSpeed * 5)) & 0x07;
  323. Buffer[4] = 0x20 | Param;
  324. Buffer[5] = 0xFF;
  325. LOG("Start Zoom Tele(parameter)");
  326. m_oDataTransport->sendData(Buffer, 6);
  327. return true;
  328. }
  329. bool protocolPTZ_PELCO::stopZoom(void)
  330. {
  331. U8 Buffer[16];
  332. if (m_bStatus == 0)
  333. {
  334. return false;
  335. }
  336. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  337. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  338. Buffer[1] = 0x01;
  339. Buffer[2] = 0x04;
  340. Buffer[3] = 0x07;
  341. Buffer[4] = 0x00;
  342. Buffer[5] = 0xFF;
  343. LOG("Stop Zoom");
  344. m_oDataTransport->sendData(Buffer, 6);
  345. return true;
  346. }
  347. /*double protocolPTZ_PELCO::getZoom( void ){
  348. U8 Buffer[16];
  349. if (m_bStatus == 0) return false;
  350. if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  351. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  352. Buffer[1]=0x09;
  353. Buffer[2]=0x04;
  354. Buffer[3]=0x47;
  355. Buffer[4]=0xFF;
  356. m_mInquiryMutex.lock();
  357. LOG("Ask Zoom");
  358. m_oDataTransport->sendData( Buffer, 5 );
  359. m_mInquiryMutex.lock();
  360. m_mInquiryMutex.unlock();
  361. LOG("Ask Zoom -> Done");
  362. return m_dZoom;
  363. };
  364. */
  365. bool protocolPTZ_PELCO::resetPTZDrive(void)
  366. {
  367. U8 Buffer[16];
  368. if (m_bStatus == 0)
  369. {
  370. return false;
  371. }
  372. memset(Buffer, 0, 16);
  373. Buffer[DCMD1_IDX] = 0x00;
  374. Buffer[DCMD2_IDX] = 0x0F;
  375. Buffer[DATA1_IDX] = 0x00;
  376. Buffer[DATA2_IDX] = 0x00;
  377. LOG("Reset PTZ");
  378. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  379. }
  380. bool protocolPTZ_PELCO::goHomePosition(void)
  381. {
  382. U8 Buffer[8];
  383. if (m_bStatus == 0)
  384. {
  385. return false;
  386. }
  387. memset(Buffer, 0, 8);
  388. Buffer[DCMD2_IDX] = 0x07;
  389. Buffer[DATA2_IDX] = 0x22;
  390. LOG("Go Home");
  391. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  392. }
  393. bool protocolPTZ_PELCO::setPanPos(double dPan)
  394. {
  395. uint8_t Buffer[16];
  396. uint16_t SPan;
  397. // -1 == 0 deg ... 1 = 360 deg
  398. SPan = ((uint16_t) (18000.0 + 18000.0 * dPan)) % 36000;
  399. memset(Buffer, 0, 16);
  400. Buffer[DCMD2_IDX] = 0x4B;
  401. Buffer[DATA1_IDX] = (SPan >> 8) & 0xFF;
  402. Buffer[DATA2_IDX] = SPan & 0xFF;
  403. #ifdef DEBUG
  404. char tBuffer[64];
  405. sprintf(tBuffer, "setPanPos %.3f", dPan);
  406. LOG(tBuffer);
  407. #endif
  408. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  409. }
  410. bool protocolPTZ_PELCO::setTiltPos(double dTilt)
  411. {
  412. uint8_t Buffer[16];
  413. uint16_t STlt;
  414. // STlt = ((U16)(18000.0 + 18000.0 * ((dTilt + 1.f) / 2.f))) % 18000;
  415. STlt = ((uint16_t) (18000.0 + 18000.0 * dTilt)) % 18000;
  416. memset(Buffer, 0, 16);
  417. Buffer[DCMD2_IDX] = 0x4D;
  418. Buffer[DATA1_IDX] = (STlt >> 8) & 0xFF;
  419. Buffer[DATA2_IDX] = STlt & 0xFF;
  420. #ifdef DEBUG
  421. char tBuffer[64];
  422. sprintf(tBuffer, "setTiltPos %.3f -> %d", dTilt, STlt);
  423. LOG(tBuffer);
  424. #endif
  425. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  426. }
  427. bool protocolPTZ_PELCO::setZoom(double dZoom)
  428. {
  429. U8 Buffer[16];
  430. U16 SZum;
  431. SZum = (U16) (65535 * dZoom);
  432. memset(Buffer, 0, 16);
  433. Buffer[DCMD2_IDX] = 0x4F;
  434. Buffer[DATA1_IDX] = (SZum >> 8) & 0xFF;
  435. Buffer[DATA2_IDX] = SZum & 0xFF;
  436. #ifdef DEBUG
  437. char tBuffer[64];
  438. sprintf(tBuffer, "setZoomPos %.3f", dZoom);
  439. LOG(tBuffer);
  440. #endif
  441. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  442. }
  443. bool protocolPTZ_PELCO::move(uint32_t MoveMatrix)
  444. {
  445. U8 Buffer[16];
  446. U8 Param1, Param2;
  447. if (m_bStatus == 0)
  448. {
  449. return false;
  450. }
  451. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  452. Param1 = (U8) (m_dPanSpeed * 64.0) & 0xFF;
  453. Param2 = (U8) (m_dTiltSpeed * 64.0) & 0xFF;
  454. memset(Buffer, 0, 16);
  455. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) != 0)
  456. {
  457. if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  458. {
  459. Buffer[DCMD2_IDX] |= 0x04;
  460. }
  461. else
  462. {
  463. Buffer[DCMD2_IDX] |= 0x02;
  464. };
  465. };
  466. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) != 0)
  467. {
  468. if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  469. {
  470. Buffer[DCMD2_IDX] |= 0x08;
  471. }
  472. else
  473. {
  474. Buffer[DCMD2_IDX] |= 0x10;
  475. };
  476. };
  477. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  478. {
  479. if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  480. {
  481. Buffer[DCMD2_IDX] |= 0x40;
  482. }
  483. else
  484. {
  485. Buffer[DCMD2_IDX] |= 0x20;
  486. };
  487. };
  488. Buffer[DATA1_IDX] = Param1; // Max = 3f Turbo Pan = FF
  489. Buffer[DATA2_IDX] = Param2;
  490. LOG("Make move");
  491. bool tv = m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  492. if (tv)
  493. {
  494. SLEEP(500);
  495. }
  496. return tv;
  497. }
  498. bool protocolPTZ_PELCO::goAbsolute(float dPan, float dTilt, float dZoom)
  499. {
  500. if (m_bStatus == 0)
  501. {
  502. return false;
  503. }
  504. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  505. if (m_bDPlusEna)
  506. {
  507. U8 Buffer[16];
  508. U8 Param1, Param2;
  509. memset(Buffer, 0, 16);
  510. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  511. Buffer[1] = 0x01;
  512. Buffer[2] = 0x06;
  513. Buffer[3] = 0x02;
  514. Buffer[4] = 0x18; // Max Pan Speed
  515. Buffer[5] = 0x14; // Max Tilt Speed
  516. uint16_t pPos, tPos;
  517. //-880 .. 880
  518. pPos = (uint16_t) (880.0 * dPan);
  519. Buffer[6] = 0x0F & (pPos >> 12);
  520. Buffer[7] = 0x0F & (pPos >> 8);
  521. Buffer[8] = 0x0F & (pPos >> 4);
  522. Buffer[9] = 0x0F & pPos;
  523. //-300 .. 300
  524. tPos = (uint16_t) (300.0 * dTilt);
  525. Buffer[10] = 0x0F & (tPos >> 12);
  526. Buffer[11] = 0x0F & (tPos >> 8);
  527. Buffer[12] = 0x0F & (tPos >> 4);
  528. Buffer[13] = 0x0F & tPos;
  529. Buffer[14] = 0xFF;
  530. LOG("ABS move");
  531. bool tv = m_oDataTransport->sendData(Buffer, 15);
  532. if (tv)
  533. {
  534. SLEEP(500);
  535. }
  536. return tv;
  537. }
  538. else
  539. {
  540. LOG("ABS move");
  541. if (setPanPos(dPan))
  542. {
  543. SLEEP(500);
  544. if (setTiltPos(dTilt))
  545. {
  546. SLEEP(500);
  547. if (setZoom(dZoom))
  548. {
  549. SLEEP(500);
  550. return true;
  551. };
  552. };
  553. };
  554. };
  555. return false;
  556. }
  557. bool protocolPTZ_PELCO::setAutoFocus(bool nMode)
  558. {
  559. m_bAutoFocus_Mode = nMode;
  560. U8 Buffer[8];
  561. if (m_bStatus == 0)
  562. {
  563. return false;
  564. }
  565. memset(Buffer, 0, 8);
  566. Buffer[DCMD2_IDX] = 0x2B;
  567. Buffer[DATA2_IDX] = (m_bAutoFocus_Mode) ? 0x01 : 0x02;
  568. LOG("setAutoFocus");
  569. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  570. }
  571. bool protocolPTZ_PELCO::setOSD(bool nMode)
  572. {
  573. U8 Buffer[16];
  574. if (m_bStatus == 0)
  575. {
  576. return false;
  577. }
  578. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  579. Buffer[0] = 0x80 + m_bProtocolDeviceID;
  580. Buffer[1] = 0x01;
  581. Buffer[2] = 0x06;
  582. Buffer[3] = 0x06;
  583. Buffer[4] = (nMode) ? 0x02 : 0x03;
  584. Buffer[5] = 0xFF;
  585. LOG("Set On Screen Display mode");
  586. m_oDataTransport->sendData(Buffer, 6);
  587. return true;
  588. }
  589. /*
  590. bool protocolPTZ_PELCO::setPSpeed(double Speed) {
  591. m_dPanSpeed = Speed;
  592. LOG("setPanSpeed");
  593. return move(0);
  594. };
  595. bool protocolPTZ_PELCO::setTSpeed(double Speed) {
  596. m_dTiltSpeed = Speed;
  597. LOG("setTiltSpeed");
  598. return move(0);
  599. };
  600. bool protocolPTZ_PELCO::setPTZSpeed(double pSpeed, double tSpeed, double zSpeed) {
  601. m_dPanSpeed = pSpeed;
  602. m_dTiltSpeed = tSpeed;
  603. m_dZoomSpeed = zSpeed;
  604. LOG("setPTZSpeed");
  605. return move(0);
  606. };
  607. bool protocolPTZ_PELCO::setZSpeed(double Speed) {
  608. m_dZoomSpeed = Speed;
  609. U8 Buffer[8];
  610. if (m_bStatus == 0) return false;
  611. memset(Buffer, 0, 8);
  612. Buffer[DCMD2_IDX] = 0x25;
  613. U8 sValue = (U8)floor(m_dZoomSpeed * 3.f);
  614. Buffer[DATA2_IDX] = sValue;
  615. LOG("setZoomSpeed");
  616. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  617. };
  618. bool protocolPTZ_PELCO::setFSpeed(double Speed) {
  619. m_dZoomSpeed = Speed;
  620. U8 Buffer[8];
  621. if (m_bStatus == 0) return false;
  622. memset(Buffer, 0, 8);
  623. Buffer[DCMD2_IDX] = 0x27;
  624. U8 sValue = (U8)floor( m_dZoomSpeed * 3.f );
  625. Buffer[DATA2_IDX] = sValue;
  626. LOG("setFocusSpeed");
  627. return m_oDataTransport->sendData(Buffer, finishUpPackage(Buffer));
  628. };
  629. */
  630. #undef LOG
  631. #undef LOG_ERROR