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.

266 lines
6.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
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. memset(m_pDeviceURI, 0, MAX_PATH_LEN);
  15. memset(m_pUser, 0, MAX_CRED_LEN);
  16. memset(m_pPassword, 0, MAX_CRED_LEN);
  17. }
  18. protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode) :
  19. protocolPTZ(),
  20. m_mInquiryMutex()
  21. {
  22. m_pLog = basicLogCollection::getInstance();
  23. m_bLastCommandIssued = CMD_PTZ_NOOP;
  24. m_pSettings = NULL;
  25. m_pBRCP = NULL;
  26. LOG(ip);
  27. LOG(username);
  28. LOG(password);
  29. m_bAuthMode = AuthMode;
  30. sprintf(m_pDeviceURI, "M Auth Mode: [%d]", m_bAuthMode);
  31. LOG( m_pDeviceURI );
  32. if (port == 80){
  33. sprintf(m_pDeviceURI, "%s", ip );
  34. } else {
  35. sprintf(m_pDeviceURI, "%s:%d", ip, port );
  36. };
  37. LOG( m_pDeviceURI );
  38. memset( m_pUser, 0, MAX_CRED_LEN);
  39. strncpy(m_pUser, username, MAX_CRED_LEN);
  40. memset( m_pPassword, 0, MAX_CRED_LEN);
  41. strncpy(m_pPassword, password, MAX_CRED_LEN);
  42. }
  43. protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode) :
  44. protocolPTZ(),
  45. m_mInquiryMutex()
  46. {
  47. m_pLog = basicLogCollection::getInstance();
  48. m_bLastCommandIssued = CMD_PTZ_NOOP;
  49. m_pSettings = NULL;
  50. m_pBRCP = NULL;
  51. LOG(ctl_url);
  52. LOG(username);
  53. LOG(password);
  54. m_bAuthMode = AuthMode;
  55. sprintf(m_pDeviceURI, "Ex Auth Mode: [%d]", m_bAuthMode);
  56. LOG( m_pDeviceURI );
  57. strncpy( m_pDeviceURI, ctl_url, MAX_CRED_LEN );
  58. strncpy( m_pUser, username, MAX_CRED_LEN);
  59. strncpy( m_pPassword, password, MAX_CRED_LEN);
  60. }
  61. protocolPTZ_BRCP::~protocolPTZ_BRCP(){
  62. if (m_pBRCP) {
  63. delete( m_pBRCP );
  64. };
  65. }
  66. bool protocolPTZ_BRCP::setIPAddress(CSTR ip){
  67. if (ip == NULL) return false;
  68. if (strlen(ip) == 0) return false;
  69. sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
  70. // strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  71. return true;
  72. }
  73. bool protocolPTZ_BRCP::setUsername(CSTR username){
  74. if (username == NULL) return false;
  75. if (strlen(username) == 0) return false;
  76. strncpy(m_pUser, username, MAX_CRED_LEN);
  77. return true;
  78. }
  79. bool protocolPTZ_BRCP::setPassword(CSTR password){
  80. if (password == NULL) return false;
  81. if (strlen(password) == 0) return false;
  82. strncpy(m_pPassword, password, MAX_CRED_LEN);
  83. return true;
  84. }
  85. bool protocolPTZ_BRCP::setAuthMode(uint8_t Mode){
  86. m_bAuthMode = Mode;
  87. return true;
  88. }
  89. bool protocolPTZ_BRCP::create(void){
  90. if (! protocolPTZ::create()) return false;
  91. if (m_pSettings != NULL){
  92. config_setting_t * pSetting;
  93. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  94. if (pSetting == NULL) return false;
  95. sprintf(m_pUser, "%s", config_setting_get_string(pSetting));
  96. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  97. if (pSetting == NULL) return false;
  98. sprintf(m_pPassword, "%s", config_setting_get_string(pSetting));
  99. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  100. if (pSetting == NULL) return false;
  101. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  102. };
  103. #ifdef DEBUG
  104. LOG(m_pDeviceURI);
  105. #endif
  106. if( strlen(m_pDeviceURI) < 4 ){
  107. LOG_ERROR("No Device URI Is Set!");
  108. return false;
  109. };
  110. m_pBRCP = new boschRCP();
  111. if( m_pBRCP == NULL ){
  112. LOG_ERROR("boschRCP NEW FAILURE!");
  113. m_bStatus = 0;
  114. return false;
  115. };
  116. m_pBRCP->setDeviceUri(m_pDeviceURI);
  117. m_pBRCP->setUsername(m_pUser);
  118. m_pBRCP->setPassword(m_pPassword);
  119. m_pBRCP->setAuthMode(m_bAuthMode);
  120. LOG("PROTOCREATE");
  121. if( m_pBRCP->create() ){
  122. LOG("DONE");
  123. m_bStatus = 1;
  124. return true;
  125. } else {
  126. LOG_ERROR("bosch RCP+ CREATE FAILURE!");
  127. delete(m_pBRCP);
  128. m_pBRCP = NULL;
  129. m_bStatus = 0;
  130. };
  131. return false;
  132. }
  133. bool protocolPTZ_BRCP::move(uint32_t MoveMatrix)
  134. {
  135. // if( m_bStatus == 0 ) return false;
  136. // if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  137. float Speed_x, Speed_y, Speed_z;
  138. if (MoveMatrix > 0)
  139. {
  140. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0)
  141. {
  142. Speed_x = 0.0f;
  143. }
  144. else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0)
  145. {
  146. Speed_x = -m_dPanSpeed;
  147. }
  148. else
  149. {
  150. Speed_x = m_dPanSpeed;
  151. };
  152. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0)
  153. {
  154. Speed_y = 0.0;
  155. }
  156. else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0)
  157. {
  158. Speed_y = m_dTiltSpeed;
  159. }
  160. else
  161. {
  162. Speed_y = -m_dTiltSpeed;
  163. };
  164. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0)
  165. {
  166. Speed_z = 0.0;
  167. }
  168. else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0)
  169. {
  170. Speed_z = m_dZoomSpeed;
  171. }
  172. else
  173. {
  174. Speed_z = -m_dZoomSpeed;
  175. };
  176. bool res = true;
  177. if ((MoveMatrix & (PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK)) != 0)
  178. {
  179. res = m_pBRCP->ptz_ContinuousMove( Speed_x, Speed_y);
  180. };
  181. if (res)
  182. {
  183. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
  184. {
  185. res = m_pBRCP->ptz_ContinuousMoveZoom( Speed_z );
  186. };
  187. };
  188. m_bStatus = (res) ? 1 : 0;
  189. } else {
  190. m_bStatus = (m_pBRCP->ptz_Stop( true, true )) ? 1 : 0;
  191. };
  192. return (m_bStatus > 0);
  193. }
  194. #include <math.h>
  195. bool protocolPTZ_BRCP::waitMoveIsDone( void ){
  196. ptzStatus tVal;
  197. uint8_t TO = 12; // 3.6 second max
  198. while( m_pBRCP->ptz_GetStatus( &tVal ) && TO ){
  199. if( tVal.hasMoveStatus ){
  200. if( tVal.PanTiltIdle && tVal.ZoomIdle ){
  201. break;
  202. }
  203. } else {
  204. if( ( fabs(tVal.pan - m_dPan) < 0.0005 ) && ( fabs( tVal.tilt - m_dTilt) < 0.0005 ) ) break;
  205. //&& ( fabs( tVal.zoom - m_dZoom ) < 0.05 ) ) break;
  206. };
  207. SLEEP(333);
  208. TO--;
  209. };
  210. if( TO ){
  211. #ifdef DEBUG_EXTRA
  212. LOG("Finished Move!");
  213. #endif
  214. return true;
  215. #ifdef DEBUG_EXTRA
  216. } else {
  217. LOG_ERROR("Error Fetching PTZ Status!");
  218. #endif
  219. };
  220. return false;
  221. }
  222. bool protocolPTZ_BRCP::goAbsolute(float dPan, float dTilt, float dZoom){
  223. #ifdef DEBUG_EXTRA
  224. LOG("ABS Move");
  225. #endif
  226. if (dZoom < 0.0f) dZoom = 0.0f;
  227. return m_pBRCP->ptz_AbsoluteMove(dPan, dTilt, dZoom);
  228. }
  229. bool protocolPTZ_BRCP::getCameraPresets(void){
  230. return false;
  231. }
  232. bool protocolPTZ_BRCP::goPreset(char * PresetToken){
  233. #ifdef DEBUG_EXTRA
  234. LOG("Preset Move");
  235. #endif
  236. if( !m_pBRCP->ptz_GotoPreset( PresetToken, 1.0f, 1.0f, 1.0f )){
  237. m_bStatus = 0;
  238. }
  239. return (m_bStatus > 0);
  240. }
  241. bool protocolPTZ_BRCP::validate(){
  242. return (m_bStatus > 0);
  243. }
  244. #undef LOG
  245. #undef LOG_ERROR