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.

348 lines
7.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
5 months ago
​
​
​
5 months ago
5 months ago
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
5 months ago
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
  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. m_pBRCP = 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. m_pBRCP = 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. m_pBRCP = 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. if (m_pBRCP) {
  67. delete( m_pBRCP );
  68. };
  69. }
  70. bool protocolPTZ_BRCP::setIPAddress(CSTR ip)
  71. {
  72. if (ip == NULL)
  73. {
  74. return false;
  75. }
  76. if (strlen(ip) == 0)
  77. {
  78. return false;
  79. }
  80. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  81. // strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  82. return true;
  83. }
  84. bool protocolPTZ_BRCP::setUsername(CSTR username)
  85. {
  86. if (username == NULL)
  87. {
  88. return false;
  89. }
  90. if (strlen(username) == 0)
  91. {
  92. return false;
  93. }
  94. strncpy(m_pUser, username, MAX_CRED_LEN);
  95. return true;
  96. }
  97. bool protocolPTZ_BRCP::setPassword(CSTR password)
  98. {
  99. if (password == NULL)
  100. {
  101. return false;
  102. }
  103. if (strlen(password) == 0)
  104. {
  105. return false;
  106. }
  107. strncpy(m_pPassword, password, MAX_CRED_LEN);
  108. return true;
  109. }
  110. bool protocolPTZ_BRCP::setAuthMode(uint8_t Mode)
  111. {
  112. m_bAuthMode = Mode;
  113. return true;
  114. }
  115. bool protocolPTZ_BRCP::create(void)
  116. {
  117. if (! protocolPTZ::create())
  118. {
  119. return false;
  120. }
  121. if (m_pSettings != NULL)
  122. {
  123. config_setting_t * pSetting;
  124. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  125. if (pSetting == NULL)
  126. {
  127. return false;
  128. }
  129. sprintf(m_pUser, "%s", config_setting_get_string(pSetting));
  130. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  131. if (pSetting == NULL)
  132. {
  133. return false;
  134. }
  135. sprintf(m_pPassword, "%s", config_setting_get_string(pSetting));
  136. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  137. if (pSetting == NULL)
  138. {
  139. return false;
  140. }
  141. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  142. };
  143. #ifdef DEBUG
  144. LOG(m_pDeviceURI);
  145. #endif
  146. if (strlen(m_pDeviceURI) < 4)
  147. {
  148. LOG_ERROR("No Device URI Is Set!");
  149. return false;
  150. };
  151. m_pBRCP = new boschRCP();
  152. if (m_pBRCP == NULL)
  153. {
  154. LOG_ERROR("boschRCP NEW FAILURE!");
  155. m_bStatus = 0;
  156. return false;
  157. };
  158. m_pBRCP->setDeviceUri(m_pDeviceURI);
  159. m_pBRCP->setUsername(m_pUser);
  160. m_pBRCP->setPassword(m_pPassword);
  161. m_pBRCP->setAuthMode(m_bAuthMode);
  162. LOG("PROTOCREATE");
  163. if (m_pBRCP->create())
  164. {
  165. //m_pProfile = m_pBRCP->getProfiles()->at(0);
  166. LOG("DONE");
  167. m_bStatus = 1;
  168. return true;
  169. } else {
  170. LOG_ERROR("boschRCP CREATE FAILURE!");
  171. delete(m_pBRCP);
  172. m_pBRCP = NULL;
  173. m_bStatus = 0;
  174. };
  175. return false;
  176. }
  177. bool protocolPTZ_BRCP::move(uint32_t MoveMatrix)
  178. {
  179. // if( m_bStatus == 0 ) return false;
  180. if (m_pProfile == NULL)
  181. {
  182. return false;
  183. }
  184. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  185. float Speed_x, Speed_y, Speed_z;
  186. if (MoveMatrix > 0)
  187. {
  188. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  189. {
  190. Speed_x = 0.0f;
  191. }
  192. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  193. {
  194. Speed_x = -m_dPanSpeed;
  195. }
  196. else
  197. {
  198. Speed_x = m_dPanSpeed;
  199. };
  200. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  201. {
  202. Speed_y = 0.0;
  203. }
  204. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  205. {
  206. Speed_y = m_dTiltSpeed;
  207. }
  208. else
  209. {
  210. Speed_y = -m_dTiltSpeed;
  211. };
  212. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  213. {
  214. Speed_z = 0.0;
  215. }
  216. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  217. {
  218. Speed_z = m_dZoomSpeed;
  219. }
  220. else
  221. {
  222. Speed_z = -m_dZoomSpeed;
  223. };
  224. bool res = true;
  225. if ((MoveMatrix & (PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK)) != 0)
  226. {
  227. res = m_pBRCP->ptz_ContinuousMove(m_pProfile->profiletoken, Speed_x, Speed_y);
  228. };
  229. if (res)
  230. {
  231. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  232. {
  233. res = m_pBRCP->ptz_ContinuousMoveZoom(m_pProfile->profiletoken, Speed_z);
  234. };
  235. };
  236. m_bStatus = (res) ? 1 : 0;
  237. }
  238. else
  239. {
  240. m_bStatus = (m_pBRCP->ptz_Stop(m_pProfile->profiletoken, true, true)) ? 1 : 0;
  241. };
  242. return (m_bStatus > 0);
  243. }
  244. #include <math.h>
  245. bool protocolPTZ_BRCP::waitMoveIsDone(void)
  246. {
  247. ptzStatus tVal;
  248. uint8_t TO = 12; // 3.6 second max
  249. while (m_pBRCP->ptz_GetStatus(m_pProfile->profiletoken, &tVal) && TO)
  250. {
  251. if (tVal.hasMoveStatus)
  252. {
  253. if (tVal.PanTiltIdle && tVal.ZoomIdle)
  254. {
  255. break;
  256. }
  257. }
  258. else
  259. {
  260. // if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break;
  261. };
  262. SLEEP(333);
  263. TO--;
  264. };
  265. if (TO)
  266. {
  267. #ifdef DEBUG_EXTRA
  268. LOG("Finished Move!");
  269. #endif
  270. return true;
  271. #ifdef DEBUG_EXTRA
  272. }
  273. else
  274. {
  275. LOG_ERROR("Error Fetching PTZ Status!");
  276. #endif
  277. };
  278. return false;
  279. }
  280. bool protocolPTZ_BRCP::goAbsolute(float dPan, float dTilt, float dZoom)
  281. {
  282. // if (m_bStatus == 0) return false;
  283. #ifdef DEBUG_EXTRA
  284. LOG("ABS Move");
  285. #endif
  286. if (m_pProfile == NULL)
  287. {
  288. LOG_ERROR("No PTZ Profile!!");
  289. return false;
  290. };
  291. if (dZoom < 0.0f)
  292. {
  293. dZoom = 0.0f;
  294. }
  295. if (m_pBRCP->ptz_AbsoluteMove(m_pProfile->profiletoken, dPan, dTilt, dZoom))
  296. {
  297. };
  298. return true;
  299. }
  300. bool protocolPTZ_BRCP::getCameraPresets(void)
  301. {
  302. LOG("GET PRESETS!");
  303. return false;//m_pBRCP->ptz_GetPresets(m_pProfile->profiletoken);
  304. }
  305. bool protocolPTZ_BRCP::goPreset(char * PresetToken)
  306. {
  307. // if (m_bStatus == 0) return false;
  308. #ifdef DEBUG_EXTRA
  309. LOG("Preset Move");
  310. #endif
  311. if (m_pProfile == NULL)
  312. {
  313. LOG_ERROR("No PTZ Profile!!");
  314. return false;
  315. };
  316. //if (! m_pBRCP->ptz_GotoPreset(m_pProfile->profiletoken, PresetToken, 1.0f, 1.0f, 1.0f))
  317. //{
  318. // m_bStatus = 0;
  319. //}
  320. return (m_bStatus > 0);
  321. }
  322. bool protocolPTZ_BRCP::validate()
  323. {
  324. return (m_bStatus > 0);
  325. }
  326. #undef LOG
  327. #undef LOG_ERROR