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.

133 lines
4.2 KiB

7 years ago
​
​
​
7 years ago
7 years ago
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 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) :protocolPTZ(), m_mInquiryMutex(){
  6. m_bLastCommandIssued = CMD_PTZ_NOOP;
  7. m_pSettings = Settings;
  8. };
  9. protocolPTZ_ONVIF::~protocolPTZ_ONVIF(){
  10. };
  11. bool protocolPTZ_ONVIF::create( void ){
  12. config_setting_t *pSetting;
  13. if (!protocolPTZ::create()) return false;
  14. m_bStatus = 0;
  15. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  16. if (pSetting == NULL) return false;
  17. sprintf(m_pUser, "%s", config_setting_get_string(pSetting));
  18. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  19. if (pSetting == NULL) return false;
  20. sprintf(m_pPassword, "%s", config_setting_get_string(pSetting));
  21. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  22. if (pSetting == NULL) return false;
  23. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  24. std::string A(m_pUser);
  25. std::string B(m_pPassword);
  26. std::string C(m_pDeviceURI);
  27. m_pDevice = new OnvifClientDevice(C, A, B);
  28. if (m_pDevice != NULL){
  29. m_pPTZ = new OnvifClientPTZ(*m_pDevice);
  30. if (m_pPTZ!=NULL){
  31. _tptz__GetNodesResponse tNodes;
  32. int RetVal;
  33. RetVal = m_pPTZ->GetNodes(tNodes);
  34. if (RetVal == 0){
  35. OnvifClientMedia media(*m_pDevice);
  36. _trt__GetProfilesResponse profiles;
  37. media.GetProfiles(profiles);
  38. m_pPTZToken = profiles.Profiles.at(0)->token;// PTZConfiguration->token;
  39. //m_pPTZToken = tNodes.PTZNode.at(0)->token;
  40. //_tptz__GetConfigurationOptionsResponse COResp;
  41. //int RetVal = m_pPTZ->GetConfigurationOptions(COResp, m_pToken);
  42. //_tptz__GetConfigurationResponse configResponce;
  43. //configResponce.PTZConfiguration = new tt__PTZConfiguration();
  44. //m_pPTZ->GetConfiguration(configResponce);
  45. //m_pToken = configResponce.PTZConfiguration->token;
  46. setConnectionStatus(CS_CONNECTED);
  47. m_bStatus = 1;
  48. return true;
  49. };
  50. };
  51. };
  52. return false;
  53. };
  54. bool protocolPTZ_ONVIF::initCamera(void){
  55. if (m_bStatus == 0) return false;
  56. //if (m_bReplyRequired) if ( m_bLastCommandIssued != CMD_PTZ_NOOP ) return false;
  57. m_bLastCommandIssued = CMD_PTZ_INIT;
  58. m_pPTZ->Initialize();
  59. return true;
  60. };
  61. bool protocolPTZ_ONVIF::move(uint32_t MoveMatrix){
  62. if (m_bStatus == 0) return false;
  63. //if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  64. _tptz__ContinuousMoveResponse ContMoveResponse;
  65. tt__PTZSpeed tSpeed;
  66. tSpeed.PanTilt = new tt__Vector2D();
  67. tSpeed.Zoom = new tt__Vector1D();
  68. LONG64 to = 1000;
  69. int RetVal;
  70. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0){
  71. tSpeed.PanTilt->x = 0.0;
  72. } else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0){
  73. tSpeed.PanTilt->x = -m_dPanSpeed;
  74. } else {
  75. tSpeed.PanTilt->x = m_dPanSpeed;
  76. };
  77. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0){
  78. tSpeed.PanTilt->y = 0.0;
  79. } else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0){
  80. tSpeed.PanTilt->y = m_dTiltSpeed;
  81. } else {
  82. tSpeed.PanTilt->y = -m_dTiltSpeed;
  83. };
  84. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0){
  85. tSpeed.Zoom->x = 0.0;
  86. } else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0){
  87. tSpeed.Zoom->x = m_dZoomSpeed;
  88. } else {
  89. tSpeed.Zoom->x = -m_dZoomSpeed;
  90. };
  91. RetVal = m_pPTZ->ContinuousMove(ContMoveResponse, tSpeed, to, m_pPTZToken);
  92. delete(tSpeed.PanTilt);
  93. delete(tSpeed.Zoom);
  94. if (RetVal) return false;
  95. return true;
  96. };
  97. bool protocolPTZ_ONVIF::goAbsolute( double dPan, double dTilt, double dZoom ){
  98. if (m_bStatus == 0) return false;
  99. //if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  100. _tptz__AbsoluteMoveResponse AbsMoveResponse;
  101. tt__PTZSpeed tSpeed;
  102. tt__PTZVector tPos;
  103. tSpeed.PanTilt = new tt__Vector2D();
  104. tSpeed.Zoom = new tt__Vector1D();
  105. tSpeed.PanTilt->x = 1.f;
  106. tSpeed.PanTilt->y = 1.f;
  107. tSpeed.Zoom->x = 1.f;
  108. tPos.PanTilt = new tt__Vector2D();
  109. tPos.Zoom = new tt__Vector1D();
  110. tPos.PanTilt->x = dPan;
  111. tPos.PanTilt->y = dTilt;
  112. tPos.Zoom->x = dZoom;
  113. int RetVal;
  114. RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
  115. delete(tSpeed.PanTilt);
  116. delete(tSpeed.Zoom);
  117. delete(tPos.PanTilt);
  118. delete(tPos.Zoom);
  119. return true;
  120. };
  121. //tt__PTZSpeed tSpeed;
  122. //tSpeed.PanTilt->
  123. #undef LOG
  124. #undef LOG_ERROR