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.

165 lines
5.3 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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_pLog = basicLogCollection::getInstance();
  7. m_bLastCommandIssued = CMD_PTZ_NOOP;
  8. m_pSettings = Settings;
  9. m_pOnVif = NULL;
  10. memset( m_pDeviceURI, 0, MAX_PATH_LEN );
  11. memset( m_pUser, 0, MAX_CRED_LEN );
  12. memset( m_pPassword, 0, MAX_CRED_LEN );
  13. };
  14. protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :protocolPTZ(), m_mInquiryMutex(){
  15. m_pLog = basicLogCollection::getInstance();
  16. m_bLastCommandIssued = CMD_PTZ_NOOP;
  17. m_pSettings = NULL;
  18. m_pOnVif = NULL;
  19. LOG( ip );
  20. LOG( username );
  21. LOG( password );
  22. strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  23. strncpy( m_pUser, username, MAX_CRED_LEN );
  24. strncpy( m_pPassword, password, MAX_CRED_LEN );
  25. };
  26. protocolPTZ_ONVIF::~protocolPTZ_ONVIF(){
  27. };
  28. bool protocolPTZ_ONVIF::setIPAddress( CSTR ip ){
  29. if( strlen(ip) == 0 ) return false;
  30. strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
  31. return true;
  32. };
  33. bool protocolPTZ_ONVIF::setUsername( CSTR username ){
  34. if( strlen(username) == 0 ) return false;
  35. strncpy( m_pUser, username, MAX_CRED_LEN );
  36. return true;
  37. };
  38. bool protocolPTZ_ONVIF::setPassword( CSTR password ){
  39. if( strlen(password) == 0 ) return false;
  40. strncpy( m_pPassword, password, MAX_CRED_LEN );
  41. return true;
  42. };
  43. bool protocolPTZ_ONVIF::create( void ){
  44. if (!protocolPTZ::create()){
  45. LOG("KAKA!");
  46. return false;
  47. };
  48. if( m_pSettings!= NULL ) {
  49. config_setting_t *pSetting;
  50. LOG("Reading Settings!");
  51. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
  52. if (pSetting == NULL) return false;
  53. sprintf( m_pUser, "%s", config_setting_get_string(pSetting));
  54. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
  55. if (pSetting == NULL) return false;
  56. sprintf( m_pPassword, "%s", config_setting_get_string(pSetting));
  57. pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
  58. if (pSetting == NULL) return false;
  59. sprintf( m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  60. };
  61. LOG( m_pDeviceURI );
  62. if( strlen( m_pDeviceURI ) < 4 ){
  63. LOG_ERROR("No Device URI Is Set!");
  64. return false;
  65. };
  66. m_pOnVif = new pOnvif();
  67. if( m_pOnVif == NULL ){
  68. LOG_ERROR("PONVIF NEW FAILURE!");
  69. return false;
  70. };
  71. m_pOnVif->setIPAddress( m_pDeviceURI );
  72. m_pOnVif->setUsername( m_pUser );
  73. m_pOnVif->setPassword( m_pPassword );
  74. if( m_pOnVif->create() ){
  75. m_pProfile = m_pOnVif->getProfiles()->at(0);
  76. return true;
  77. } else {
  78. LOG("PONVIF CREATION ERROR!");
  79. delete( m_pOnVif );
  80. m_pOnVif = NULL;
  81. };
  82. return false;
  83. };
  84. bool protocolPTZ_ONVIF::move( uint32_t MoveMatrix ){
  85. //if( m_bStatus == 0 ) return false;
  86. if( m_pProfile == NULL ) return false;
  87. //if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  88. float Speed_x, Speed_y, Speed_z;
  89. if( MoveMatrix > 0 ) {
  90. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0){
  91. Speed_x = 0.0f;
  92. } else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0){
  93. Speed_x = -m_dPanSpeed;
  94. } else {
  95. Speed_x = m_dPanSpeed;
  96. };
  97. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0){
  98. Speed_y = 0.0;
  99. } else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0){
  100. Speed_y = m_dTiltSpeed;
  101. } else {
  102. Speed_y = -m_dTiltSpeed;
  103. };
  104. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0){
  105. Speed_z = 0.0;
  106. } else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0){
  107. Speed_z = m_dZoomSpeed;
  108. } else {
  109. Speed_z = -m_dZoomSpeed;
  110. };
  111. if( m_pOnVif->ptz_ContinuousMove( m_pProfile->profiletoken, Speed_x , Speed_y ) ){
  112. return m_pOnVif->ptz_ContinuousMoveZoom( m_pProfile->profiletoken, Speed_z );
  113. };
  114. } else {
  115. return m_pOnVif->ptz_Stop( m_pProfile->profiletoken, true, true );
  116. };
  117. return false;
  118. };
  119. #include <math.h>
  120. bool protocolPTZ_ONVIF::goAbsolute( float dPan, float dTilt, float dZoom ){
  121. //if (m_bStatus == 0) return false;
  122. //LOG("ABS Move");
  123. if( m_pProfile == NULL ){
  124. LOG_ERROR("No PTZ Profile!!");
  125. return false;
  126. };
  127. if ( dZoom < 0.0f ) dZoom = 0.0f;
  128. uint8_t TO = 100;
  129. if ( m_pOnVif->ptz_AbsoluteMove( m_pProfile->profiletoken, dPan, dTilt, dZoom ) ){
  130. SLEEP(10);
  131. ptzStatus tVal;
  132. while( m_pOnVif->ptz_GetStatus( m_pProfile->profiletoken, &tVal ) && TO ) {
  133. if( tVal.hasMoveStatus ) {
  134. //LOG("CHK CAM IDLE");
  135. if( tVal.PanTiltIdle && tVal.ZoomIdle ) break;
  136. } else {
  137. if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break;
  138. };
  139. SLEEP(10);
  140. TO --;
  141. };
  142. if( TO ) {
  143. #ifdef DEBUG
  144. //LOG("Finished Move!");
  145. #endif
  146. return true;
  147. } else LOG_ERROR("Error Fetching PTZ Status!");
  148. };
  149. return false;
  150. };
  151. #undef LOG
  152. #undef LOG_ERROR