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.

689 lines
16 KiB

7 years ago
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
7 years ago
​
​
​
7 years ago
​
  1. #include "protocolPTZ_ONVIF.h"
  2. #include "../../hardware/uart/serialPort.h"
  3. #define LOG(X) m_pLog->Log("ONVIF", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("ONVIF", this, _LOG_ERROR, X)
  5. protocolPTZ_ONVIF::protocolPTZ_ONVIF(config_setting_t * Settings) :
  6. protocolPTZ(),
  7. m_mInquiryMutex()
  8. {
  9. m_pLog = basicLogCollection::getInstance();
  10. m_bLastCommandIssued = CMD_PTZ_NOOP;
  11. m_pSettings = Settings;
  12. m_bAuthMode = 0;
  13. #ifdef USE_PONVIF
  14. m_pOnVif = NULL;
  15. m_pProfile = NULL;
  16. m_bReportsMoveStatus = false;
  17. m_bReportsPosition = false;
  18. m_bTargetValid = false;
  19. m_fTargetPan = 0.0f;
  20. m_fTargetTilt = 0.0f;
  21. m_fTargetZoom = 0.0f;
  22. #else
  23. m_pDevice = NULL;
  24. m_pPTZ = NULL;
  25. #endif
  26. memset(m_pDeviceURI, 0, MAX_PATH_LEN);
  27. memset(m_pUser, 0, MAX_CRED_LEN);
  28. memset(m_pPassword, 0, MAX_CRED_LEN);
  29. }
  30. protocolPTZ_ONVIF::protocolPTZ_ONVIF(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode) :
  31. protocolPTZ(),
  32. m_mInquiryMutex()
  33. {
  34. m_pLog = basicLogCollection::getInstance();
  35. m_bLastCommandIssued = CMD_PTZ_NOOP;
  36. m_pSettings = NULL;
  37. #ifdef USE_PONVIF
  38. m_pOnVif = NULL;
  39. m_pProfile = NULL;
  40. m_bReportsMoveStatus = false;
  41. m_bReportsPosition = false;
  42. m_bTargetValid = false;
  43. m_fTargetPan = 0.0f;
  44. m_fTargetTilt = 0.0f;
  45. m_fTargetZoom = 0.0f;
  46. #else
  47. m_pDevice = NULL;
  48. m_pPTZ = NULL;
  49. #endif
  50. LOG(ip);
  51. LOG(username);
  52. LOG(password);
  53. m_bAuthMode = AuthMode;
  54. sprintf(m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode);
  55. LOG(m_pDeviceURI);
  56. if (port == 80)
  57. {
  58. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  59. }
  60. else
  61. {
  62. sprintf(m_pDeviceURI, "http://%s:%d/onvif/device_service", ip, port);
  63. }
  64. LOG(m_pDeviceURI);
  65. strncpy(m_pUser, username, MAX_CRED_LEN);
  66. strncpy(m_pPassword, password, MAX_CRED_LEN);
  67. }
  68. protocolPTZ_ONVIF::protocolPTZ_ONVIF(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode) :
  69. protocolPTZ(),
  70. m_mInquiryMutex()
  71. {
  72. m_pLog = basicLogCollection::getInstance();
  73. m_bLastCommandIssued = CMD_PTZ_NOOP;
  74. m_pSettings = NULL;
  75. #ifdef USE_PONVIF
  76. m_pOnVif = NULL;
  77. m_pProfile = NULL;
  78. m_bReportsMoveStatus = false;
  79. m_bReportsPosition = false;
  80. m_bTargetValid = false;
  81. m_fTargetPan = 0.0f;
  82. m_fTargetTilt = 0.0f;
  83. m_fTargetZoom = 0.0f;
  84. #else
  85. m_pDevice = NULL;
  86. m_pPTZ = NULL;
  87. #endif
  88. LOG(ctl_url);
  89. LOG(username);
  90. LOG(password);
  91. m_bAuthMode = AuthMode;
  92. sprintf(m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode);
  93. LOG(m_pDeviceURI);
  94. strncpy(m_pDeviceURI, ctl_url, 250);
  95. strncpy(m_pUser, username, MAX_CRED_LEN);
  96. strncpy(m_pPassword, password, MAX_CRED_LEN);
  97. }
  98. protocolPTZ_ONVIF::~protocolPTZ_ONVIF() {}
  99. bool protocolPTZ_ONVIF::setIPAddress(CSTR ip)
  100. {
  101. if (ip == NULL)
  102. {
  103. return false;
  104. }
  105. if (strlen(ip) == 0)
  106. {
  107. return false;
  108. }
  109. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  110. // strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  111. return true;
  112. }
  113. bool protocolPTZ_ONVIF::setUsername(CSTR username)
  114. {
  115. if (username == NULL)
  116. {
  117. return false;
  118. }
  119. if (strlen(username) == 0)
  120. {
  121. return false;
  122. }
  123. strncpy(m_pUser, username, MAX_CRED_LEN);
  124. return true;
  125. }
  126. bool protocolPTZ_ONVIF::setPassword(CSTR password)
  127. {
  128. if (password == NULL)
  129. {
  130. return false;
  131. }
  132. if (strlen(password) == 0)
  133. {
  134. return false;
  135. }
  136. strncpy(m_pPassword, password, MAX_CRED_LEN);
  137. return true;
  138. }
  139. bool protocolPTZ_ONVIF::setAuthMode(uint8_t Mode)
  140. {
  141. m_bAuthMode = Mode;
  142. return true;
  143. }
  144. bool protocolPTZ_ONVIF::create(void)
  145. {
  146. if (! protocolPTZ::create())
  147. {
  148. return false;
  149. }
  150. if (m_pSettings != NULL)
  151. {
  152. config_setting_t * pSetting;
  153. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  154. if (pSetting == NULL)
  155. {
  156. return false;
  157. }
  158. sprintf(m_pUser, "%s", config_setting_get_string(pSetting));
  159. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  160. if (pSetting == NULL)
  161. {
  162. return false;
  163. }
  164. sprintf(m_pPassword, "%s", config_setting_get_string(pSetting));
  165. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  166. if (pSetting == NULL)
  167. {
  168. return false;
  169. }
  170. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  171. };
  172. #ifdef DEBUG
  173. LOG(m_pDeviceURI);
  174. #endif
  175. if (strlen(m_pDeviceURI) < 4)
  176. {
  177. LOG_ERROR("No Device URI Is Set!");
  178. return false;
  179. };
  180. #ifdef USE_PONVIF
  181. m_pOnVif = new pOnvif();
  182. if (m_pOnVif == NULL)
  183. {
  184. LOG_ERROR("pOnvif NEW FAILURE!");
  185. m_bStatus = 0;
  186. return false;
  187. };
  188. m_pOnVif->setDeviceUri(m_pDeviceURI);
  189. m_pOnVif->setUsername(m_pUser);
  190. m_pOnVif->setPassword(m_pPassword);
  191. m_pOnVif->setAuthMode(m_bAuthMode);
  192. LOG("PROTOCREATE");
  193. if (m_pOnVif->create())
  194. {
  195. m_pProfile = m_pOnVif->getProfiles()->at(0);
  196. detectStatusSupport();
  197. LOG("DONE");
  198. m_bStatus = 1;
  199. return true;
  200. }
  201. else
  202. {
  203. LOG_ERROR("pOnvif CREATE FAILURE!");
  204. delete(m_pOnVif);
  205. m_pOnVif = NULL;
  206. m_bStatus = 0;
  207. return false;
  208. };
  209. #else
  210. std::string A(m_pUser);
  211. std::string B(m_pPassword);
  212. std::string C(m_pDeviceURI);
  213. m_pDevice = new OnvifClientDevice(C, A, B);
  214. if (m_pDevice != NULL)
  215. {
  216. m_pPTZ = new OnvifClientPTZ(*m_pDevice);
  217. if (m_pPTZ != NULL)
  218. {
  219. _tptz__GetNodesResponse tNodes;
  220. int RetVal;
  221. RetVal = m_pPTZ->GetNodes(tNodes);
  222. if (RetVal == 0)
  223. {
  224. OnvifClientMedia media(*m_pDevice);
  225. _trt__GetProfilesResponse profiles;
  226. media.GetProfiles(profiles);
  227. m_pPTZToken = profiles.Profiles.at(0)->token; // PTZConfiguration->token;
  228. // m_pPTZToken = tNodes.PTZNode.at(0)->token;
  229. //_tptz__GetConfigurationOptionsResponse COResp;
  230. // int RetVal = m_pPTZ->GetConfigurationOptions(COResp, m_pToken);
  231. //_tptz__GetConfigurationResponse configResponce;
  232. // configResponce.PTZConfiguration = new tt__PTZConfiguration();
  233. // m_pPTZ->GetConfiguration(configResponce);
  234. // m_pToken = configResponce.PTZConfiguration->token;
  235. setConnectionStatus(CS_CONNECTED);
  236. m_bStatus = 1;
  237. return true;
  238. };
  239. };
  240. };
  241. #endif
  242. return false;
  243. }
  244. #ifndef USE_PONVIF
  245. bool protocolPTZ_ONVIF::initCamera(void)
  246. {
  247. if (m_bStatus == 0)
  248. {
  249. return false;
  250. }
  251. // if (m_bReplyRequired) if ( m_bLastCommandIssued != CMD_PTZ_NOOP ) return false;
  252. m_bLastCommandIssued = CMD_PTZ_INIT;
  253. m_pPTZ->Initialize();
  254. return true;
  255. }
  256. #endif
  257. bool protocolPTZ_ONVIF::move(uint32_t MoveMatrix)
  258. {
  259. // if( m_bStatus == 0 ) return false;
  260. #ifdef USE_PONVIF
  261. if (m_pProfile == NULL)
  262. {
  263. return false;
  264. }
  265. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  266. float Speed_x, Speed_y, Speed_z;
  267. if (MoveMatrix > 0)
  268. {
  269. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  270. {
  271. Speed_x = 0.0f;
  272. }
  273. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  274. {
  275. Speed_x = -m_dPanSpeed;
  276. }
  277. else
  278. {
  279. Speed_x = m_dPanSpeed;
  280. };
  281. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  282. {
  283. Speed_y = 0.0;
  284. }
  285. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  286. {
  287. Speed_y = m_dTiltSpeed;
  288. }
  289. else
  290. {
  291. Speed_y = -m_dTiltSpeed;
  292. };
  293. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  294. {
  295. Speed_z = 0.0;
  296. }
  297. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  298. {
  299. Speed_z = m_dZoomSpeed;
  300. }
  301. else
  302. {
  303. Speed_z = -m_dZoomSpeed;
  304. };
  305. bool res = true;
  306. if ((MoveMatrix & (PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK)) != 0)
  307. {
  308. res = m_pOnVif->ptz_ContinuousMove(m_pProfile->profiletoken, Speed_x, Speed_y);
  309. };
  310. if (res)
  311. {
  312. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  313. {
  314. res = m_pOnVif->ptz_ContinuousMoveZoom(m_pProfile->profiletoken, Speed_z);
  315. };
  316. };
  317. m_bStatus = (res) ? 1 : 0;
  318. }
  319. else
  320. {
  321. m_bStatus = (m_pOnVif->ptz_Stop(m_pProfile->profiletoken, true, true)) ? 1 : 0;
  322. };
  323. return (m_bStatus > 0);
  324. #else
  325. if (m_bStatus == 0)
  326. {
  327. return false;
  328. }
  329. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  330. _tptz__ContinuousMoveResponse ContMoveResponse;
  331. tt__PTZSpeed tSpeed;
  332. tSpeed.PanTilt = new tt__Vector2D();
  333. tSpeed.Zoom = new tt__Vector1D();
  334. LONG64 to = 1000;
  335. int RetVal;
  336. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  337. {
  338. tSpeed.PanTilt->x = 0.0;
  339. }
  340. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  341. {
  342. tSpeed.PanTilt->x = -m_dPanSpeed;
  343. }
  344. else
  345. {
  346. tSpeed.PanTilt->x = m_dPanSpeed;
  347. };
  348. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  349. {
  350. tSpeed.PanTilt->y = 0.0;
  351. }
  352. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  353. {
  354. tSpeed.PanTilt->y = m_dTiltSpeed;
  355. }
  356. else
  357. {
  358. tSpeed.PanTilt->y = -m_dTiltSpeed;
  359. };
  360. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  361. {
  362. tSpeed.Zoom->x = 0.0;
  363. }
  364. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  365. {
  366. tSpeed.Zoom->x = m_dZoomSpeed;
  367. }
  368. else
  369. {
  370. tSpeed.Zoom->x = -m_dZoomSpeed;
  371. };
  372. RetVal = m_pPTZ->ContinuousMove(ContMoveResponse, tSpeed, to, m_pPTZToken);
  373. delete(tSpeed.PanTilt);
  374. delete(tSpeed.Zoom);
  375. if (RetVal)
  376. {
  377. return false;
  378. }
  379. return true;
  380. #endif
  381. }
  382. #include <math.h>
  383. #include <time.h>
  384. #ifdef USE_PONVIF
  385. static long ptzOnvifNowMs(void)
  386. {
  387. struct timespec tTS;
  388. clock_gettime(CLOCK_MONOTONIC, &tTS);
  389. return (long) tTS.tv_sec * 1000L + tTS.tv_nsec / 1000000L;
  390. }
  391. // Pan in the generic space wraps around (-1 == +1 on 360 degree cameras)
  392. static float ptzOnvifPanDistance(float a, float b)
  393. {
  394. float d = fabsf(a - b);
  395. if (d > 1.0f)
  396. {
  397. d = 2.0f - d;
  398. }
  399. return d;
  400. }
  401. /*
  402. Finds out once (after create) how the end of a move can be detected for this camera.
  403. The PTZ service capabilities (MoveStatus / StatusPosition attributes) are asked first; many cameras
  404. don't implement GetServiceCapabilities or leave the attributes out, so a real GetStatus decides.
  405. An explicit "false" in the capabilities wins over a GetStatus reply (some cameras send fixed values).
  406. */
  407. void protocolPTZ_ONVIF::detectStatusSupport(void)
  408. {
  409. m_bReportsMoveStatus = false;
  410. m_bReportsPosition = false;
  411. if (m_pOnVif == NULL || m_pProfile == NULL)
  412. {
  413. return;
  414. }
  415. int8_t capMoveStatus = -1;
  416. int8_t capStatusPosition = -1;
  417. m_pOnVif->ptz_GetServiceCapabilities(&capMoveStatus, &capStatusPosition);
  418. ptzStatus tVal;
  419. bool tProbe = m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal);
  420. m_bReportsMoveStatus = tProbe && tVal.hasMoveStatus && (capMoveStatus != 0);
  421. m_bReportsPosition = tProbe && tVal.hasPosition && (capStatusPosition != 0);
  422. char tB[256];
  423. snprintf(tB, sizeof(tB), "PTZ status support: MoveStatus=%s Position=%s (GetStatus %s, capabilities MoveStatus=%d StatusPosition=%d) -> %s",
  424. m_bReportsMoveStatus ? "yes" : "no", m_bReportsPosition ? "yes" : "no", tProbe ? "ok" : "failed", capMoveStatus, capStatusPosition,
  425. m_bReportsMoveStatus ? "wait for IDLE" : (m_bReportsPosition ? "wait for position" : "fixed wait"));
  426. LOG(tB);
  427. }
  428. bool protocolPTZ_ONVIF::fixedMoveWait(long alreadyWaitedMs)
  429. {
  430. long tRest = PTZ_ONVIF_FIXED_MOVE_WAIT_MS - alreadyWaitedMs;
  431. if (tRest > 0)
  432. {
  433. SLEEP(tRest);
  434. }
  435. return true;
  436. }
  437. /*
  438. Blocks until the last AbsoluteMove is finished (see the strategy at the top of protocolPTZ_ONVIF.h).
  439. Returns true when the move is over (or after the fixed wait / timeout), false only if there is no
  440. PTZ connection at all.
  441. */
  442. bool protocolPTZ_ONVIF::waitMoveIsDone(void)
  443. {
  444. if (m_pOnVif == NULL || m_pProfile == NULL)
  445. {
  446. return false;
  447. }
  448. if (! m_bReportsMoveStatus && ! m_bReportsPosition)
  449. {
  450. return fixedMoveWait(0);
  451. }
  452. long tStart = ptzOnvifNowMs();
  453. int tFailures = 0;
  454. bool tSeenMoving = false;
  455. bool tHavePrev = false;
  456. int tStableCount = 0;
  457. float tPrevPan = 0.0f;
  458. float tPrevTilt = 0.0f;
  459. float tPrevZoom = 0.0f;
  460. char tB[256];
  461. for (;;)
  462. {
  463. long tElapsed = ptzOnvifNowMs() - tStart;
  464. if (tElapsed >= PTZ_ONVIF_MOVE_TIMEOUT_MS)
  465. {
  466. LOG_ERROR("Timeout waiting for the end of the PTZ move!");
  467. return true;
  468. };
  469. ptzStatus tVal;
  470. if (! m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal))
  471. {
  472. if (++tFailures >= PTZ_ONVIF_MAX_STATUS_FAILURES)
  473. {
  474. LOG_ERROR("GetStatus keeps failing, falling back to the fixed wait");
  475. return fixedMoveWait(ptzOnvifNowMs() - tStart);
  476. };
  477. SLEEP(PTZ_ONVIF_STATUS_POLL_MS);
  478. continue;
  479. };
  480. tFailures = 0;
  481. bool tNear = false;
  482. bool tStable = false;
  483. if (m_bReportsPosition && tVal.hasPosition)
  484. {
  485. tNear = m_bTargetValid && (ptzOnvifPanDistance(tVal.pan, m_fTargetPan) <= PTZ_ONVIF_POS_TOLERANCE) &&
  486. (fabsf(tVal.tilt - m_fTargetTilt) <= PTZ_ONVIF_POS_TOLERANCE) &&
  487. (! tVal.hasZoomPosition || fabsf(tVal.zoom - m_fTargetZoom) <= PTZ_ONVIF_POS_TOLERANCE);
  488. if (tHavePrev && ptzOnvifPanDistance(tVal.pan, tPrevPan) < PTZ_ONVIF_POS_STABLE_EPS && fabsf(tVal.tilt - tPrevTilt) < PTZ_ONVIF_POS_STABLE_EPS &&
  489. fabsf(tVal.zoom - tPrevZoom) < PTZ_ONVIF_POS_STABLE_EPS)
  490. {
  491. tStableCount++;
  492. }
  493. else
  494. {
  495. tStableCount = 0;
  496. };
  497. tPrevPan = tVal.pan;
  498. tPrevTilt = tVal.tilt;
  499. tPrevZoom = tVal.zoom;
  500. tHavePrev = true;
  501. tStable = (tStableCount >= PTZ_ONVIF_POS_STABLE_POLLS);
  502. };
  503. bool tAfterGrace = (tElapsed >= PTZ_ONVIF_MOVE_START_GRACE_MS);
  504. bool tDone = false;
  505. if (m_bReportsMoveStatus && tVal.hasMoveStatus)
  506. {
  507. // Right after the command a camera may still say IDLE: accept IDLE once it was seen
  508. // moving, once the target is reached, or after the start grace time.
  509. if (tVal.isMoving)
  510. {
  511. tSeenMoving = true;
  512. }
  513. else if (tSeenMoving || tNear || tAfterGrace)
  514. {
  515. tDone = true;
  516. };
  517. }
  518. else if (m_bReportsPosition && tVal.hasPosition)
  519. {
  520. tDone = tNear || (tStable && tAfterGrace);
  521. }
  522. else
  523. {
  524. // This reply carries neither MoveStatus nor Position
  525. return fixedMoveWait(tElapsed);
  526. };
  527. if (tDone)
  528. {
  529. #ifdef DEBUG_EXTRA
  530. snprintf(tB, sizeof(tB), "Finished Move in %ld ms (pos %.3f %.3f %.3f)", ptzOnvifNowMs() - tStart, tVal.pan, tVal.tilt, tVal.zoom);
  531. LOG(tB);
  532. #else
  533. (void) tB;
  534. #endif
  535. return true;
  536. };
  537. SLEEP(PTZ_ONVIF_STATUS_POLL_MS);
  538. };
  539. }
  540. #else
  541. bool protocolPTZ_ONVIF::waitMoveIsDone(void)
  542. {
  543. return false;
  544. }
  545. #endif
  546. bool protocolPTZ_ONVIF::goAbsolute(float dPan, float dTilt, float dZoom)
  547. {
  548. #ifdef USE_PONVIF
  549. // if (m_bStatus == 0) return false;
  550. #ifdef DEBUG_EXTRA
  551. LOG("ABS Move");
  552. #endif
  553. if (m_pProfile == NULL)
  554. {
  555. LOG_ERROR("No PTZ Profile!!");
  556. return false;
  557. };
  558. if (dZoom < 0.0f)
  559. {
  560. dZoom = 0.0f;
  561. }
  562. // Remember the target for waitMoveIsDone()
  563. m_fTargetPan = dPan;
  564. m_fTargetTilt = dTilt;
  565. m_fTargetZoom = dZoom;
  566. m_bTargetValid = true;
  567. if (m_pOnVif->ptz_AbsoluteMove(m_pProfile->profiletoken, dPan, dTilt, dZoom))
  568. {
  569. };
  570. return true;
  571. #else
  572. if (m_bStatus == 0)
  573. {
  574. return false;
  575. }
  576. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  577. _tptz__AbsoluteMoveResponse AbsMoveResponse;
  578. tt__PTZSpeed tSpeed;
  579. tt__PTZVector tPos;
  580. tSpeed.PanTilt = new tt__Vector2D();
  581. tSpeed.Zoom = new tt__Vector1D();
  582. tSpeed.PanTilt->x = 1.f;
  583. tSpeed.PanTilt->y = 1.f;
  584. tSpeed.Zoom->x = 1.f;
  585. tPos.PanTilt = new tt__Vector2D();
  586. tPos.Zoom = new tt__Vector1D();
  587. tPos.PanTilt->x = dPan;
  588. tPos.PanTilt->y = dTilt;
  589. tPos.Zoom->x = dZoom;
  590. int RetVal;
  591. RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
  592. delete(tSpeed.PanTilt);
  593. delete(tSpeed.Zoom);
  594. delete(tPos.PanTilt);
  595. delete(tPos.Zoom);
  596. return true;
  597. #endif
  598. }
  599. bool protocolPTZ_ONVIF::getCameraPresets(void)
  600. {
  601. LOG("GET PRESETS!");
  602. return m_pOnVif->ptz_GetPresets(m_pProfile->profiletoken);
  603. }
  604. bool protocolPTZ_ONVIF::goPreset(char * PresetToken)
  605. {
  606. #ifdef USE_PONVIF
  607. // if (m_bStatus == 0) return false;
  608. #ifdef DEBUG_EXTRA
  609. LOG("Preset Move");
  610. #endif
  611. if (m_pProfile == NULL)
  612. {
  613. LOG_ERROR("No PTZ Profile!!");
  614. return false;
  615. };
  616. // A preset move has no known target: waitMoveIsDone() must not compare with an old AbsoluteMove target
  617. m_bTargetValid = false;
  618. if (! m_pOnVif->ptz_GotoPreset(m_pProfile->profiletoken, PresetToken, 1.0f, 1.0f, 1.0f))
  619. {
  620. m_bStatus = 0;
  621. }
  622. return (m_bStatus > 0);
  623. #else
  624. if (m_bStatus == 0)
  625. {
  626. return false;
  627. }
  628. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  629. /*
  630. _tptz__AbsoluteMoveResponse AbsMoveResponse;
  631. tt__PTZSpeed tSpeed;
  632. tt__PTZVector tPos;
  633. tSpeed.PanTilt = new tt__Vector2D();
  634. tSpeed.Zoom = new tt__Vector1D();
  635. tSpeed.PanTilt->x = 1.f;
  636. tSpeed.PanTilt->y = 1.f;
  637. tSpeed.Zoom->x = 1.f;
  638. tPos.PanTilt = new tt__Vector2D();
  639. tPos.Zoom = new tt__Vector1D();
  640. tPos.PanTilt->x = dPan;
  641. tPos.PanTilt->y = dTilt;
  642. tPos.Zoom->x = dZoom;
  643. int RetVal;
  644. RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
  645. delete(tSpeed.PanTilt);
  646. delete(tSpeed.Zoom);
  647. delete(tPos.PanTilt);
  648. delete(tPos.Zoom);
  649. */
  650. return true;
  651. #endif
  652. }
  653. bool protocolPTZ_ONVIF::validate()
  654. {
  655. return (m_bStatus > 0);
  656. }
  657. #undef LOG
  658. #undef LOG_ERROR