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.
139 lines
4.5 KiB
139 lines
4.5 KiB
#include "protocolPTZ_ONVIF.h"
|
|
#include "../../hardware/uart/serialPort.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "ONVIF", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "ONVIF", this, _LOG_ERROR, X )
|
|
|
|
protocolPTZ_ONVIF::protocolPTZ_ONVIF( config_setting_t *Settings ) :protocolPTZ(), m_mInquiryMutex(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_bLastCommandIssued = CMD_PTZ_NOOP;
|
|
m_pSettings = Settings;
|
|
m_pOnVif = NULL;
|
|
memset( m_pDeviceURI, 0, MAX_PATH_LEN );
|
|
memset( m_pUser, 0, MAX_CRED_LEN );
|
|
memset( m_pPassword, 0, MAX_CRED_LEN );
|
|
};
|
|
|
|
protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :protocolPTZ(), m_mInquiryMutex(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_bLastCommandIssued = CMD_PTZ_NOOP;
|
|
m_pSettings = NULL;
|
|
m_pOnVif = NULL;
|
|
LOG( ip );
|
|
LOG( username );
|
|
LOG( password );
|
|
strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
|
|
strncpy( m_pUser, username, MAX_CRED_LEN );
|
|
strncpy( m_pPassword, password, MAX_CRED_LEN );
|
|
};
|
|
|
|
protocolPTZ_ONVIF::~protocolPTZ_ONVIF(){
|
|
};
|
|
|
|
bool protocolPTZ_ONVIF::setIPAddress( CSTR ip ){
|
|
if( strlen(ip) == 0 ) return false;
|
|
strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
|
|
return true;
|
|
};
|
|
bool protocolPTZ_ONVIF::setUsername( CSTR username ){
|
|
if( strlen(username) == 0 ) return false;
|
|
strncpy( m_pUser, username, MAX_CRED_LEN );
|
|
return true;
|
|
};
|
|
bool protocolPTZ_ONVIF::setPassword( CSTR password ){
|
|
if( strlen(password) == 0 ) return false;
|
|
strncpy( m_pPassword, password, MAX_CRED_LEN );
|
|
return true;
|
|
};
|
|
|
|
|
|
bool protocolPTZ_ONVIF::create( void ){
|
|
if (!protocolPTZ::create()){
|
|
LOG("KAKA!");
|
|
return false;
|
|
};
|
|
if( m_pSettings!= NULL ) {
|
|
config_setting_t *pSetting;
|
|
|
|
LOG("Reading Settings!");
|
|
pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_USER);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_pUser, "%s", config_setting_get_string(pSetting));
|
|
pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_PASS);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_pPassword, "%s", config_setting_get_string(pSetting));
|
|
pSetting = config_setting_get_member(m_pSettings, PPTZ_TAG_ONVIF_DEV_URI);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_pDeviceURI, "%s", config_setting_get_string(pSetting));
|
|
};
|
|
LOG( m_pDeviceURI );
|
|
if( strlen( m_pDeviceURI ) < 4 ){
|
|
LOG_ERROR("No Device URI Is Set!");
|
|
return false;
|
|
};
|
|
m_pOnVif = new pOnvif();
|
|
if( m_pOnVif == NULL ){
|
|
LOG_ERROR("PONVIF NEW FAILURE!");
|
|
return false;
|
|
};
|
|
m_pOnVif->setIPAddress( m_pDeviceURI );
|
|
m_pOnVif->setUsername( m_pUser );
|
|
m_pOnVif->setPassword( m_pPassword );
|
|
if( m_pOnVif->create() ){
|
|
m_pProfile = m_pOnVif->getProfiles()->at(0);
|
|
return true;
|
|
} else {
|
|
LOG("PONVIF CREATION ERROR!");
|
|
delete( m_pOnVif );
|
|
m_pOnVif = NULL;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool protocolPTZ_ONVIF::move( uint32_t MoveMatrix ){
|
|
//if( m_bStatus == 0 ) return false;
|
|
if( m_pProfile == NULL ) return false;
|
|
//if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
|
|
float Speed_x, Speed_y, Speed_z;
|
|
if( MoveMatrix > 0 ) {
|
|
if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0){
|
|
Speed_x = 0.0f;
|
|
} else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0){
|
|
Speed_x = -m_dPanSpeed;
|
|
} else {
|
|
Speed_x = m_dPanSpeed;
|
|
};
|
|
if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0){
|
|
Speed_y = 0.0;
|
|
} else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0){
|
|
Speed_y = m_dTiltSpeed;
|
|
} else {
|
|
Speed_y = -m_dTiltSpeed;
|
|
};
|
|
if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0){
|
|
Speed_z = 0.0;
|
|
} else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0){
|
|
Speed_z = m_dZoomSpeed;
|
|
} else {
|
|
Speed_z = -m_dZoomSpeed;
|
|
};
|
|
if( m_pOnVif->ptz_ContinuousMove( m_pProfile->profiletoken, Speed_x , Speed_y ) ){
|
|
return m_pOnVif->ptz_ContinuousMoveZoom( m_pProfile->profiletoken, Speed_z );
|
|
};
|
|
} else {
|
|
return m_pOnVif->ptz_Stop( m_pProfile->profiletoken, true, true );
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool protocolPTZ_ONVIF::goAbsolute( double dPan, double dTilt, double dZoom ){
|
|
//if (m_bStatus == 0) return false;
|
|
LOG("ABS Move");
|
|
if( m_pProfile == NULL ) return false;
|
|
|
|
return m_pOnVif->ptz_AbsoluteMove( m_pProfile->profiletoken, dPan, dTilt, dZoom );
|
|
};
|
|
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|