diff --git a/libraries/AP_ONVIF/AP_ONVIF.cpp b/libraries/AP_ONVIF/AP_ONVIF.cpp index 8a4e5ebe55..a91d64f2fb 100644 --- a/libraries/AP_ONVIF/AP_ONVIF.cpp +++ b/libraries/AP_ONVIF/AP_ONVIF.cpp @@ -16,6 +16,7 @@ */ #include "AP_ONVIF.h" +#if ENABLE_ONVIF #include #include "onvifhelpers.h" @@ -31,6 +32,7 @@ const char *wsse_Base64BinaryURI = "http://docs.oasis-open.org/wss/2004/01/oasis AP_ONVIF *AP_ONVIF::_singleton; extern const AP_HAL::HAL &hal; +static AP_ONVIF onvif; // Default constructor AP_ONVIF::AP_ONVIF() @@ -41,27 +43,26 @@ AP_ONVIF::AP_ONVIF() _singleton = this; } -bool AP_ONVIF::init() -{ - srand ((time_t)(hal.util->get_hw_rtc()/1000000ULL)); - soap = soap_new1(SOAP_XML_CANONICAL | SOAP_C_UTFSTRING); - soap->connect_timeout = soap->recv_timeout = soap->send_timeout = 30; // 30 sec - - proxy_device = new DeviceBindingProxy(soap); - proxy_media = new MediaBindingProxy(soap); - proxy_ptz = new PTZBindingProxy(soap); - - if (proxy_device == nullptr || - proxy_media == nullptr || - proxy_ptz == nullptr) { - AP_HAL::panic("AP_ONVIF: Failed to allocate gSOAP Proxy objects."); - return false; - } - return true; -} - +// Start ONVIF client with username, password and service host url bool AP_ONVIF::start(const char *user, const char *pass, const char *httphostname) { + if (!initialised) { + srand ((time_t)(hal.util->get_hw_rtc()/1000000ULL)); + soap = soap_new1(SOAP_XML_CANONICAL | SOAP_C_UTFSTRING); + soap->connect_timeout = soap->recv_timeout = soap->send_timeout = 30; // 30 sec + + proxy_device = new DeviceBindingProxy(soap); + proxy_media = new MediaBindingProxy(soap); + proxy_ptz = new PTZBindingProxy(soap); + + if (proxy_device == nullptr || + proxy_media == nullptr || + proxy_ptz == nullptr) { + AP_HAL::panic("AP_ONVIF: Failed to allocate gSOAP Proxy objects."); + } + initialised = true; + } + username = user; password = pass; hostname = httphostname; @@ -104,6 +105,7 @@ void AP_ONVIF::report_error() } } +// detect onvif server present on the network bool AP_ONVIF::probe_onvif_server() { _tds__GetDeviceInformation GetDeviceInformation; @@ -250,6 +252,7 @@ bool AP_ONVIF::probe_onvif_server() return true; } +// Generate Random Nonce value void AP_ONVIF::rand_nonce(char *nonce, size_t noncelen) { size_t i; @@ -261,6 +264,7 @@ void AP_ONVIF::rand_nonce(char *nonce, size_t noncelen) (void)memcpy((void *)(nonce + i), (const void *)&r, 4); } } + #define TEST_NONCE "LKqI6G/AikKCQrN0zqZFlg==" #define TEST_TIME "2010-09-16T07:50:45Z" #define TEST_PASS "userpassword" @@ -326,6 +330,8 @@ void AP_ONVIF::set_credentials() security->UsernameToken->wsu__Created = soap_strdup(soap, created); } +// Turn ONVIF camera to mentioned pan, tilt and zoom, normalised +// between limits bool AP_ONVIF::set_absolutemove(float x, float y, float z) { _tptz__AbsoluteMove AbsoluteMove; @@ -353,3 +359,4 @@ bool AP_ONVIF::set_absolutemove(float x, float y, float z) soap_end(soap); return true; } +#endif //#if ENABLE_ONVIF diff --git a/libraries/AP_ONVIF/AP_ONVIF.h b/libraries/AP_ONVIF/AP_ONVIF.h index 9252a54c0d..f298f821b2 100644 --- a/libraries/AP_ONVIF/AP_ONVIF.h +++ b/libraries/AP_ONVIF/AP_ONVIF.h @@ -17,6 +17,8 @@ #pragma once #include + +#if ENABLE_ONVIF #include #include #include @@ -31,22 +33,34 @@ public: AP_ONVIF(const AP_ONVIF &other) = delete; AP_ONVIF &operator=(const AP_ONVIF&) = delete; - bool init(); + // Start ONVIF client with username, password and service host url bool start(const char *user, const char *pass, const char *httphostname); - void set_credentials(); + + // Turn ONVIF camera to mentioned pan, tilt and zoom, normalised + // between limits bool set_absolutemove(float pan, float tilt, float zoom); - void set_pan_norm(float pan) { pan_norm = pan; } - void set_tilt_norm(float tilt) { tilt_norm = tilt; } - void set_zoom_norm(float zoom) { zoom_norm = zoom; } + + // returns pan/tilt command max limit Vector2f get_pan_tilt_limit_max() const { return pan_tilt_limit_max; } + + // returns pan/tilt command min limit Vector2f get_pan_tilt_limit_min() const { return pan_tilt_limit_min; } // get singleton instance static AP_ONVIF *get_singleton() { return _singleton; } private: + + // prepares security header of SOAP message going to be sent immmediately after + void set_credentials(); + + // convert error message from gSOAP lib into human readable string and print void report_error(); + + // detect onvif server present on the network bool probe_onvif_server(); + + // Generate Random Nonce value void rand_nonce(char *nonce, size_t noncelen); Vector2f pan_tilt_limit_min; @@ -70,9 +84,11 @@ private: std::string DEVICE_ENDPOINT; std::string MEDIA_ENDPOINT; std::string PTZ_ENDPOINT; + bool initialised; }; namespace AP { AP_ONVIF &onvif(); }; +#endif // #if ENABLE_ONVIF diff --git a/libraries/AP_ONVIF/sha1.cpp b/libraries/AP_ONVIF/sha1.cpp index d11dde1800..6bd1b834d8 100644 --- a/libraries/AP_ONVIF/sha1.cpp +++ b/libraries/AP_ONVIF/sha1.cpp @@ -37,6 +37,7 @@ #include "onvifhelpers.h" +#ifdef __BYTE_ORDER #define SHA1_BLOCK_SIZE 64 #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) @@ -231,3 +232,4 @@ void sha1(unsigned char hval[], const unsigned char data[], unsigned long len) sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); } +#endif //#ifdef __BYTE_ORDER