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.

175 lines
5.7 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_ERROR("protocolPTZ::create Failure!");
  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. LOG("PONVIF BEFORE CREATE");
  75. if( m_pOnVif->create() ){
  76. LOG("CREATE OK -> Get Profile");
  77. m_pProfile = m_pOnVif->getProfiles()->at(0);
  78. LOG("Get Profile OK");
  79. return true;
  80. } else {
  81. LOG("PONVIF CREATION ERROR!");
  82. delete( m_pOnVif );
  83. m_pOnVif = NULL;
  84. };
  85. return false;
  86. };
  87. bool protocolPTZ_ONVIF::move( uint32_t MoveMatrix ){
  88. //if( m_bStatus == 0 ) return false;
  89. if( m_pProfile == NULL ) return false;
  90. //if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
  91. float Speed_x, Speed_y, Speed_z;
  92. if( MoveMatrix > 0 ) {
  93. if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0){
  94. Speed_x = 0.0f;
  95. } else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0){
  96. Speed_x = -m_dPanSpeed;
  97. } else {
  98. Speed_x = m_dPanSpeed;
  99. };
  100. if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0){
  101. Speed_y = 0.0;
  102. } else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0){
  103. Speed_y = m_dTiltSpeed;
  104. } else {
  105. Speed_y = -m_dTiltSpeed;
  106. };
  107. if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0){
  108. Speed_z = 0.0;
  109. } else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0){
  110. Speed_z = m_dZoomSpeed;
  111. } else {
  112. Speed_z = -m_dZoomSpeed;
  113. };
  114. bool res = true;
  115. if( ( MoveMatrix & ( PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK ) ) != 0 ) {
  116. res = m_pOnVif->ptz_ContinuousMove( m_pProfile->profiletoken, Speed_x , Speed_y );
  117. };
  118. if( res ){
  119. if(( MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0 ) {
  120. return true;
  121. };
  122. return m_pOnVif->ptz_ContinuousMoveZoom( m_pProfile->profiletoken, Speed_z );
  123. };
  124. } else {
  125. return m_pOnVif->ptz_Stop( m_pProfile->profiletoken, true, true );
  126. };
  127. return false;
  128. };
  129. #include <math.h>
  130. bool protocolPTZ_ONVIF::goAbsolute( float dPan, float dTilt, float dZoom ){
  131. //if (m_bStatus == 0) return false;
  132. //LOG("ABS Move");
  133. if( m_pProfile == NULL ){
  134. LOG_ERROR("No PTZ Profile!!");
  135. return false;
  136. };
  137. if ( dZoom < 0.0f ) dZoom = 0.0f;
  138. uint8_t TO = 100;
  139. if ( m_pOnVif->ptz_AbsoluteMove( m_pProfile->profiletoken, dPan, dTilt, dZoom ) ){
  140. SLEEP(10);
  141. ptzStatus tVal;
  142. while( m_pOnVif->ptz_GetStatus( m_pProfile->profiletoken, &tVal ) && TO ) {
  143. if( tVal.hasMoveStatus ) {
  144. //LOG("CHK CAM IDLE");
  145. if( tVal.PanTiltIdle && tVal.ZoomIdle ) break;
  146. } else {
  147. if( ( fabs(tVal.pan - dPan) < 0.0005 ) && ( fabs( tVal.tilt - dTilt) < 0.0005 ) ) break;//&& ( fabs( tVal.zoom - dZoom ) < 0.05 ) ) break;
  148. };
  149. SLEEP(10);
  150. TO --;
  151. };
  152. if( TO ) {
  153. #ifdef DEBUG
  154. //LOG("Finished Move!");
  155. #endif
  156. return true;
  157. } else LOG_ERROR("Error Fetching PTZ Status!");
  158. };
  159. return false;
  160. };
  161. #undef LOG
  162. #undef LOG_ERROR