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.
266 lines
6.3 KiB
266 lines
6.3 KiB
#include "protocolPTZ_BRCP.h"
|
|
|
|
#include "../../hardware/uart/serialPort.h"
|
|
|
|
#define LOG(X) m_pLog->Log("BRCP", this, X)
|
|
#define LOG_ERROR(X) m_pLog->Log("BRCP", this, _LOG_ERROR, X)
|
|
|
|
protocolPTZ_BRCP::protocolPTZ_BRCP(config_setting_t * Settings) :
|
|
protocolPTZ(),
|
|
m_mInquiryMutex()
|
|
{
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_bLastCommandIssued = CMD_PTZ_NOOP;
|
|
m_pSettings = Settings;
|
|
m_bAuthMode = 0;
|
|
m_pBRCP = NULL;
|
|
memset(m_pDeviceURI, 0, MAX_PATH_LEN);
|
|
memset(m_pUser, 0, MAX_CRED_LEN);
|
|
memset(m_pPassword, 0, MAX_CRED_LEN);
|
|
}
|
|
|
|
protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode) :
|
|
protocolPTZ(),
|
|
m_mInquiryMutex()
|
|
{
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_bLastCommandIssued = CMD_PTZ_NOOP;
|
|
m_pSettings = NULL;
|
|
m_pBRCP = NULL;
|
|
LOG(ip);
|
|
LOG(username);
|
|
LOG(password);
|
|
m_bAuthMode = AuthMode;
|
|
sprintf(m_pDeviceURI, "M Auth Mode: [%d]", m_bAuthMode);
|
|
LOG( m_pDeviceURI );
|
|
if (port == 80){
|
|
sprintf(m_pDeviceURI, "%s", ip );
|
|
} else {
|
|
sprintf(m_pDeviceURI, "%s:%d", ip, port );
|
|
};
|
|
LOG( m_pDeviceURI );
|
|
memset( m_pUser, 0, MAX_CRED_LEN);
|
|
strncpy(m_pUser, username, MAX_CRED_LEN);
|
|
memset( m_pPassword, 0, MAX_CRED_LEN);
|
|
strncpy(m_pPassword, password, MAX_CRED_LEN);
|
|
}
|
|
|
|
protocolPTZ_BRCP::protocolPTZ_BRCP(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode) :
|
|
protocolPTZ(),
|
|
m_mInquiryMutex()
|
|
{
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_bLastCommandIssued = CMD_PTZ_NOOP;
|
|
m_pSettings = NULL;
|
|
m_pBRCP = NULL;
|
|
LOG(ctl_url);
|
|
LOG(username);
|
|
LOG(password);
|
|
m_bAuthMode = AuthMode;
|
|
sprintf(m_pDeviceURI, "Ex Auth Mode: [%d]", m_bAuthMode);
|
|
LOG( m_pDeviceURI );
|
|
strncpy( m_pDeviceURI, ctl_url, MAX_CRED_LEN );
|
|
strncpy( m_pUser, username, MAX_CRED_LEN);
|
|
strncpy( m_pPassword, password, MAX_CRED_LEN);
|
|
}
|
|
|
|
protocolPTZ_BRCP::~protocolPTZ_BRCP(){
|
|
if (m_pBRCP) {
|
|
delete( m_pBRCP );
|
|
};
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::setIPAddress(CSTR ip){
|
|
if (ip == NULL) return false;
|
|
if (strlen(ip) == 0) return false;
|
|
sprintf(m_pDeviceURI, "http://%s/onvif/device_service", ip);
|
|
// strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
|
|
return true;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::setUsername(CSTR username){
|
|
if (username == NULL) return false;
|
|
if (strlen(username) == 0) return false;
|
|
strncpy(m_pUser, username, MAX_CRED_LEN);
|
|
return true;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::setPassword(CSTR password){
|
|
if (password == NULL) return false;
|
|
if (strlen(password) == 0) return false;
|
|
strncpy(m_pPassword, password, MAX_CRED_LEN);
|
|
return true;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::setAuthMode(uint8_t Mode){
|
|
m_bAuthMode = Mode;
|
|
return true;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::create(void){
|
|
if (! protocolPTZ::create()) return false;
|
|
if (m_pSettings != NULL){
|
|
config_setting_t * pSetting;
|
|
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));
|
|
};
|
|
#ifdef DEBUG
|
|
LOG(m_pDeviceURI);
|
|
#endif
|
|
if( strlen(m_pDeviceURI) < 4 ){
|
|
LOG_ERROR("No Device URI Is Set!");
|
|
return false;
|
|
};
|
|
m_pBRCP = new boschRCP();
|
|
if( m_pBRCP == NULL ){
|
|
LOG_ERROR("boschRCP NEW FAILURE!");
|
|
m_bStatus = 0;
|
|
return false;
|
|
};
|
|
m_pBRCP->setDeviceUri(m_pDeviceURI);
|
|
m_pBRCP->setUsername(m_pUser);
|
|
m_pBRCP->setPassword(m_pPassword);
|
|
m_pBRCP->setAuthMode(m_bAuthMode);
|
|
LOG("PROTOCREATE");
|
|
if( m_pBRCP->create() ){
|
|
LOG("DONE");
|
|
m_bStatus = 1;
|
|
return true;
|
|
} else {
|
|
LOG_ERROR("bosch RCP+ CREATE FAILURE!");
|
|
delete(m_pBRCP);
|
|
m_pBRCP = NULL;
|
|
m_bStatus = 0;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::move(uint32_t MoveMatrix)
|
|
{
|
|
// if( m_bStatus == 0 ) 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;
|
|
};
|
|
bool res = true;
|
|
if ((MoveMatrix & (PTZ_DRIVE_PAN_MASK | PTZ_DRIVE_TILT_MASK)) != 0)
|
|
{
|
|
res = m_pBRCP->ptz_ContinuousMove( Speed_x, Speed_y);
|
|
};
|
|
if (res)
|
|
{
|
|
if ((MoveMatrix & PTZ_DRIVE_ZOOM_MASK) != 0)
|
|
{
|
|
res = m_pBRCP->ptz_ContinuousMoveZoom( Speed_z );
|
|
};
|
|
};
|
|
m_bStatus = (res) ? 1 : 0;
|
|
} else {
|
|
|
|
m_bStatus = (m_pBRCP->ptz_Stop( true, true )) ? 1 : 0;
|
|
};
|
|
return (m_bStatus > 0);
|
|
}
|
|
|
|
#include <math.h>
|
|
|
|
bool protocolPTZ_BRCP::waitMoveIsDone( void ){
|
|
ptzStatus tVal;
|
|
uint8_t TO = 12; // 3.6 second max
|
|
while( m_pBRCP->ptz_GetStatus( &tVal ) && TO ){
|
|
if( tVal.hasMoveStatus ){
|
|
if( tVal.PanTiltIdle && tVal.ZoomIdle ){
|
|
break;
|
|
}
|
|
} else {
|
|
if( ( fabs(tVal.pan - m_dPan) < 0.0005 ) && ( fabs( tVal.tilt - m_dTilt) < 0.0005 ) ) break;
|
|
//&& ( fabs( tVal.zoom - m_dZoom ) < 0.05 ) ) break;
|
|
};
|
|
SLEEP(333);
|
|
TO--;
|
|
};
|
|
if( TO ){
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Finished Move!");
|
|
#endif
|
|
return true;
|
|
#ifdef DEBUG_EXTRA
|
|
} else {
|
|
LOG_ERROR("Error Fetching PTZ Status!");
|
|
#endif
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::goAbsolute(float dPan, float dTilt, float dZoom){
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("ABS Move");
|
|
#endif
|
|
if (dZoom < 0.0f) dZoom = 0.0f;
|
|
return m_pBRCP->ptz_AbsoluteMove(dPan, dTilt, dZoom);
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::getCameraPresets(void){
|
|
return false;
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::goPreset(char * PresetToken){
|
|
|
|
#ifdef DEBUG_EXTRA
|
|
LOG("Preset Move");
|
|
#endif
|
|
if( !m_pBRCP->ptz_GotoPreset( PresetToken, 1.0f, 1.0f, 1.0f )){
|
|
m_bStatus = 0;
|
|
}
|
|
return (m_bStatus > 0);
|
|
}
|
|
|
|
bool protocolPTZ_BRCP::validate(){
|
|
return (m_bStatus > 0);
|
|
}
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|