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.

513 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolPTZ_BRCP.h"
  2. #include "../../hardware/uart/serialPort.h"
  3. #define LOG(X) m_pLog->Log("BRCP", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("BRCP", this, _LOG_ERROR, X)
  5. protocolPTZ_BRCP::protocolPTZ_BRCP(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. boschRCP = NULL;
  14. m_pProfile = NULL;
  15. memset(m_pDeviceURI, 0, MAX_PATH_LEN);
  16. memset(m_pUser, 0, MAX_CRED_LEN);
  17. memset(m_pPassword, 0, MAX_CRED_LEN);
  18. }
  19. protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode) :
  20. protocolPTZ(),
  21. m_mInquiryMutex()
  22. {
  23. m_pLog = basicLogCollection::getInstance();
  24. m_bLastCommandIssued = CMD_PTZ_NOOP;
  25. m_pSettings = NULL;
  26. boschRCP = NULL;
  27. m_pProfile = NULL;
  28. LOG(ip);
  29. LOG(username);
  30. LOG(password);
  31. m_bAuthMode = AuthMode;
  32. sprintf(m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode);
  33. LOG(m_pDeviceURI);
  34. if (port == 80)
  35. {
  36. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  37. }
  38. else
  39. {
  40. sprintf(m_pDeviceURI, "http://%s:%d/onvif/device_service", ip, port);
  41. }
  42. LOG(m_pDeviceURI);
  43. strncpy(m_pUser, username, MAX_CRED_LEN);
  44. strncpy(m_pPassword, password, MAX_CRED_LEN);
  45. }
  46. protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode) :
  47. protocolPTZ(),
  48. m_mInquiryMutex()
  49. {
  50. m_pLog = basicLogCollection::getInstance();
  51. m_bLastCommandIssued = CMD_PTZ_NOOP;
  52. m_pSettings = NULL;
  53. boschRCP = NULL;
  54. m_pProfile = NULL;
  55. LOG(ctl_url);
  56. LOG(username);
  57. LOG(password);
  58. m_bAuthMode = AuthMode;
  59. sprintf(m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode);
  60. LOG(m_pDeviceURI);
  61. strncpy(m_pDeviceURI, ctl_url, 250);
  62. strncpy(m_pUser, username, MAX_CRED_LEN);
  63. strncpy(m_pPassword, password, MAX_CRED_LEN);
  64. }
  65. protocolPTZ_BRCP::~protocolPTZ_BRCP() {}
  66. bool protocolPTZ_BRCP::setIPAddress(CSTR ip)
  67. {
  68. if (ip == NULL)
  69. {
  70. return false;
  71. }
  72. if (strlen(ip) == 0)
  73. {
  74. return false;
  75. }
  76. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  77. // strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  78. return true;
  79. }
  80. bool protocolPTZ_BRCP::setUsername(CSTR username)
  81. {
  82. if (username == NULL)
  83. {
  84. return false;
  85. }
  86. if (strlen(username) == 0)
  87. {
  88. return false;
  89. }
  90. strncpy(m_pUser, username, MAX_CRED_LEN);
  91. return true;
  92. }
  93. bool protocolPTZ_BRCP::setPassword(CSTR password)
  94. {
  95. if (password == NULL)
  96. {
  97. return false;
  98. }
  99. if (strlen(password) == 0)
  100. {
  101. return false;
  102. }
  103. strncpy(m_pPassword, password, MAX_CRED_LEN);
  104. return true;
  105. }
  106. bool protocolPTZ_BRCP::setAuthMode(uint8_t Mode)
  107. {
  108. m_bAuthMode = Mode;
  109. return true;
  110. }
  111. bool protocolPTZ_BRCP::create(void)
  112. {
  113. if (! protocolPTZ::create())
  114. {
  115. return false;
  116. }
  117. if (m_pSettings != NULL)
  118. {
  119. config_setting_t * pSetting;
  120. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  121. if (pSetting == NULL)
  122. {
  123. return false;
  124. }
  125. sprintf(m_pUser, "%s", config_setting_get_string(pSetting));
  126. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  127. if (pSetting == NULL)
  128. {
  129. return false;
  130. }
  131. sprintf(m_pPassword, "%s", config_setting_get_string(pSetting));
  132. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  133. if (pSetting == NULL)
  134. {
  135. return false;
  136. }
  137. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  138. };
  139. #ifdef DEBUG
  140. LOG(m_pDeviceURI);
  141. #endif
  142. if (strlen(m_pDeviceURI) < 4)
  143. {
  144. LOG_ERROR("No Device URI Is Set!");
  145. return false;
  146. };
  147. #ifdef USE_PONVIF
  148. boschRCP = new boschRCP();
  149. if (boschRCP == NULL)
  150. {
  151. LOG_ERROR("boschRCP NEW FAILURE!");
  152. m_bStatus = 0;
  153. return false;
  154. };
  155. boschRCP->setDeviceUri(m_pDeviceURI);
  156. boschRCP->setUsername(m_pUser);
  157. boschRCP->setPassword(m_pPassword);
  158. boschRCP->setAuthMode(m_bAuthMode);
  159. LOG("PROTOCREATE");
  160. if (boschRCP->create())
  161. {
  162. m_pProfile = boschRCP->getProfiles()->at(0);
  163. LOG("DONE");
  164. m_bStatus = 1;
  165. return true;
  166. } else {
  167. LOG_ERROR("pOnvif CREATE FAILURE!");
  168. delete(m_pOnVif);
  169. m_pOnVif = NULL;
  170. m_bStatus = 0;
  171. return false;
  172. };
  173. #else
  174. std::string A(m_pUser);
  175. std::string B(m_pPassword);
  176. std::string C(m_pDeviceURI);
  177. m_pDevice = new OnvifClientDevice(C, A, B);
  178. if (m_pDevice != NULL)
  179. {
  180. m_pPTZ = new OnvifClientPTZ(*m_pDevice);
  181. if (m_pPTZ != NULL)
  182. {
  183. _tptz__GetNodesResponse tNodes;
  184. int RetVal;
  185. RetVal = m_pPTZ->GetNodes(tNodes);
  186. if (RetVal == 0)
  187. {
  188. OnvifClientMedia media(*m_pDevice);
  189. _trt__GetProfilesResponse profiles;
  190. media.GetProfiles(profiles);
  191. m_pPTZToken = profiles.Profiles.at(0)->token; // PTZConfiguration->token;
  192. // m_pPTZToken = tNodes.PTZNode.at(0)->token;
  193. //_tptz__GetConfigurationOptionsResponse COResp;
  194. // int RetVal = m_pPTZ->GetConfigurationOptions(COResp, m_pToken);
  195. //_tptz__GetConfigurationResponse configResponce;
  196. // configResponce.PTZConfiguration = new tt__PTZConfiguration();
  197. // m_pPTZ->GetConfiguration(configResponce);
  198. // m_pToken = configResponce.PTZConfiguration->token;
  199. setConnectionStatus(CS_CONNECTED);
  200. m_bStatus = 1;
  201. return true;
  202. };
  203. };
  204. };
  205. #endif
  206. return false;
  207. }
  208. #ifndef USE_PONVIF
  209. bool protocolPTZ_BRCP::initCamera(void)
  210. {
  211. if (m_bStatus == 0)
  212. {
  213. return false;
  214. }
  215. // if (m_bReplyRequired) if ( m_bLastCommandIssued != CMD_PTZ_NOOP ) return false;
  216. m_bLastCommandIssued = CMD_PTZ_INIT;
  217. m_pPTZ->Initialize();
  218. return true;
  219. }
  220. #endif
  221. bool protocolPTZ_BRCP::move(uint32_t MoveMatrix)
  222. {
  223. // if( m_bStatus == 0 ) return false;
  224. #ifdef USE_PONVIF
  225. if (m_pProfile == NULL)
  226. {
  227. return false;
  228. }
  229. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  230. float Speed_x, Speed_y, Speed_z;
  231. if (MoveMatrix > 0)
  232. {
  233. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  234. {
  235. Speed_x = 0.0f;
  236. }
  237. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  238. {
  239. Speed_x = -m_dPanSpeed;
  240. }
  241. else
  242. {
  243. Speed_x = m_dPanSpeed;
  244. };
  245. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  246. {
  247. Speed_y = 0.0;
  248. }
  249. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  250. {
  251. Speed_y = m_dTiltSpeed;
  252. }
  253. else
  254. {
  255. Speed_y = -m_dTiltSpeed;
  256. };
  257. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  258. {
  259. Speed_z = 0.0;
  260. }
  261. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  262. {
  263. Speed_z = m_dZoomSpeed;
  264. }
  265. else
  266. {
  267. Speed_z = -m_dZoomSpeed;
  268. };
  269. bool res = true;
  270. if ((MoveMatrix & (PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK)) != 0)
  271. {
  272. res = m_pOnVif->ptz_ContinuousMove(m_pProfile->profiletoken, Speed_x, Speed_y);
  273. };
  274. if (res)
  275. {
  276. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  277. {
  278. res = m_pOnVif->ptz_ContinuousMoveZoom(m_pProfile->profiletoken, Speed_z);
  279. };
  280. };
  281. m_bStatus = (res) ? 1 : 0;
  282. }
  283. else
  284. {
  285. m_bStatus = (m_pOnVif->ptz_Stop(m_pProfile->profiletoken, true, true)) ? 1 : 0;
  286. };
  287. return (m_bStatus > 0);
  288. #else
  289. if (m_bStatus == 0)
  290. {
  291. return false;
  292. }
  293. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  294. _tptz__ContinuousMoveResponse ContMoveResponse;
  295. tt__PTZSpeed tSpeed;
  296. tSpeed.PanTilt = new tt__Vector2D();
  297. tSpeed.Zoom = new tt__Vector1D();
  298. LONG64 to = 1000;
  299. int RetVal;
  300. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  301. {
  302. tSpeed.PanTilt->x = 0.0;
  303. }
  304. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  305. {
  306. tSpeed.PanTilt->x = -m_dPanSpeed;
  307. }
  308. else
  309. {
  310. tSpeed.PanTilt->x = m_dPanSpeed;
  311. };
  312. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  313. {
  314. tSpeed.PanTilt->y = 0.0;
  315. }
  316. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  317. {
  318. tSpeed.PanTilt->y = m_dTiltSpeed;
  319. }
  320. else
  321. {
  322. tSpeed.PanTilt->y = -m_dTiltSpeed;
  323. };
  324. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  325. {
  326. tSpeed.Zoom->x = 0.0;
  327. }
  328. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  329. {
  330. tSpeed.Zoom->x = m_dZoomSpeed;
  331. }
  332. else
  333. {
  334. tSpeed.Zoom->x = -m_dZoomSpeed;
  335. };
  336. RetVal = m_pPTZ->ContinuousMove(ContMoveResponse, tSpeed, to, m_pPTZToken);
  337. delete(tSpeed.PanTilt);
  338. delete(tSpeed.Zoom);
  339. if (RetVal)
  340. {
  341. return false;
  342. }
  343. return true;
  344. #endif
  345. }
  346. #include <math.h>
  347. bool protocolPTZ_BRCP::waitMoveIsDone(void)
  348. {
  349. ptzStatus tVal;
  350. uint8_t TO = 12; // 3.6 second max
  351. while (m_pOnVif->ptz_GetStatus(m_pProfile->profiletoken, &tVal) && TO)
  352. {
  353. if (tVal.hasMoveStatus)
  354. {
  355. if (tVal.PanTiltIdle && tVal.ZoomIdle)
  356. {
  357. break;
  358. }
  359. }
  360. else
  361. {
  362. // if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break;
  363. };
  364. SLEEP(333);
  365. TO--;
  366. };
  367. if (TO)
  368. {
  369. #ifdef DEBUG_EXTRA
  370. LOG("Finished Move!");
  371. #endif
  372. return true;
  373. #ifdef DEBUG_EXTRA
  374. }
  375. else
  376. {
  377. LOG_ERROR("Error Fetching PTZ Status!");
  378. #endif
  379. };
  380. return false;
  381. }
  382. bool protocolPTZ_BRCP::goAbsolute(float dPan, float dTilt, float dZoom)
  383. {
  384. #ifdef USE_PONVIF
  385. // if (m_bStatus == 0) return false;
  386. #ifdef DEBUG_EXTRA
  387. LOG("ABS Move");
  388. #endif
  389. if (m_pProfile == NULL)
  390. {
  391. LOG_ERROR("No PTZ Profile!!");
  392. return false;
  393. };
  394. if (dZoom < 0.0f)
  395. {
  396. dZoom = 0.0f;
  397. }
  398. if (m_pOnVif->ptz_AbsoluteMove(m_pProfile->profiletoken, dPan, dTilt, dZoom))
  399. {
  400. };
  401. return true;
  402. #else
  403. if (m_bStatus == 0)
  404. {
  405. return false;
  406. }
  407. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  408. _tptz__AbsoluteMoveResponse AbsMoveResponse;
  409. tt__PTZSpeed tSpeed;
  410. tt__PTZVector tPos;
  411. tSpeed.PanTilt = new tt__Vector2D();
  412. tSpeed.Zoom = new tt__Vector1D();
  413. tSpeed.PanTilt->x = 1.f;
  414. tSpeed.PanTilt->y = 1.f;
  415. tSpeed.Zoom->x = 1.f;
  416. tPos.PanTilt = new tt__Vector2D();
  417. tPos.Zoom = new tt__Vector1D();
  418. tPos.PanTilt->x = dPan;
  419. tPos.PanTilt->y = dTilt;
  420. tPos.Zoom->x = dZoom;
  421. int RetVal;
  422. RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
  423. delete(tSpeed.PanTilt);
  424. delete(tSpeed.Zoom);
  425. delete(tPos.PanTilt);
  426. delete(tPos.Zoom);
  427. return true;
  428. #endif
  429. }
  430. bool protocolPTZ_BRCP::getCameraPresets(void)
  431. {
  432. LOG("GET PRESETS!");
  433. return m_pOnVif->ptz_GetPresets(m_pProfile->profiletoken);
  434. }
  435. bool protocolPTZ_BRCP::goPreset(char * PresetToken)
  436. {
  437. #ifdef USE_PONVIF
  438. // if (m_bStatus == 0) return false;
  439. #ifdef DEBUG_EXTRA
  440. LOG("Preset Move");
  441. #endif
  442. if (m_pProfile == NULL)
  443. {
  444. LOG_ERROR("No PTZ Profile!!");
  445. return false;
  446. };
  447. if (! m_pOnVif->ptz_GotoPreset(m_pProfile->profiletoken, PresetToken, 1.0f, 1.0f, 1.0f))
  448. {
  449. m_bStatus = 0;
  450. }
  451. return (m_bStatus > 0);
  452. #else
  453. if (m_bStatus == 0)
  454. {
  455. return false;
  456. }
  457. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  458. /*
  459. _tptz__AbsoluteMoveResponse AbsMoveResponse;
  460. tt__PTZSpeed tSpeed;
  461. tt__PTZVector tPos;
  462. tSpeed.PanTilt = new tt__Vector2D();
  463. tSpeed.Zoom = new tt__Vector1D();
  464. tSpeed.PanTilt->x = 1.f;
  465. tSpeed.PanTilt->y = 1.f;
  466. tSpeed.Zoom->x = 1.f;
  467. tPos.PanTilt = new tt__Vector2D();
  468. tPos.Zoom = new tt__Vector1D();
  469. tPos.PanTilt->x = dPan;
  470. tPos.PanTilt->y = dTilt;
  471. tPos.Zoom->x = dZoom;
  472. int RetVal;
  473. RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
  474. delete(tSpeed.PanTilt);
  475. delete(tSpeed.Zoom);
  476. delete(tPos.PanTilt);
  477. delete(tPos.Zoom);
  478. */
  479. return true;
  480. #endif
  481. }
  482. bool protocolPTZ_BRCP::validate()
  483. {
  484. return (m_bStatus > 0);
  485. }
  486. #undef LOG
  487. #undef LOG_ERROR