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.

132 lines
4.2 KiB

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