 la_mojo pOnvif: ONVIF compliance fixes (report points 1-6)
1. Faults are no longer reported as success: every request waits for the
answer, checks the HTTP status and the SOAP Fault (logged with
Code/Subcode/Reason); getLastError()/getLastFault() tell the caller.
protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on
communication errors, not on a Fault from a reachable camera.
AbsoluteMove now waits for its answer too.
2. Request/reply race: already fixed in #11 (checked).
3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof),
videoSource zero-filled, Imaging values parsed as float, IrCutFilter
AUTO no longer read as OFF, missing XAddr no longer becomes "(null)",
GetSystemDateAndTime without UTCDateTime no longer breaks the token
time (falls back to the local clock).
4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one
that has it (fallback to profile 0 with an error log); create() fails
cleanly when the device has no profiles instead of throwing.
5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S
(PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags.
6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer,
header only when a user name is set (anonymous devices), user name and
all string arguments XML-escaped. Requests are built by _buildRequest()
from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no
password until the device asks; Digest preferred) instead of Basic;
no HTTP auth without credentials.
Also: Content-Type without the trailing ';', GetServices/
GetDeviceInformation sent to the device service, printf format-string
bugs on device replies fixed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago  la_mojo cameras: track PTZ health and re-initialise a failed PTZ protocol
PTZ health per camera (deviceNodeCamera):
- PTZ_HEALTH_INFO: state (NONE / INIT / OK / FAILED), failure and
recovery counters, consecutive failed initialisations, time of the
last state change / failure, next retry and the last error text.
getPtzHealth() returns a copy (mutex-protected, any thread).
- getPtzStatus() - already sent to the remote server as
CAMERA_STATUS_PTZ_OK - now reflects it: 1 for OK (or no PTZ protocol),
0 while PTZ is initialising or failed. Before it was 1 as soon as the
state machine left CAM_WS_INIT, whatever the protocol did.
Failure detection and re-initialisation:
- While idle (CAM_WS_READY) the camera checks the protocol's validate()
every loop and calls the new protocolPTZ::probe() every 30 s
(ONVIF: GetStatus; a SOAP Fault still means "reachable", only a
communication error marks the camera lost). Default probe() is the
protocol's validate(), so serial protocols are unchanged.
- On failure the PTZ protocol is recreated through CAM_WS_INIT: first
attempt at once, then 5, 10, 20, 40, 60 s (capped) between attempts;
recoveries are logged and counted.
- A failed target-driven goAbsolute/goPreset no longer ends the camera
thread (CAM_WS_END rebuilt the whole node): for ONVIF a command the
camera rejected (connection OK) only drops that ROI, anything else
re-initialises the PTZ protocol.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
1 day ago |
|
#ifndef __PROTOCOL_PTZ_ONVIF_HEADER__
#define __PROTOCOL_PTZ_ONVIF_HEADER__
#include "protocolPTZ.h"
#define USE_PONVIF
#ifdef USE_PONVIF
#include "../ponvif/ponvif.h"
#else
#include "../onvif/include/onvifclient.hpp"
#endif
/*
Waiting for the end of an AbsoluteMove (waitMoveIsDone): - camera reports MoveStatus -> poll GetStatus until pan/tilt and zoom are IDLE - camera reports Position -> poll GetStatus until the target is reached or the position stops changing - camera reports neither -> fixed wait (PTZ_ONVIF_FIXED_MOVE_WAIT_MS) What the camera reports is detected once in create() (PTZ GetServiceCapabilities + a real GetStatus).*/#define PTZ_ONVIF_STATUS_POLL_MS 200 // GetStatus polling period
#define PTZ_ONVIF_MOVE_TIMEOUT_MS 10000 // give up waiting for the end of a move after this
#define PTZ_ONVIF_MOVE_START_GRACE_MS 1000 // a camera may still report IDLE / old position right after the command
#define PTZ_ONVIF_FIXED_MOVE_WAIT_MS 3000 // wait for cameras that report neither MoveStatus nor Position
#define PTZ_ONVIF_POS_TOLERANCE 0.01f // target reached (generic space units)
#define PTZ_ONVIF_POS_STABLE_EPS 0.001f // position "not changing" between two polls
#define PTZ_ONVIF_POS_STABLE_POLLS 2 // consecutive unchanged polls = move finished
#define PTZ_ONVIF_MAX_STATUS_FAILURES 3 // consecutive GetStatus failures before falling back to the fixed wait
class protocolPTZ_ONVIF : public protocolPTZ{ private:
basicLogCollection * m_pLog; char m_pUser[MAX_CRED_LEN]; char m_pPassword[MAX_CRED_LEN]; char m_pDeviceURI[MAX_PATH_LEN]; uint8_t m_bAuthMode;#ifdef USE_PONVIF
pOnvif * m_pOnVif; videoSourceProfile * m_pProfile;#else
OnvifClientDevice * m_pDevice; OnvifClientPTZ * m_pPTZ; std::string m_pPTZToken; std::string m_pMediaToken;#endif
config_setting_t * m_pSettings; basicMutex m_mInquiryMutex;#ifdef USE_PONVIF
bool m_bReportsMoveStatus; // camera reports PTZStatus/MoveStatus (IDLE/MOVING)
bool m_bReportsPosition; // camera reports PTZStatus/Position
bool m_bTargetValid; // m_fTarget* hold the last AbsoluteMove target
float m_fTargetPan; float m_fTargetTilt; float m_fTargetZoom;
void detectStatusSupport(void); bool commandResult(bool ok); bool fixedMoveWait(long alreadyWaitedMs);#endif
public:
explicit protocolPTZ_ONVIF(config_setting_t * Settings = NULL); protocolPTZ_ONVIF(CSTR ip, uint16_t port, CSTR username, CSTR password, uint8_t AuthMode = 0); protocolPTZ_ONVIF(CSTR ctl_url, CSTR username, CSTR password, uint8_t AuthMode = 0); virtual ~protocolPTZ_ONVIF(); virtual bool create(void);#ifndef USE_PONVIF
bool initCamera(void);#endif
virtual bool move(uint32_t MoveMatrix); virtual bool goAbsolute(float dPan, float dTilt, float dZoom); virtual bool goPreset(char * PresetToken); virtual bool getCameraPresets(void);
bool setIPAddress(CSTR ip); bool setUsername(CSTR username); bool setPassword(CSTR password); bool setAuthMode(uint8_t Mode); virtual bool waitMoveIsDone(void); virtual bool validate(); virtual bool probe(void);};
#endif
|