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

#include "protocolPTZ_ONVIF.h"
#include "../../hardware/uart/serialPort.h"
#define LOG( X ) m_pLog->Log( "Proto[ONVIF]", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "Proto[ONVIF]", this, _LOG_ERROR, X )
protocolPTZ_ONVIF::protocolPTZ_ONVIF(config_setting_t *Settings) :protocolPTZ(Settings), m_mInquiryMutex(){
m_bLastCommandIssued = CMD_PTZ_NOOP;
};
protocolPTZ_ONVIF::~protocolPTZ_ONVIF(){
};
bool protocolPTZ_ONVIF::create( void ){
config_setting_t *pSetting;
if (!protocolPTZ::create()) return false;
m_bStatus = 0;
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));
std::string A(m_pUser);
std::string B(m_pPassword);
std::string C(m_pDeviceURI);
m_pDevice = new OnvifClientDevice(C, A, B);
if (m_pDevice != NULL){
m_pPTZ = new OnvifClientPTZ(*m_pDevice);
if (m_pPTZ!=NULL){
_tptz__GetNodesResponse tNodes;
int RetVal;
RetVal = m_pPTZ->GetNodes(tNodes);
if (RetVal == 0){
OnvifClientMedia media(*m_pDevice);
_trt__GetProfilesResponse profiles;
media.GetProfiles(profiles);
m_pPTZToken = profiles.Profiles.at(0)->token;// PTZConfiguration->token;
//m_pPTZToken = tNodes.PTZNode.at(0)->token;
//_tptz__GetConfigurationOptionsResponse COResp;
//int RetVal = m_pPTZ->GetConfigurationOptions(COResp, m_pToken);
//_tptz__GetConfigurationResponse configResponce;
//configResponce.PTZConfiguration = new tt__PTZConfiguration();
//m_pPTZ->GetConfiguration(configResponce);
//m_pToken = configResponce.PTZConfiguration->token;
setConnectionStatus(CS_CONNECTED);
m_bStatus = 1;
return true;
};
};
};
return false;
};
bool protocolPTZ_ONVIF::initCamera(void){
if (m_bStatus == 0) return false;
//if (m_bReplyRequired) if ( m_bLastCommandIssued != CMD_PTZ_NOOP ) return false;
m_bLastCommandIssued = CMD_PTZ_INIT;
m_pPTZ->Initialize();
return true;
};
bool protocolPTZ_ONVIF::move(uint32_t MoveMatrix){
if (m_bStatus == 0) return false;
//if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
_tptz__ContinuousMoveResponse ContMoveResponse;
tt__PTZSpeed tSpeed;
tSpeed.PanTilt = new tt__Vector2D();
tSpeed.Zoom = new tt__Vector1D();
LONG64 to = 1000;
int RetVal;
if ((MoveMatrix & PTZ_DRIVE_PAN_MASK) == 0){
tSpeed.PanTilt->x = 0.0;
} else if ((MoveMatrix & PTZ_DRIVE_PAN_LEFT) != 0){
tSpeed.PanTilt->x = -m_dPanSpeed;
} else {
tSpeed.PanTilt->x = m_dPanSpeed;
};
if ((MoveMatrix & PTZ_DRIVE_TILT_MASK) == 0){
tSpeed.PanTilt->y = 0.0;
} else if ((MoveMatrix & PTZ_DRIVE_TILT_UP) != 0){
tSpeed.PanTilt->y = m_dTiltSpeed;
} else {
tSpeed.PanTilt->y = -m_dTiltSpeed;
};
if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) == 0){
tSpeed.Zoom->x = 0.0;
} else if ((MoveMatrix & PTZ_DRIVE_ZOOM_WIDE) != 0){
tSpeed.Zoom->x = m_dZoomSpeed;
} else {
tSpeed.Zoom->x = -m_dZoomSpeed;
};
RetVal = m_pPTZ->ContinuousMove(ContMoveResponse, tSpeed, to, m_pPTZToken);
delete(tSpeed.PanTilt);
delete(tSpeed.Zoom);
if (RetVal) return false;
return true;
};
bool protocolPTZ_ONVIF::goAbsolute( double dPan, double dTilt, double dZoom ){
if (m_bStatus == 0) return false;
//if (m_bReplyRequired) if (m_bLastCommandIssued != CMD_PTZ_NOOP) return false;
_tptz__AbsoluteMoveResponse AbsMoveResponse;
tt__PTZSpeed tSpeed;
tt__PTZVector tPos;
tSpeed.PanTilt = new tt__Vector2D();
tSpeed.Zoom = new tt__Vector1D();
tSpeed.PanTilt->x = 1.f;
tSpeed.PanTilt->y = 1.f;
tSpeed.Zoom->x = 1.f;
tPos.PanTilt = new tt__Vector2D();
tPos.Zoom = new tt__Vector1D();
tPos.PanTilt->x = dPan;
tPos.PanTilt->y = dTilt;
tPos.Zoom->x = dZoom;
int RetVal;
RetVal = m_pPTZ->AbsoluteMove(AbsMoveResponse, tSpeed, tPos, m_pPTZToken);
delete(tSpeed.PanTilt);
delete(tSpeed.Zoom);
delete(tPos.PanTilt);
delete(tPos.Zoom);
return true;
};
//tt__PTZSpeed tSpeed;
//tSpeed.PanTilt->
#undef LOG
#undef LOG_ERROR