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.

3032 lines
74 KiB

​
​
​
5 months ago
​
​
3 years 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
8 hours 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
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
2 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years 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
8 hours 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
8 hours 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
8 hours 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
8 hours 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
8 hours 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
8 hours ago
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 months ago
​
​
​
​
2 months ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years 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
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months 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
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years 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
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "deviceNodeCamera.h"
  2. #include "../../components/base/basicCameraInfo.h"
  3. #include "../../components/object/objectSystemAnchor.h"
  4. #include "../../data/protocol/protocolPTZ_ONVIF.h"
  5. #include "../../data/protocol/protocolPTZ_PELCO.h"
  6. #include "../../data/protocol/protocolPTZ_VISCA.h"
  7. #include "../../data/protocol/protocolPTZ_BRCP.h"
  8. //#include "../../hardware/uart/serialPort.h"
  9. //#include "../../hardware/uart/serialSOL.h"
  10. #include "../mojo/mojoKernel.h"
  11. #include "hardwareManager.h"
  12. #include "hardwareResourceSerialProvider.h"
  13. #include "kernelModuleEmbedVideo.h"
  14. #define LOG(X) deviceNode::m_pLog->Log("RCAM", this, X)
  15. //#define DEBUG_EXTRA
  16. #ifdef DEBUG
  17. #define LOG_ERROR(X) \
  18. { \
  19. char _tBfrErrMSG2w34[512]; \
  20. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  21. deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  22. }
  23. #else
  24. #define LOG_ERROR(X) deviceNode::m_pLog->Log("RCAM", this, _LOG_ERROR, X);
  25. #endif
  26. // all sizes in mm
  27. static const float AC_imager_diag[12] = {5.0f, 5.68f, 6.0f, 6.592f, 8.0f, 8.933f, 11.0f, 16.0f, 22.5f, 30.1f, 43.3f, 69.7f};
  28. static const float AC_imager_width[12] = {4.0f, 4.536f, 4.8f, 5.27f, 6.4f, 7.176f, 8.8f, 12.8f, 18.0f, 25.1f, 36.0f, 56.0f};
  29. static const float AC_imager_height[12] = {3.0f, 3.416f, 3.6f, 3.96f, 4.8f, 5.319f, 6.6f, 9.6f, 13.5f, 16.7f, 24.0f, 41.5f};
  30. #define CAM_FOCAL_LENGTH_CNT 49
  31. static const float cam_predef_focal_length[CAM_FOCAL_LENGTH_CNT] = {2.7f, 3.0f, 3.2f, 3.5f, 3.7f, 3.9f, 4.0f, 4.3f, 4.8f, 5.0f, 5.1f, 5.5f, 5.8f, 6.0f, 6.2f, 6.6f, 7.0f, 7.1f, 7.5f, 7.6f, 8.0f, 8.6f, 8.9f, 9.0f, 9.2f, 9.3f, 10.0f, 10.5f, 10.6f,
  32. 10.7f, 11.0f, 11.3f, 12.0f, 12.9f, 13.0f, 13.5f, 13.6f, 14.0f, 14.6f, 15.0f, 15.1f, 15.5f, 16.0f, 17.0f, 17.5f, 17.7f, 18.0f, 18.2f, 19.0f};
  33. deviceNodeCamera::deviceNodeCamera(uint32_t NodeID) :
  34. deviceNode(NodeID),
  35. basicThread()
  36. {
  37. // m_pLog = basicLogCollection::getInstance();
  38. m_pBEH = basicEventHeap::getInstance();
  39. m_bSkeepPositioningWait = true;
  40. m_bNoMoveDoneReport = false;
  41. memset(&m_sPtzHealth, 0, sizeof(m_sPtzHealth));
  42. m_sPtzHealth.state = PTZ_HEALTH_INIT;
  43. m_sPtzHealth.since = time(NULL);
  44. m_tPtzLastProbe = 0;
  45. m_bNoAbsPositionning = false;
  46. m_bCameraOnHomePosition = false;
  47. m_tTimeTSeconds = 0;
  48. m_pProtocol = NULL;
  49. // m_pTransport = NULL;
  50. m_pCurrentROI = NULL;
  51. m_nRealFrameWidth = 640;
  52. // m_bState = 0;
  53. // m_bBusy = true;
  54. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  55. m_nRelativeMoveCounter = 0;
  56. m_bRelativeMoveMatrix = 0;
  57. m_bCurrentPresetCol = 0;
  58. m_bCurrentPresetRow = 0;
  59. m_bShineOnTarget = false;
  60. m_bCameraIsStatic = false;
  61. m_bIRIsOn = false;
  62. m_bIRTO = 0;
  63. m_fSpeedRise = 0.03f;
  64. m_fZoomCorrection = 1.0f;
  65. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  66. // m_bSourceConnected = false;
  67. // m_pSource = NULL;
  68. }
  69. deviceNodeCamera::deviceNodeCamera(DBC_NODE_DATA * Data) :
  70. deviceNode(Data),
  71. basicThread()
  72. {
  73. // m_pLog = basicLogCollection::getInstance();
  74. m_pBEH = basicEventHeap::getInstance();
  75. m_bSkeepPositioningWait = true;
  76. m_bNoMoveDoneReport = false;
  77. memset(&m_sPtzHealth, 0, sizeof(m_sPtzHealth));
  78. m_sPtzHealth.state = PTZ_HEALTH_INIT;
  79. m_sPtzHealth.since = time(NULL);
  80. m_tPtzLastProbe = 0;
  81. m_bNoAbsPositionning = false;
  82. m_bCameraOnHomePosition = false;
  83. m_tTimeTSeconds = 0;
  84. m_pProtocol = NULL;
  85. // m_pTransport = NULL;
  86. m_pCurrentROI = NULL;
  87. m_nRealFrameWidth = 640;
  88. // m_bState = 0;
  89. // m_bBusy = true;
  90. m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
  91. m_nRelativeMoveCounter = 0;
  92. m_bRelativeMoveMatrix = 0;
  93. m_bCurrentPresetCol = 0;
  94. m_bCurrentPresetRow = 0;
  95. m_bShineOnTarget = false;
  96. m_bIRIsOn = false;
  97. m_bIRTO = 0;
  98. m_fSpeedRise = 0.03f;
  99. m_fZoomCorrection = 1.0f;
  100. m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
  101. // m_bSourceConnected = false;
  102. // m_pSource = NULL;
  103. }
  104. deviceNodeCamera::~deviceNodeCamera()
  105. {
  106. LOG("Destruct");
  107. // m_mQPROTECTOR.unlock();
  108. waitThreadEnd(true);
  109. LOG("Thread Del OK");
  110. /*if( m_pTransport!= NULL ) {
  111. if( m_sCamData.uart_id ) {
  112. DBC_UART_DATA *tData = NULL;
  113. tData = m_pDBC->getUartData( m_sCamData.uart_id );
  114. switch( tData->type ) {
  115. case UART_TYPE_HARDWARE:{
  116. delete((serialPort*)m_pTransport);
  117. break;
  118. };
  119. case UART_TYPE_SOL:{
  120. delete((serialSOL*)m_pTransport);
  121. break;
  122. };
  123. };
  124. };
  125. };
  126. LOG("Transport Del OK");
  127. */
  128. if (m_pProtocol != NULL)
  129. {
  130. switch (m_sCamData.protocol)
  131. {
  132. case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
  133. case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
  134. case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
  135. case CAM_CTRL_PROTO_BRCP: delete((protocolPTZ_BRCP *) m_pProtocol); break;
  136. default : delete(m_pProtocol);
  137. };
  138. };
  139. LOG("Proto Del OK");
  140. // if( m_pPosition != NULL ) delete( m_pPosition );
  141. // LOG("Pos Del OK");
  142. // if( m_bSourceConnected ){
  143. // if( m_pSource != NULL ){
  144. // m_pSource->_close();
  145. // delete( m_pSource );
  146. // };
  147. // };
  148. // LOG("Stream Del OK");
  149. }
  150. void deviceNodeCamera::updateOpticalParameters(uint16_t frame_width, uint16_t frame_heigth)
  151. {
  152. #ifdef DEBUG
  153. char tB[128];
  154. LOG("Set Optical Parameters");
  155. sprintf(tB, "\tCapturing Frame: %dx%d ", frame_width, frame_heigth);
  156. LOG(tB);
  157. #endif
  158. if (frame_width > 0 && frame_heigth > 0)
  159. {
  160. m_nRealFrameWidth = frame_width;
  161. m_nRealFrameHeight = frame_heigth;
  162. float tFrameDiag = sqrtf(m_nRealFrameHeight * m_nRealFrameHeight + m_nRealFrameWidth * m_nRealFrameWidth);
  163. switch (m_sCamData.zoom_model)
  164. {
  165. case 0:
  166. {
  167. #ifdef DEBUG
  168. LOG("\tFixed Zoom");
  169. #endif
  170. m_fMaxFL = m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  171. m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
  172. m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
  173. m_fR2FL = .0f;
  174. m_fZoomCorrection = .0f;
  175. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  176. break;
  177. };
  178. case 1:
  179. {
  180. #ifdef DEBUG
  181. LOG("\tAutomated Zoom");
  182. #endif
  183. m_fMinFL = cam_predef_focal_length[m_sCamData.lens_f];
  184. m_fMinRange = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMinFL, tFrameDiag);
  185. m_fMaxFL = cam_predef_focal_length[m_sCamData.lens_f] * m_sCamData.zoom;
  186. m_fMaxRange = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], m_fMaxFL, tFrameDiag);
  187. if (m_fMaxRange > m_fMinRange)
  188. {
  189. m_fR2FL = ((m_fMaxFL - m_fMinFL) / (m_fMaxRange - m_fMinRange));
  190. }
  191. else
  192. {
  193. m_fR2FL = .0f;
  194. };
  195. m_fZoomCorrection = 1.0f;
  196. m_pDBC->updateCamRange(m_sCamData.id, m_fMaxRange);
  197. break;
  198. };
  199. case 2:
  200. {
  201. #ifdef DEBUG
  202. LOG("\tManual Zoom");
  203. #endif
  204. //The Fixing minimal distance from 5 meters to a 0.5
  205. m_fMinRange = 0.5f; // Minimal 0.5 meters
  206. if (m_sCamData.max_range < m_fMinRange)
  207. {
  208. m_fMaxRange = m_fMinRange;
  209. }
  210. else
  211. {
  212. m_fMaxRange = m_sCamData.max_range;
  213. };
  214. m_fZoomCorrection = m_sCamData.zoom * 0.01f;
  215. m_fMinFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMinRange);//, tFrameDiag);
  216. m_fMaxFL = calcCFL(AC_imager_width[m_sCamData.imager_type], m_fMaxRange);//, tFrameDiag);
  217. break;
  218. };
  219. };
  220. m_fMinHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMaxFL));
  221. m_fMaxHFov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], m_fMinFL));
  222. m_fMinVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMaxFL));
  223. m_fMaxVFov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], m_fMinFL));
  224. #ifdef DEBUG
  225. sprintf(tB, "\tMinimal FL: %0.3fmm. Maximal FL: %0.3fmm. ", m_fMinFL, m_fMaxFL);
  226. LOG(tB);
  227. sprintf(tB, "\tMinimal Range: %0.2fm. Maximal Range: %0.2fm. ", m_fMinRange, m_fMaxRange);
  228. LOG(tB);
  229. sprintf(tB, "\tMinimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov);
  230. LOG(tB);
  231. sprintf(tB, "\tMaximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov);
  232. LOG(tB);
  233. #endif
  234. };
  235. }
  236. bool deviceNodeCamera::create()
  237. {
  238. if (m_bThreadStatus == TH_WORKING)
  239. {
  240. return true;
  241. }
  242. setWM(CAM_WS_INIT);
  243. if (m_sNodeData.aux_id == 0)
  244. {
  245. return false;
  246. }
  247. DBC_CAM_DATA * tData = m_pDBC->getCamData(m_sNodeData.aux_id);
  248. if (tData != NULL)
  249. {
  250. memcpy(&m_sCamData, tData, sizeof(DBC_CAM_DATA));
  251. free(tData);
  252. }
  253. else
  254. {
  255. LOG_ERROR("Cannot Fetch CAM Data from Database!");
  256. return false;
  257. };
  258. if (! (m_sCamData.lens_f < CAM_FOCAL_LENGTH_CNT))
  259. {
  260. m_sCamData.lens_f = CAM_FOCAL_LENGTH_CNT - 1;
  261. }
  262. updateOpticalParameters(1280, 720); // HD Ready
  263. if (m_sCamData.ptz_speed_step > .0f)
  264. {
  265. m_fSpeedRise = m_sCamData.ptz_speed_step;
  266. };
  267. // m_pPosition = new basicPosition();// m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
  268. // if( m_pPosition == NULL ) {
  269. // LOG_ERROR("Position Constructor Failure!");
  270. // return false;
  271. // };
  272. // m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
  273. // m_oPosition.setOrientationDeg( m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot );
  274. systemAnchor * SA = systemAnchor::getInstance();
  275. if( SA ){
  276. LOG("SysAnchor OK");
  277. if( SA->beLocal() ){
  278. LOG("SysAnchor beLocal!");
  279. m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z, 0); // SA->getUTMZone() );
  280. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  281. } else {
  282. LOG("SysAnchor is Global Position System!");
  283. C3D_DECART LD = SA->getXYZ();
  284. m_oPosition.setPositionXYZ(LD.x + m_sCamData.x, LD.y + m_sCamData.y, LD.z + m_sCamData.z, SA->getUTMZone());
  285. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  286. };
  287. } else {
  288. LOG("No SysAnchor!");
  289. m_oPosition.setPositionXYZ(m_sCamData.x, m_sCamData.y, m_sCamData.z);
  290. m_oPosition.setOrientationDeg(m_sCamData.x_rot, m_sCamData.y_rot, m_sCamData.z_rot);
  291. };
  292. m_oPosition.updateMatrix();
  293. #ifdef DEBUG
  294. char tB[128];
  295. sprintf(tB, "Finalized Camera Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt());
  296. LOG(tB);
  297. sprintf(tB, "Finalized Camera Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ());
  298. LOG(tB);
  299. sprintf(tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg());
  300. LOG(tB);
  301. #endif
  302. if (m_pProtocol != NULL)
  303. {
  304. LOG_ERROR("Cannot Start: Service Already Running!");
  305. return false;
  306. };
  307. #ifdef CAM_POST_INIT
  308. if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
  309. {
  310. m_bNoAbsPositionning = true;
  311. }
  312. if (m_sCamData.protocol == 0)
  313. {
  314. m_bCameraIsStatic = true;
  315. m_bSkeepPositioningWait = true;
  316. m_sCamData.online = true;
  317. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  318. return m_sCamData.online;
  319. };
  320. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  321. return init();
  322. #else //! CAM_POST_INIT
  323. switch (m_sCamData.protocol)
  324. {
  325. case CAM_CTRL_PROTO_VISCA:
  326. {
  327. #ifdef DEBUG
  328. LOG("VISCA");
  329. #endif
  330. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
  331. if (m_pProtocol != NULL)
  332. {
  333. basicTransport * tTransport = NULL;
  334. hardwareManager * tHM = hardwareManager::getInstance();
  335. if (tHM)
  336. {
  337. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  338. if (tRES != NULL)
  339. {
  340. if (tRES->isValid())
  341. {
  342. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  343. if (m_pProtocol->setTransport(tTransport))
  344. {
  345. if (! m_pProtocol->create())
  346. {
  347. LOG_ERROR("Protocol <<< Create >>> Failure!");
  348. };
  349. }
  350. else
  351. {
  352. LOG_ERROR("Binding Port Failure!");
  353. };
  354. };
  355. #ifdef DEBUG
  356. }
  357. else
  358. {
  359. LOG("HWM Has No UART PORT!");
  360. #endif
  361. };
  362. #ifdef DEBUG
  363. }
  364. else
  365. {
  366. LOG_ERROR("Can not get Hardware Manager!");
  367. #endif
  368. };
  369. if (tTransport != NULL)
  370. {
  371. LOG("Bind Transport Port!");
  372. }
  373. else
  374. {
  375. LOG_ERROR("Transport Creation Failure!");
  376. delete((protocolPTZ_VISCA *) m_pProtocol);
  377. m_pProtocol = NULL;
  378. };
  379. #ifdef DEBUG
  380. }
  381. else
  382. {
  383. LOG_ERROR("Protocol Creation failure!");
  384. #endif
  385. };
  386. break;
  387. };
  388. case CAM_CTRL_PROTO_PELCO:
  389. {
  390. #ifdef DEBUG
  391. LOG("PELCO");
  392. #endif
  393. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
  394. if (m_pProtocol != NULL)
  395. {
  396. basicTransport * tTransport = NULL;
  397. hardwareManager * tHM = hardwareManager::getInstance();
  398. if (tHM)
  399. {
  400. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  401. if (tRES != NULL)
  402. {
  403. if (tRES->isValid())
  404. {
  405. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  406. if (m_pProtocol->setTransport(tTransport))
  407. {
  408. if (! m_pProtocol->create())
  409. {
  410. LOG_ERROR("Protocol <<< Create >>> Failure!");
  411. };
  412. }
  413. else
  414. {
  415. LOG_ERROR("Binding Port Failure!");
  416. };
  417. };
  418. #ifdef DEBUG
  419. }
  420. else
  421. {
  422. LOG("HWM Has No UART PORT!");
  423. #endif
  424. };
  425. #ifdef DEBUG
  426. }
  427. else
  428. {
  429. LOG_ERROR("Can not get Hardware Manager!");
  430. #endif
  431. };
  432. if (tTransport != NULL)
  433. {
  434. LOG("Bind Transport Port!");
  435. }
  436. else
  437. {
  438. LOG_ERROR("Transport Creation Failure!");
  439. delete((protocolPTZ_PELCO *) m_pProtocol);
  440. m_pProtocol = NULL;
  441. };
  442. #ifdef DEBUG
  443. }
  444. else
  445. {
  446. LOG_ERROR("Protocol Creation failure!");
  447. #endif
  448. };
  449. break;
  450. };
  451. case CAM_CTRL_PROTO_ONVIF:
  452. {
  453. #ifdef DEBUG_EXTRA
  454. LOG("ONVIF");
  455. #endif
  456. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  457. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  458. {
  459. char tURI[256];
  460. if (m_sCamData.port)
  461. {
  462. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  463. }
  464. else
  465. {
  466. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  467. };
  468. LOG("PTZ BUILD URI");
  469. LOG(tURI);
  470. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  471. }
  472. else
  473. {
  474. LOG("USE FULL PTZ URI");
  475. LOG(m_sCamData.onvif_ctrl);
  476. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  477. };
  478. #ifdef DEBUG_EXTRA
  479. LOG("ONVIF-END");
  480. #endif
  481. if (m_pProtocol != NULL)
  482. {
  483. if (! m_pProtocol->create())
  484. {
  485. LOG_ERROR("Error Creating Proto!");
  486. delete((protocolPTZ_ONVIF *) m_pProtocol);
  487. m_pProtocol = NULL;
  488. };
  489. #ifdef DEBUG_EXTRA
  490. LOG("PROTO CREATE DONE");
  491. #endif
  492. };
  493. break;
  494. };
  495. case CAM_CTRL_PROTO_BRCP:{
  496. #ifdef DEBUG
  497. LOG("BRCP");
  498. #endif
  499. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  500. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  501. {
  502. char tURI[256];
  503. if (m_sCamData.port)
  504. {
  505. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  506. }
  507. else
  508. {
  509. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  510. };
  511. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  512. }
  513. else
  514. {
  515. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  516. };
  517. #ifdef DEBUG
  518. LOG("BRCP-END");
  519. #endif
  520. if (m_pProtocol != NULL)
  521. {
  522. if (! m_pProtocol->create())
  523. {
  524. LOG_ERROR("Error Creating Proto!");
  525. delete((protocolPTZ_BRCP *) m_pProtocol);
  526. m_pProtocol = NULL;
  527. };
  528. #ifdef DEBUG
  529. LOG("PROTO CREATE DONE");
  530. #endif
  531. };
  532. break;
  533. };
  534. default:
  535. {
  536. #ifdef DEBUG
  537. LOG("Camera Has no defined control protocol");
  538. #endif
  539. };
  540. };
  541. // Check - No ABS Movement!
  542. if ((m_sCamData.type == ARGUS_IP_PRESET_CAMERA) || (m_sCamData.type == ARGUS_ANALOG_PRESET_CAMERA))
  543. {
  544. m_bNoAbsPositionning = true;
  545. }
  546. if (m_pProtocol == NULL)
  547. {
  548. if (m_sCamData.protocol == 0)
  549. {
  550. m_bCameraIsStatic = true;
  551. m_bSkeepPositioningWait = true;
  552. m_sCamData.online = true;
  553. }
  554. else
  555. {
  556. LOG_ERROR("No Proto Created!");
  557. }
  558. }
  559. else
  560. {
  561. #ifdef DEBUG
  562. LOG("Proto is OK");
  563. #endif
  564. // Load Presets only if we have protocol
  565. load_presets();
  566. mojoKernel * tKRNL = mojoKernel::getInstance();
  567. m_bNoMoveDoneReport = false;
  568. if (tKRNL)
  569. {
  570. m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
  571. #ifdef DEBUG
  572. char ttTT[128];
  573. sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
  574. LOG(ttTT);
  575. if (m_bSkeepPositioningWait)
  576. {
  577. LOG("Camera No Wait On Pos!");
  578. }
  579. else
  580. {
  581. LOG("Camera Will Wait On Pos!");
  582. };
  583. #endif
  584. }
  585. else
  586. {
  587. LOG_ERROR("No Kernel Instance!");
  588. };
  589. m_sCamData.online = init();
  590. };
  591. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  592. return m_sCamData.online;
  593. #endif //! CAM_POST_INIT
  594. }
  595. // void deviceNodeCamera::setBusy( bool Status ){
  596. // m_bBusy = Status;
  597. //};
  598. bool deviceNodeCamera::relativeMove(float PanSPD, float TiltSPD, float ZoomSPD)
  599. {
  600. if (m_sCamData.online)
  601. {
  602. uint32_t MoveMatrix = 0;
  603. if (PanSPD != .0f)
  604. {
  605. if (PanSPD > 0)
  606. {
  607. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
  608. {
  609. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  610. }
  611. else
  612. {
  613. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  614. };
  615. }
  616. else
  617. {
  618. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 2)
  619. {
  620. MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
  621. }
  622. else
  623. {
  624. MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
  625. };
  626. };
  627. };
  628. if (TiltSPD != .0f)
  629. {
  630. if (TiltSPD > 0)
  631. {
  632. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
  633. {
  634. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  635. }
  636. else
  637. {
  638. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  639. };
  640. }
  641. else
  642. {
  643. if (m_sCamData.flip_mode == 0 || m_sCamData.flip_mode == 1)
  644. {
  645. MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
  646. }
  647. else
  648. {
  649. MoveMatrix |= PTZ_DRIVE_TILT_UP;
  650. };
  651. };
  652. };
  653. if (ZoomSPD != .0f)
  654. {
  655. if (ZoomSPD > 0)
  656. {
  657. MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
  658. }
  659. else
  660. {
  661. MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
  662. };
  663. };
  664. if (MoveMatrix != 0)
  665. {
  666. m_pProtocol->setPTZSpeed(fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD));
  667. };
  668. return m_pProtocol->move(MoveMatrix);
  669. };
  670. return false;
  671. }
  672. bool deviceNodeCamera::relativeStop()
  673. {
  674. if (m_sCamData.online)
  675. {
  676. return m_pProtocol->move(0);
  677. };
  678. return false;
  679. }
  680. CAM_TASK * deviceNodeCamera::fetchCamTask(void)
  681. {
  682. CAM_TASK * rVal = NULL;
  683. m_mQPROTECTOR.lock();
  684. if (m_qCAM_TASK.size())
  685. {
  686. rVal = m_qCAM_TASK.front();
  687. m_qCAM_TASK.pop();
  688. };
  689. m_mQPROTECTOR.unlock();
  690. return rVal;
  691. }
  692. bool deviceNodeCamera::pushCamTask(CAM_TASK * ptr)
  693. {
  694. if (ptr == NULL)
  695. {
  696. return false;
  697. }
  698. m_mQPROTECTOR.lock();
  699. m_qCAM_TASK.push(ptr);
  700. m_mQPROTECTOR.unlock();
  701. return true;
  702. }
  703. #ifndef NO_CAMERA_FUSION_ENGINE
  704. bool deviceNodeCamera::fusion_compare(CAM_ROI * ptr, C3D_SPH_DEGREES tp)
  705. {
  706. if (ptr == NULL)
  707. {
  708. return false;
  709. }
  710. float tFI = fabsf(ptr->cam_position.fi - tp.fi);
  711. float tTETTA = fabsf(ptr->cam_position.tetta - tp.tetta);
  712. #ifdef DEBUG_ALL
  713. char tB[128];
  714. sprintf(tB, "FC: FOV:[%.5f:%.5f] dTG:[%.5f:%.5f] %.2f<%.2f>%.2f", ptr->h_fov, ptr->v_fov, tFI, tTETTA, ptr->min_range, tp.r, ptr->max_range);
  715. LOG(tB);
  716. #endif
  717. if (tFI > ptr->h_fov)
  718. {
  719. return false;
  720. }
  721. if (tTETTA > ptr->v_fov)
  722. {
  723. return false;
  724. }
  725. if (tp.r < ptr->min_range)
  726. {
  727. return false;
  728. }
  729. if (tp.r > ptr->max_range)
  730. {
  731. return false;
  732. }
  733. return true;
  734. }
  735. bool deviceNodeCamera::fusion_consumeData(uint32_t db_id, C3D_SPH_DEGREES tOR)
  736. {
  737. if (db_id == 0)
  738. {
  739. return false;
  740. }
  741. CAM_TRACK_RECORD * tTrackRecord = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  742. if (tTrackRecord == NULL)
  743. {
  744. return false;
  745. }
  746. #ifdef DEBUG_EXTRA
  747. LOG("Fusion: Consuming new Data!");
  748. #endif
  749. memset(tTrackRecord, 0, sizeof(CAM_TRACK_RECORD));
  750. tTrackRecord->target_direction.fi = tOR.fi;
  751. tTrackRecord->target_direction.r = tOR.r;
  752. tTrackRecord->target_direction.tetta = tOR.tetta;
  753. tTrackRecord->evt_db_ID = db_id;
  754. tTrackRecord->ts_ms = getMilliseconds();
  755. m_mROIsProtector.lock();
  756. vCAM_ROIS::iterator idx = m_vROIS.begin();
  757. for (; idx < m_vROIS.end(); idx++)
  758. {
  759. if (fusion_compare(*idx, tOR))
  760. {
  761. break;
  762. }
  763. }
  764. if (idx != m_vROIS.end())
  765. {
  766. // have Match!
  767. #ifdef DEBUG_EXTRA
  768. LOG("ROI MATCHED!");
  769. #endif
  770. (*idx)->targets.push_back(tTrackRecord);
  771. fusion_validateROI(tTrackRecord->ts_ms, *idx);
  772. }
  773. else
  774. {
  775. #ifdef DEBUG_EXTRA
  776. LOG("NO MATCH FOUND!");
  777. #endif
  778. // No mathced ROI -> create new one
  779. //CAM_ROI * tROI = (CAM_ROI *) malloc(sizeof(CAM_ROI));
  780. CAM_ROI * tROI = new CAM_ROI();
  781. if (tROI)
  782. {
  783. tROI->ts_ms = tTrackRecord->ts_ms;
  784. spherical2onvif(tOR, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  785. tROI->cam_position.fi = tOR.fi;
  786. tROI->cam_position.tetta = tOR.tetta;
  787. tROI->cam_position.r = tOR.r;
  788. float cFL = m_fMinFL + m_fR2FL * (tROI->cam_position.r - m_fMinRange);
  789. tROI->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  790. tROI->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  791. tROI->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to no to div in comparation function
  792. tROI->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // that will be called more ofthen
  793. tROI->targets.push_back(tTrackRecord);
  794. m_vROIS.push_back(tROI);
  795. };
  796. };
  797. m_mROIsProtector.unlock();
  798. return true;
  799. }
  800. bool deviceNodeCamera::fusion_validateROI(uint64_t cts, CAM_ROI * ptr)
  801. {
  802. if (ptr == NULL)
  803. {
  804. return false;
  805. }
  806. if ((cts - ptr->ts_ms) > LOSE_INTERES_TIME_MS)
  807. {
  808. return false;
  809. }
  810. #ifdef DEBUG_EXTRA
  811. char tB[128];
  812. sprintf(tB, "\tROI [%d]", ptr->targets.size());
  813. LOG(tB);
  814. #endif
  815. if (ptr->targets.size())
  816. {
  817. double tA = 0.0;
  818. double tB = 0.0;
  819. double tC = 0.0;
  820. uint32_t tCNT = 0;
  821. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end();)
  822. {
  823. if ((cts - (*idx)->ts_ms) > LOSE_INTERES_TIME_MS)
  824. {
  825. free(*idx);
  826. ptr->targets.erase(idx);
  827. }
  828. else
  829. {
  830. tA = tA + (*idx)->target_direction.fi;
  831. tB = tB + (*idx)->target_direction.tetta;
  832. tC = tC + (*idx)->target_direction.r;
  833. tCNT++;
  834. idx++;
  835. };
  836. };
  837. if (tCNT)
  838. {
  839. C3D_SPH_DEGREES L;// = {0};
  840. //memset( &L, 0, sizeof(C3D_SPH_DEGREES));
  841. L.fi = (float) (tA / (double) tCNT);
  842. L.tetta = (float) (tB / (double) tCNT);
  843. L.r = (float) (tC / (double) tCNT);
  844. spherical2onvif(L, ptr->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  845. ptr->ts_ms = cts;
  846. float cFL = m_fMinFL + m_fR2FL * (ptr->cam_position.r - m_fMinRange);
  847. ptr->max_range = calcMaxDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  848. ptr->min_range = calcMinDistance_mm(AC_imager_diag[m_sCamData.imager_type], cFL, m_nRealFrameWidth);
  849. ptr->h_fov = rad2deg(calcFOV_mm(AC_imager_width[m_sCamData.imager_type], cFL)) / 2.0f; // div to prevent division in comparation
  850. ptr->v_fov = rad2deg(calcFOV_mm(AC_imager_height[m_sCamData.imager_type], cFL)) / 2.0f; // function that will be called more ofthen
  851. return true;
  852. };
  853. };
  854. return false;
  855. }
  856. CAM_ROI * deviceNodeCamera::fusion_fetchROI(void)
  857. {
  858. CAM_ROI * tVAL = NULL;
  859. m_mROIsProtector.lock();
  860. if (m_vROIS.size())
  861. {
  862. vCAM_ROIS::iterator sRec;
  863. uint64_t cts = 0;
  864. for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end(); idx++)
  865. {
  866. if (tVAL == NULL)
  867. {
  868. sRec = idx;
  869. tVAL = (*idx);
  870. cts = tVAL->ts_ms;
  871. }
  872. else
  873. {
  874. #ifdef CAM_FETCH_ROI_NEWEST
  875. if ((*idx)->ts_ms > cts)
  876. #else
  877. if ((*idx)->ts_ms < cts)
  878. #endif
  879. {
  880. sRec = idx;
  881. tVAL = (*idx);
  882. cts = tVAL->ts_ms;
  883. };
  884. };
  885. };
  886. m_vROIS.erase(sRec);
  887. };
  888. m_mROIsProtector.unlock();
  889. if (m_bNoAbsPositionning && tVAL)
  890. {
  891. // Skip targets older 3 seconds
  892. if (getMilliseconds() - tVAL->ts_ms > 3000)
  893. #ifdef DEBUG_EXTRA
  894. {
  895. LOG("Targetd too old! ---> Skiping");
  896. utilizeROI(tVAL);
  897. };
  898. #else
  899. utilizeROI(tVAL);
  900. #endif
  901. };
  902. return tVAL;
  903. }
  904. DBC_SNAPSHOT_DATA * deviceNodeCamera::fusion_translate_ROI(CAM_ROI *(&ptr))
  905. {
  906. DBC_SNAPSHOT_DATA * rVal = NULL;
  907. if (ptr == NULL)
  908. {
  909. return NULL;
  910. }
  911. if (ptr->targets.size())
  912. {
  913. //rVal = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
  914. rVal = new DBC_SNAPSHOT_DATA();
  915. if (rVal)
  916. {
  917. //memset(rVal, 0, sizeof(DBC_SNAPSHOT_DATA));
  918. rVal->stream_id = m_sNodeData.aux_parameter;
  919. for (vCAM_TRACK_RECORDS::iterator idx = ptr->targets.begin(); idx < ptr->targets.end(); idx++)
  920. {
  921. rVal->assoc_event_ids.push_back((*idx)->evt_db_ID);
  922. }
  923. };
  924. ptr->targets.clear();
  925. }
  926. else
  927. {
  928. LOG_ERROR("No Events ID to ROI");
  929. };
  930. utilizeROI(ptr);
  931. // Not Setting MD5 and TS -> will set at capture time
  932. return rVal;
  933. }
  934. void deviceNodeCamera::fusion_validate(void)
  935. {
  936. if (m_bNoAbsPositionning)
  937. {
  938. return;
  939. }
  940. m_mROIsProtector.lock();
  941. if (m_vROIS.size())
  942. {
  943. #ifdef DEBUG_EXTRA
  944. char tB[128];
  945. sprintf(tB, "Fusion: Have [%d] Regions Of Interes", m_vROIS.size());
  946. LOG(tB);
  947. #endif
  948. uint64_t cts = getMilliseconds();
  949. for (vCAM_ROIS::iterator idx = m_vROIS.begin(); idx != m_vROIS.end();)
  950. {
  951. if (! fusion_validateROI(cts, *idx))
  952. {
  953. utilizeROI(*idx);
  954. m_vROIS.erase(idx);
  955. }
  956. else
  957. {
  958. idx++;
  959. }
  960. };
  961. };
  962. m_mROIsProtector.unlock();
  963. }
  964. #endif // !NO_CAMERA_FUSION_ENGINE
  965. bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, float PanPOS, float TiltPOS, float ZoomPOS)
  966. {
  967. //if (m_sCamData.online)
  968. {
  969. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  970. if (tTask)
  971. {
  972. memset(tTask, 0, sizeof(CAM_TASK));
  973. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  974. if (tTask->CMD)
  975. {
  976. tTask->CMD->CMD = PTZ_ABSOLUTE;
  977. tTask->CMD->PAN = PanPOS;
  978. tTask->CMD->TILT = TiltPOS;
  979. tTask->CMD->ZOOM = ZoomPOS;
  980. tTask->movemet_needed = true;
  981. tTask->source_evt_id = TargetRefID;
  982. setWM(CAM_WS_BUSY);
  983. return pushCamTask(tTask);
  984. }
  985. else
  986. {
  987. LOG_ERROR("CMD malloc Error!");
  988. free(tTask);
  989. };
  990. }
  991. else
  992. {
  993. LOG_ERROR("Task malloc error!");
  994. }
  995. };
  996. return false;
  997. }
  998. bool deviceNodeCamera::absoluteMove(uint32_t TargetRefID, C3D_ORIENT_ONVIF O)
  999. {
  1000. //if (m_sCamData.online)
  1001. {
  1002. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  1003. if (tTask)
  1004. {
  1005. memset(tTask, 0, sizeof(CAM_TASK));
  1006. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  1007. if (tTask->CMD)
  1008. {
  1009. tTask->CMD->CMD = PTZ_ABSOLUTE;
  1010. tTask->CMD->PAN = O.pan;
  1011. tTask->CMD->TILT = O.tilt;
  1012. tTask->CMD->ZOOM = O.zoom;
  1013. tTask->movemet_needed = true;
  1014. tTask->source_evt_id = TargetRefID;
  1015. setWM(CAM_WS_BUSY);
  1016. return pushCamTask(tTask);
  1017. }
  1018. else
  1019. {
  1020. LOG_ERROR("CMD malloc Error!");
  1021. free(tTask);
  1022. };
  1023. }
  1024. else
  1025. {
  1026. LOG_ERROR("Task malloc error!");
  1027. }
  1028. };
  1029. return false;
  1030. }
  1031. // PTZ control status for the health report: 1 = PTZ works (or the camera has no PTZ), 0 = PTZ failed / not ready
  1032. uint8_t deviceNodeCamera::getPtzStatus()
  1033. {
  1034. if (m_sCamData.protocol == 0)
  1035. {
  1036. return 1;
  1037. }
  1038. m_mPtzHealth.lock();
  1039. PTZ_HEALTH_STATE tState = m_sPtzHealth.state;
  1040. m_mPtzHealth.unlock();
  1041. return (tState == PTZ_HEALTH_OK || tState == PTZ_HEALTH_NONE) ? 1 : 0;
  1042. }
  1043. void deviceNodeCamera::getPtzHealth(PTZ_HEALTH_INFO * info)
  1044. {
  1045. if (info == NULL)
  1046. {
  1047. return;
  1048. }
  1049. m_mPtzHealth.lock();
  1050. memcpy(info, &m_sPtzHealth, sizeof(PTZ_HEALTH_INFO));
  1051. m_mPtzHealth.unlock();
  1052. }
  1053. /*
  1054. State changes of the PTZ health. FAILED schedules the next re-initialisation: the first one right away
  1055. (the camera may just have rebooted), then CAM_PTZ_RETRY_MIN_S doubling up to CAM_PTZ_RETRY_MAX_S.
  1056. */
  1057. void deviceNodeCamera::ptzHealthSet(PTZ_HEALTH_STATE state, const char * reason)
  1058. {
  1059. time_t tNow = time(NULL);
  1060. char tB[256];
  1061. tB[0] = (char) 0;
  1062. m_mPtzHealth.lock();
  1063. PTZ_HEALTH_STATE tOld = m_sPtzHealth.state;
  1064. if (state == PTZ_HEALTH_FAILED)
  1065. {
  1066. if (tOld != PTZ_HEALTH_FAILED)
  1067. {
  1068. m_sPtzHealth.failures++;
  1069. m_sPtzHealth.failed_inits = 0;
  1070. m_sPtzHealth.next_retry = tNow;
  1071. }
  1072. else
  1073. {
  1074. // another failed initialisation
  1075. m_sPtzHealth.failed_inits++;
  1076. uint32_t tDelay = CAM_PTZ_RETRY_MIN_S;
  1077. for (uint32_t i = 1; i < m_sPtzHealth.failed_inits && tDelay < CAM_PTZ_RETRY_MAX_S; i++)
  1078. {
  1079. tDelay *= 2;
  1080. }
  1081. if (tDelay > CAM_PTZ_RETRY_MAX_S)
  1082. {
  1083. tDelay = CAM_PTZ_RETRY_MAX_S;
  1084. }
  1085. m_sPtzHealth.next_retry = tNow + tDelay;
  1086. };
  1087. m_sPtzHealth.last_failure = tNow;
  1088. snprintf(m_sPtzHealth.last_error, sizeof(m_sPtzHealth.last_error), "%s", (reason != NULL) ? reason : "PTZ failure");
  1089. snprintf(tB, sizeof(tB), "PTZ FAILED (%s), failures %u, next re-init in %ld s", m_sPtzHealth.last_error, m_sPtzHealth.failures,
  1090. (long) (m_sPtzHealth.next_retry - tNow));
  1091. }
  1092. else
  1093. {
  1094. if (state == PTZ_HEALTH_OK && tOld == PTZ_HEALTH_FAILED)
  1095. {
  1096. m_sPtzHealth.recoveries++;
  1097. snprintf(tB, sizeof(tB), "PTZ recovered after %u failed attempt(s), recoveries %u", m_sPtzHealth.failed_inits + 1, m_sPtzHealth.recoveries);
  1098. }
  1099. m_sPtzHealth.failed_inits = 0;
  1100. m_sPtzHealth.next_retry = 0;
  1101. };
  1102. if (state != tOld)
  1103. {
  1104. m_sPtzHealth.since = tNow;
  1105. }
  1106. m_sPtzHealth.state = state;
  1107. m_mPtzHealth.unlock();
  1108. if (tB[0])
  1109. {
  1110. if (state == PTZ_HEALTH_FAILED)
  1111. {
  1112. LOG_ERROR(tB);
  1113. }
  1114. else
  1115. {
  1116. LOG(tB);
  1117. }
  1118. };
  1119. }
  1120. // CAM_WS_INIT may (re)create the protocol now? Only throttled while FAILED.
  1121. bool deviceNodeCamera::ptzReinitDue(void)
  1122. {
  1123. m_mPtzHealth.lock();
  1124. bool tDue = (m_sPtzHealth.state != PTZ_HEALTH_FAILED) || (time(NULL) >= m_sPtzHealth.next_retry);
  1125. m_mPtzHealth.unlock();
  1126. return tDue;
  1127. }
  1128. /*
  1129. A target-driven PTZ command failed. Before, the camera thread ended (CAM_WS_END -> the node was rebuilt).
  1130. Now: ONVIF tells apart a rejected command (SOAP Fault, camera reachable -> validate() still true: drop this
  1131. ROI and carry on) from a lost camera. Every other failure re-initialises the PTZ protocol.
  1132. */
  1133. void deviceNodeCamera::ptzCommandFailed(const char * command)
  1134. {
  1135. char tB[160];
  1136. utilizeROI(m_pCurrentROI);
  1137. if (m_sCamData.protocol == CAM_CTRL_PROTO_ONVIF && m_pProtocol != NULL && m_pProtocol->validate())
  1138. {
  1139. snprintf(tB, sizeof(tB), "%s rejected by the camera (see the PONVIF log), PTZ connection OK", command);
  1140. LOG_ERROR(tB);
  1141. setWM(CAM_WS_READY);
  1142. return;
  1143. }
  1144. snprintf(tB, sizeof(tB), "%s failed: PTZ protocol lost", command);
  1145. ptzLost(tB);
  1146. }
  1147. // The PTZ protocol was lost: mark FAILED and re-initialise it (CAM_WS_INIT deletes and recreates it).
  1148. void deviceNodeCamera::ptzLost(const char * reason)
  1149. {
  1150. ptzHealthSet(PTZ_HEALTH_FAILED, reason);
  1151. setWM(CAM_WS_INIT);
  1152. }
  1153. /*
  1154. Called every loop of the camera thread. Only while idle (CAM_WS_READY), so moves are not disturbed:
  1155. - the protocol's own status (validate) is checked every loop;
  1156. - every CAM_PTZ_PROBE_INTERVAL_S the camera is actively asked (protocolPTZ::probe; ONVIF: GetStatus).
  1157. */
  1158. void deviceNodeCamera::ptzCheck(uint8_t tState)
  1159. {
  1160. if (tState != CAM_WS_READY || m_pProtocol == NULL || m_sCamData.protocol == 0)
  1161. {
  1162. return;
  1163. }
  1164. if (! m_pProtocol->validate())
  1165. {
  1166. ptzLost("PTZ protocol reports a failure");
  1167. return;
  1168. }
  1169. time_t tNow = time(NULL);
  1170. if (tNow - m_tPtzLastProbe >= CAM_PTZ_PROBE_INTERVAL_S)
  1171. {
  1172. m_tPtzLastProbe = tNow;
  1173. if (! m_pProtocol->probe())
  1174. {
  1175. ptzLost("PTZ liveness check failed (camera not reachable)");
  1176. }
  1177. };
  1178. }
  1179. uint8_t deviceNodeCamera::getStreamStatus()
  1180. {
  1181. return 1;
  1182. }
  1183. void deviceNodeCamera::m_fThreadProc(void)
  1184. {
  1185. DBC_PUSHED_CMD * PUSHED = NULL;
  1186. m_bThreadStatus = TH_WORKING;
  1187. bool bNewSecondLoop = false;
  1188. uint32_t cTimeSeconds = 0;
  1189. uint32_t oTimeSeconds = 0;
  1190. pthread_setname_np( pthread_self(), "NodeCamera" );
  1191. while (m_bThreadStatus < TH_ENDED)
  1192. {
  1193. cTimeSeconds = (uint32_t) time(NULL);
  1194. if ((bNewSecondLoop = (cTimeSeconds != oTimeSeconds))) oTimeSeconds = cTimeSeconds;
  1195. uint8_t tState = getWM();
  1196. ptzCheck(tState);
  1197. tState = getWM();
  1198. //char tB[128];
  1199. #ifndef NO_CAMERA_FUSION_ENGINE
  1200. fusion_validate();
  1201. #endif
  1202. switch (tState)
  1203. {
  1204. case CAM_WS_INIT:
  1205. {
  1206. if (! ptzReinitDue())
  1207. {
  1208. break; // PTZ failed: wait for the next re-initialisation attempt
  1209. }
  1210. if (m_pProtocol != NULL)
  1211. {
  1212. switch (m_sCamData.protocol)
  1213. {
  1214. case CAM_CTRL_PROTO_VISCA: delete((protocolPTZ_VISCA *) m_pProtocol); break;
  1215. case CAM_CTRL_PROTO_PELCO: delete((protocolPTZ_PELCO *) m_pProtocol); break;
  1216. case CAM_CTRL_PROTO_ONVIF: delete((protocolPTZ_ONVIF *) m_pProtocol); break;
  1217. case CAM_CTRL_PROTO_BRCP : delete((protocolPTZ_BRCP *) m_pProtocol); break;
  1218. default : delete(m_pProtocol);
  1219. };
  1220. m_pProtocol = NULL;
  1221. m_sCamData.online = false;
  1222. };
  1223. switch (m_sCamData.protocol)
  1224. {
  1225. case CAM_CTRL_PROTO_VISCA:
  1226. {
  1227. #ifdef DEBUG
  1228. LOG("VISCA");
  1229. #endif
  1230. m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA(m_sCamData.protocol_aux);
  1231. if (m_pProtocol != NULL)
  1232. {
  1233. basicTransport * tTransport = NULL;
  1234. hardwareManager * tHM = hardwareManager::getInstance();
  1235. if (tHM)
  1236. {
  1237. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  1238. if (tRES != NULL)
  1239. {
  1240. if (tRES->isValid())
  1241. {
  1242. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  1243. if (m_pProtocol->setTransport(tTransport))
  1244. {
  1245. if (! m_pProtocol->create())
  1246. {
  1247. LOG_ERROR("Protocol <<< Create >>> Failure!");
  1248. };
  1249. }
  1250. else
  1251. {
  1252. LOG_ERROR("Binding Port Failure!");
  1253. };
  1254. };
  1255. #ifdef DEBUG
  1256. }
  1257. else
  1258. {
  1259. LOG("HWM Has No UART PORT!");
  1260. #endif
  1261. };
  1262. #ifdef DEBUG
  1263. }
  1264. else
  1265. {
  1266. LOG_ERROR("Can not get Hardware Manager!");
  1267. #endif
  1268. };
  1269. if (tTransport != NULL)
  1270. {
  1271. LOG("Bind Transport Port!");
  1272. }
  1273. else
  1274. {
  1275. LOG_ERROR("Transport Creation Failure!");
  1276. delete((protocolPTZ_VISCA *) m_pProtocol);
  1277. m_pProtocol = NULL;
  1278. };
  1279. #ifdef DEBUG
  1280. }
  1281. else
  1282. {
  1283. LOG_ERROR("Protocol Creation failure!");
  1284. #endif
  1285. };
  1286. break;
  1287. };
  1288. case CAM_CTRL_PROTO_PELCO:
  1289. {
  1290. #ifdef DEBUG
  1291. LOG("PELCO");
  1292. #endif
  1293. m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO(m_sCamData.protocol_aux);
  1294. if (m_pProtocol != NULL)
  1295. {
  1296. basicTransport * tTransport = NULL;
  1297. hardwareManager * tHM = hardwareManager::getInstance();
  1298. if (tHM)
  1299. {
  1300. hardwareResource * tRES = tHM->requestResource(HARDWARE_PROVIDER_SERIAL, m_sCamData.uart_id);
  1301. if (tRES != NULL)
  1302. {
  1303. if (tRES->isValid())
  1304. {
  1305. tTransport = static_cast<basicTransport *>(static_cast<hardwareResourceSerialProvider *>(tRES));
  1306. if (m_pProtocol->setTransport(tTransport))
  1307. {
  1308. if (! m_pProtocol->create())
  1309. {
  1310. LOG_ERROR("Protocol <<< Create >>> Failure!");
  1311. };
  1312. }
  1313. else
  1314. {
  1315. LOG_ERROR("Binding Port Failure!");
  1316. };
  1317. };
  1318. #ifdef DEBUG
  1319. }
  1320. else
  1321. {
  1322. LOG("HWM Has No UART PORT!");
  1323. #endif
  1324. };
  1325. #ifdef DEBUG
  1326. }
  1327. else
  1328. {
  1329. LOG_ERROR("Can not get Hardware Manager!");
  1330. #endif
  1331. };
  1332. if (tTransport != NULL)
  1333. {
  1334. LOG("Bind Transport Port!");
  1335. }
  1336. else
  1337. {
  1338. LOG_ERROR("Transport Creation Failure!");
  1339. delete((protocolPTZ_PELCO *) m_pProtocol);
  1340. m_pProtocol = NULL;
  1341. };
  1342. #ifdef DEBUG
  1343. }
  1344. else
  1345. {
  1346. LOG_ERROR("Protocol Creation failure!");
  1347. #endif
  1348. };
  1349. break;
  1350. };
  1351. case CAM_CTRL_PROTO_ONVIF:
  1352. {
  1353. #ifdef DEBUG_EXTRA
  1354. LOG("ONVIF");
  1355. #endif
  1356. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  1357. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL)
  1358. {
  1359. char tURI[512];
  1360. if (m_sCamData.port)
  1361. {
  1362. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  1363. }
  1364. else
  1365. {
  1366. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  1367. };
  1368. LOG("PTZ URI CREATE");
  1369. LOG( tURI );
  1370. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1371. }
  1372. else
  1373. {
  1374. LOG("PTZ USE");
  1375. LOG( m_sCamData.onvif_ctrl );
  1376. m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1377. };
  1378. #ifdef DEBUG_EXTRA
  1379. LOG("ONVIF-END");
  1380. #endif
  1381. if (m_pProtocol != NULL)
  1382. {
  1383. if (! m_pProtocol->create())
  1384. {
  1385. LOG_ERROR("Error Creating Proto!");
  1386. delete((protocolPTZ_ONVIF *) m_pProtocol);
  1387. m_pProtocol = NULL;
  1388. };
  1389. #ifdef DEBUG_EXTRA
  1390. LOG("PROTO CREATE DONE");
  1391. #endif
  1392. };
  1393. break;
  1394. };
  1395. case CAM_CTRL_PROTO_BRCP:{
  1396. #ifdef DEBUG
  1397. LOG("BRCP");
  1398. #endif
  1399. // m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.port, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
  1400. if (strstr(m_sCamData.onvif_ctrl, "http") == NULL){
  1401. char tURI[256];
  1402. if (m_sCamData.port) {
  1403. sprintf(tURI, "http://%s:%d%s", m_sCamData.ip, m_sCamData.port, m_sCamData.onvif_ctrl);
  1404. } else {
  1405. sprintf(tURI, "http://%s%s", m_sCamData.ip, m_sCamData.onvif_ctrl);
  1406. };
  1407. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(tURI, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1408. } else {
  1409. m_pProtocol = (protocolPTZ *) new protocolPTZ_BRCP(m_sCamData.onvif_ctrl, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode);
  1410. };
  1411. #ifdef DEBUG
  1412. LOG("BRCP-END");
  1413. #endif
  1414. if (m_pProtocol != NULL) {
  1415. if (! m_pProtocol->create()) {
  1416. LOG_ERROR("Error Creating Proto!");
  1417. delete((protocolPTZ_BRCP *) m_pProtocol);
  1418. m_pProtocol = NULL;
  1419. };
  1420. #ifdef DEBUG
  1421. LOG("PROTO CREATE DONE");
  1422. #endif
  1423. };
  1424. break;
  1425. };
  1426. default:
  1427. {
  1428. #ifdef DEBUG
  1429. LOG("Camera Has no defined control protocol");
  1430. #endif
  1431. };
  1432. };
  1433. if (m_pProtocol != NULL)
  1434. {
  1435. // Load Presets only if we have protocol
  1436. load_presets();
  1437. mojoKernel * tKRNL = mojoKernel::getInstance();
  1438. m_bNoMoveDoneReport = false;
  1439. if (tKRNL)
  1440. {
  1441. m_bSkeepPositioningWait = ((tKRNL->getMediaMode() & EVE_OUTPUT_VIDEO) == EVE_OUTPUT_VIDEO);
  1442. #ifdef DEBUG_EXTRA
  1443. char ttTT[128];
  1444. sprintf(ttTT, "Kernel Media Mode:%d", tKRNL->getMediaMode());
  1445. LOG(ttTT);
  1446. if (m_bSkeepPositioningWait)
  1447. {
  1448. LOG("Camera No Wait On Pos!");
  1449. }
  1450. else
  1451. {
  1452. LOG("Camera Will Wait On Pos!");
  1453. };
  1454. #endif
  1455. }
  1456. else
  1457. {
  1458. LOG_ERROR("No Kernel Instance!");
  1459. };
  1460. m_sCamData.online = true;
  1461. setWM(CAM_WS_POWER_INIT);
  1462. };
  1463. m_pDBC->updateCamOnlineStatus(m_sCamData.id, m_sCamData.online);
  1464. if (m_sCamData.protocol == 0)
  1465. {
  1466. ptzHealthSet(PTZ_HEALTH_NONE);
  1467. }
  1468. else if (m_pProtocol != NULL)
  1469. {
  1470. m_tPtzLastProbe = time(NULL);
  1471. ptzHealthSet(PTZ_HEALTH_OK);
  1472. }
  1473. else
  1474. {
  1475. ptzHealthSet(PTZ_HEALTH_FAILED, "PTZ protocol initialisation failed");
  1476. };
  1477. break;
  1478. };
  1479. case CAM_WS_POWER_INIT:
  1480. {
  1481. #ifdef DEBUG
  1482. LOG("Init Camera - PowerMode");
  1483. #endif
  1484. // setBusy( true );
  1485. if (m_pProtocol->initCamera())
  1486. {
  1487. setWM(CAM_WS_WHITE_BALLANCE);
  1488. }
  1489. // setBusy( false );
  1490. break;
  1491. };
  1492. case CAM_WS_WHITE_BALLANCE:
  1493. {
  1494. #ifdef DEBUG
  1495. LOG("Set WB");
  1496. #endif
  1497. // setBusy( true );
  1498. if (m_pProtocol->setWhiteBalanceMode(WB_AUTO))
  1499. {
  1500. setWM(CAM_WS_BACKLIGHT);
  1501. }
  1502. // setBusy( false );
  1503. break;
  1504. };
  1505. case CAM_WS_BACKLIGHT:
  1506. {
  1507. #ifdef DEBUG
  1508. LOG("Set BLC");
  1509. #endif
  1510. // setBusy( true );
  1511. if (m_pProtocol->setBackLightMode(true))
  1512. {
  1513. setWM(CAM_WS_AUTO_FOCUS);
  1514. }
  1515. // setBusy( false );
  1516. break;
  1517. };
  1518. case CAM_WS_AUTO_FOCUS:
  1519. {
  1520. #ifdef DEBUG
  1521. LOG("Set AF");
  1522. #endif
  1523. // setBusy( true );
  1524. if (m_pProtocol->setAutoFocus(true))
  1525. {
  1526. setWM(CAM_WS_INIT_GO_HOME);
  1527. }
  1528. // setBusy( false );
  1529. break;
  1530. };
  1531. case CAM_WS_INIT_GO_HOME:
  1532. {
  1533. m_nHomingCounter = 0;
  1534. /* Skip For Restartin bug
  1535. if( !m_bNoAbsPositionning ) {
  1536. #ifdef DEBUG
  1537. LOG("INIT GO -1 0 -1");
  1538. #endif
  1539. if (m_pProtocol->goAbsolute(-1, 0, -1)) {
  1540. m_fCP_Pan = -1;
  1541. m_fCP_Tilt = 0;
  1542. m_fCP_Zoom = -1;
  1543. setWM( CAM_WS_READY );
  1544. };
  1545. } else {
  1546. #ifdef DEBUG
  1547. LOG("Go Home!");
  1548. #endif
  1549. CSTR TK = getPresetToken( ARGUS_PRESET_TYPE_HOME );
  1550. if( TK ) {
  1551. if ( !m_bCameraOnHomePosition ) {
  1552. if( !m_pProtocol->goPreset( TK )){
  1553. LOG_ERROR("Cannot Issue goPreset Command!");
  1554. };
  1555. m_bCameraOnHomePosition = true;
  1556. };
  1557. };
  1558. setWM( CAM_WS_READY );
  1559. };*/
  1560. LOG("INit GoHome");
  1561. setWM(CAM_WS_READY);
  1562. break;
  1563. };
  1564. case CAM_WS_AUTOMATED_MOVE:
  1565. {
  1566. m_bCameraOnHomePosition = false;
  1567. m_nRelativeMoveCounter++;
  1568. if ((m_bRelativeMoveMatrix & 0x03) != 0)
  1569. {
  1570. // Pan Move
  1571. if ((m_bRelativeMoveMatrix & 0x01) == 0)
  1572. {
  1573. m_fRM_Pan -= m_fSpeedRise;
  1574. }
  1575. else
  1576. {
  1577. m_fRM_Pan += m_fSpeedRise;
  1578. };
  1579. };
  1580. if ((m_bRelativeMoveMatrix & 0x0C) != 0)
  1581. {
  1582. // TILT Move
  1583. if ((m_bRelativeMoveMatrix & 0x04) == 0)
  1584. {
  1585. m_fRM_Tilt -= m_fSpeedRise;
  1586. }
  1587. else
  1588. {
  1589. m_fRM_Tilt += m_fSpeedRise;
  1590. }
  1591. };
  1592. if ((m_bRelativeMoveMatrix & 0x30) != 0)
  1593. {
  1594. // ZOOM Move
  1595. if ((m_bRelativeMoveMatrix & 0x10) == 0)
  1596. {
  1597. // Wide
  1598. m_fRM_Zoom -= m_fSpeedRise;
  1599. }
  1600. else
  1601. {
  1602. // Tele
  1603. m_fRM_Zoom += m_fSpeedRise;
  1604. };
  1605. };
  1606. if (m_fRM_Pan < -1.0f)
  1607. {
  1608. m_fRM_Pan = -1.0f;
  1609. }
  1610. if (m_fRM_Pan > 1.0f)
  1611. {
  1612. m_fRM_Pan = 1.0f;
  1613. }
  1614. if (m_fRM_Tilt < -1.0f)
  1615. {
  1616. m_fRM_Tilt = -1.0f;
  1617. }
  1618. if (m_fRM_Tilt > 1.0f)
  1619. {
  1620. m_fRM_Tilt = 1.0f;
  1621. }
  1622. if (m_fRM_Zoom < -1.0f)
  1623. {
  1624. m_fRM_Zoom = -1.0f;
  1625. }
  1626. if (m_fRM_Zoom > 1.0f)
  1627. {
  1628. m_fRM_Zoom = 1.0f;
  1629. }
  1630. m_fCP_Zoom += 0.5f * m_fRM_Zoom;
  1631. if (m_fCP_Zoom < -1.0f)
  1632. {
  1633. m_fCP_Zoom = -1.0f;
  1634. }
  1635. if (m_fCP_Zoom > 1.0f)
  1636. {
  1637. m_fCP_Zoom = 1.0f;
  1638. }
  1639. if (! relativeMove(m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom))
  1640. {
  1641. m_nRelativeMoveCounter = 0;
  1642. setWM(CAM_WS_READY);
  1643. break;
  1644. };
  1645. if (m_sCamData.ptz_axel)
  1646. { // Manual
  1647. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1648. {
  1649. m_nRelativeMoveCounter = 0;
  1650. setWM(CAM_WS_READY);
  1651. };
  1652. }
  1653. else
  1654. {
  1655. // Stepping Axel by Zoom
  1656. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1657. if (m_nRelativeMoveCounter > tVal)
  1658. {
  1659. m_nRelativeMoveCounter = 0;
  1660. setWM(CAM_WS_READY);
  1661. };
  1662. };
  1663. break;
  1664. };
  1665. case CAM_WS_STOP_MOVE:
  1666. {
  1667. m_nRelativeMoveCounter++;
  1668. m_fRM_Pan = .0f;
  1669. m_fRM_Pan = .0f;
  1670. m_fRM_Tilt = .0f;
  1671. m_fRM_Tilt = .0f;
  1672. m_fRM_Zoom = .0f;
  1673. m_fRM_Zoom = .0f;
  1674. if (relativeStop())
  1675. {
  1676. m_nHomingCounter = 0;
  1677. m_nRelativeMoveCounter = 0;
  1678. setWM(CAM_WS_READY);
  1679. break;
  1680. };
  1681. if (m_sCamData.ptz_axel)
  1682. {
  1683. if (m_nRelativeMoveCounter > m_sCamData.ptz_axel)
  1684. {
  1685. setWM(CAM_WS_READY);
  1686. }
  1687. }
  1688. else
  1689. {
  1690. uint8_t tVal = (uint8_t) (10.0f * (2.0f - (1.0f + m_fCP_Zoom)));
  1691. if (m_nRelativeMoveCounter > tVal)
  1692. {
  1693. setWM(CAM_WS_READY);
  1694. }
  1695. };
  1696. break;
  1697. };
  1698. case CAM_WS_GO_ABS_ROI:
  1699. case CAM_WS_GO_ABS_POSITION:
  1700. {
  1701. m_bCameraOnHomePosition = false;
  1702. setWM(CAM_WS_BUSY);
  1703. if (m_pCurrentROI != NULL)
  1704. {
  1705. // LOG("ROI Ok");
  1706. m_nHomingCounter = 0;
  1707. if (m_pBEH)
  1708. {
  1709. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_MOVE_TO, NULL, NULL, NULL);
  1710. if (tEVT)
  1711. {
  1712. m_pBEH->broadcast(tEVT);
  1713. }
  1714. };
  1715. if (m_bNoAbsPositionning)
  1716. {
  1717. // LOG("ABS to PRESET");
  1718. uint8_t COL, ROW;
  1719. translateROI2PRESET(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom, COL, ROW);
  1720. // char tB[64];
  1721. // sprintf( tB, "Get ABS Preset Col %d Row %d!", COL, ROW );
  1722. // LOG( tB );
  1723. // sprintf( tB, "Old Preset Col %d Row %d!", m_bCurrentPresetCol, m_bCurrentPresetRow );
  1724. // LOG( tB );
  1725. if ((m_bCurrentPresetCol == COL) && (m_bCurrentPresetRow == ROW))
  1726. {
  1727. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1728. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1729. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1730. #ifdef DEBUG_EXTRA
  1731. LOG("INSTANT BCAST CAM ONPOS");
  1732. #endif
  1733. // Send Capture event
  1734. #ifndef NO_CAMERA_FUSION_ENGINE
  1735. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1736. #else
  1737. DBC_SNAPSHOT_DATA * tData = NULL;
  1738. #endif
  1739. if (tData != NULL)
  1740. {
  1741. if (m_pBEH)
  1742. {
  1743. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1744. if (tEVT)
  1745. {
  1746. m_pBEH->broadcast(tEVT);
  1747. }
  1748. else
  1749. {
  1750. //free(tData);
  1751. delete(tData);
  1752. };
  1753. }
  1754. else
  1755. {
  1756. //free(tData);
  1757. delete(tData);
  1758. };
  1759. };
  1760. setWM(CAM_WS_READY);
  1761. }
  1762. else
  1763. {
  1764. CSTR token = getPresetToken(COL, ROW);
  1765. if (token)
  1766. {
  1767. // update position Info
  1768. m_bCurrentPresetCol = COL;
  1769. m_bCurrentPresetRow = ROW;
  1770. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1771. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1772. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1773. if (! m_pProtocol->goPreset(token))
  1774. {
  1775. ptzCommandFailed("goPreset");
  1776. }
  1777. else
  1778. {
  1779. // Waiting Movement finish
  1780. if (m_bSkeepPositioningWait && 0)
  1781. {
  1782. #ifdef DEBUG_EXTRA
  1783. LOG("INSTANT BCAST CAM ONPOS");
  1784. #endif
  1785. // Send Capture event
  1786. #ifndef NO_CAMERA_FUSION_ENGINE
  1787. DBC_SNAPSHOT_DATA * tData = fusion_translate_ROI(m_pCurrentROI);
  1788. #else
  1789. DBC_SNAPSHOT_DATA * tData = NULL;
  1790. #endif
  1791. if (tData != NULL)
  1792. {
  1793. if (m_pBEH)
  1794. {
  1795. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1796. if (tEVT)
  1797. {
  1798. m_pBEH->broadcast(tEVT);
  1799. }
  1800. else
  1801. {
  1802. //free(tData);
  1803. delete(tData);
  1804. };
  1805. }
  1806. else
  1807. {
  1808. //free(tData);
  1809. delete(tData);
  1810. };
  1811. };
  1812. setWM(CAM_WS_READY);
  1813. }
  1814. else
  1815. {
  1816. // utilizeROI( m_pCurrentROI );
  1817. setWM(CAM_WS_WAIT_ONPOS);
  1818. };
  1819. };
  1820. }
  1821. else
  1822. {
  1823. #ifdef DEBUG_EXTRA
  1824. LOG("Not Found!");
  1825. #endif
  1826. utilizeROI(m_pCurrentROI);
  1827. setWM(CAM_WS_READY);
  1828. };
  1829. };
  1830. }
  1831. else
  1832. {
  1833. // update position Info
  1834. m_fCP_Pan = m_pCurrentROI->cam_orientation.pan;
  1835. m_fCP_Tilt = m_pCurrentROI->cam_orientation.tilt;
  1836. m_fCP_Zoom = m_pCurrentROI->cam_orientation.zoom;
  1837. // Do Movement
  1838. if (! m_pProtocol->goAbsolute(m_pCurrentROI->cam_orientation.pan, m_pCurrentROI->cam_orientation.tilt, m_pCurrentROI->cam_orientation.zoom * m_fZoomCorrection))
  1839. {
  1840. ptzCommandFailed("goAbsolute");
  1841. }
  1842. else
  1843. {
  1844. // EVT_CAMERA_ON_POSITION is sent from CAM_WS_WAIT_ONPOS once the move is done
  1845. // (before, with video output it was sent right after the command).
  1846. setWM(CAM_WS_WAIT_ONPOS);
  1847. };
  1848. };
  1849. }
  1850. else
  1851. {
  1852. setWM(CAM_WS_READY);
  1853. }
  1854. break;
  1855. };
  1856. case CAM_WS_WAIT_ONPOS:
  1857. {
  1858. // LOG("WaitOnPos...");
  1859. DBC_SNAPSHOT_DATA * tData = NULL;
  1860. if (m_pCurrentROI != NULL)
  1861. {
  1862. // Send Capture event
  1863. #ifndef NO_CAMERA_FUSION_ENGINE
  1864. tData = fusion_translate_ROI(m_pCurrentROI);
  1865. #else
  1866. tData = NULL;
  1867. #endif
  1868. };
  1869. // To Accept any new ROI's ??
  1870. // setWM( CAM_WS_READY );
  1871. #ifdef DEBUG_EXTRA
  1872. LOG("Start Waiting Cam On Position!");
  1873. #endif
  1874. // Target-driven ABS / preset move: EVT_CAMERA_ON_POSITION only after the move is done.
  1875. // Protocols that cannot report the end of a move get a fixed wait.
  1876. if (! m_bNoMoveDoneReport)
  1877. {
  1878. if (! m_pProtocol->waitMoveIsDone())
  1879. {
  1880. LOG("Protocol cannot report the end of a move -> fixed wait");
  1881. m_bNoMoveDoneReport = true;
  1882. }
  1883. };
  1884. if (m_bNoMoveDoneReport)
  1885. {
  1886. SLEEP(CAM_MOVE_FIXED_WAIT_MS);
  1887. }
  1888. #ifdef DEBUG_EXTRA
  1889. LOG("Done Waiting Cam On Position!");
  1890. #endif
  1891. if (tData != NULL)
  1892. {
  1893. if (m_pBEH)
  1894. {
  1895. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  1896. if (tEVT)
  1897. {
  1898. #ifdef DEBUG_EXTRA
  1899. LOG("BCAST CAM ONPOS");
  1900. #endif
  1901. m_pBEH->broadcast(tEVT);
  1902. }
  1903. else
  1904. {
  1905. //free(tData);
  1906. delete(tData);
  1907. };
  1908. }
  1909. else
  1910. {
  1911. //free(tData);
  1912. delete(tData);
  1913. };
  1914. tData = NULL;
  1915. };
  1916. setWM(CAM_WS_READY);
  1917. break;
  1918. };
  1919. case CAM_WS_GO_HOMING_PRESET:
  1920. {
  1921. if (! m_bCameraOnHomePosition)
  1922. {
  1923. // For new Camera Presets
  1924. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  1925. if (TK)
  1926. {
  1927. #ifdef DEBUG_EXTRA
  1928. LOG("Go Home!");
  1929. LOG(TK);
  1930. #endif
  1931. if (! m_pProtocol->goPreset(TK))
  1932. {
  1933. LOG_ERROR("Cannot Issue goPreset Command!");
  1934. };
  1935. }
  1936. else
  1937. {
  1938. // Old Method
  1939. if (m_sCamData.home_token[0] != (char) 0)
  1940. {
  1941. #ifdef DEBUG_EXTRA
  1942. LOG("Go Home!");
  1943. LOG(m_sCamData.home_token);
  1944. #endif
  1945. if (! m_pProtocol->goPreset(m_sCamData.home_token))
  1946. {
  1947. LOG_ERROR("Cannot Issue goPreset Command!");
  1948. };
  1949. };
  1950. };
  1951. m_bCameraOnHomePosition = true;
  1952. m_bCurrentPresetCol = 0;
  1953. m_bCurrentPresetRow = 0;
  1954. };
  1955. setWM(CAM_WS_READY);
  1956. break;
  1957. };
  1958. case CAM_WS_GO_PRESET:
  1959. {
  1960. LOG("Go Preset!");
  1961. // if( m_sCamData.home_token[0] != (char)0 ) {
  1962. // LOG("Go Home!");
  1963. // LOG( m_sCamData.home_token );
  1964. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1965. // LOG_ERROR("Cannot Issue goPreset Command!");
  1966. // };
  1967. // };
  1968. setWM(CAM_WS_READY);
  1969. break;
  1970. };
  1971. case CAM_WS_SET_PRESET:
  1972. {
  1973. LOG("Set Preset!");
  1974. // if( m_sCamData.home_token[0] != (char)0 ) {
  1975. // LOG("Go Home!");
  1976. // LOG( m_sCamData.home_token );
  1977. // if( !m_pProtocol->goPreset( m_sCamData.home_token )){
  1978. // LOG_ERROR("Cannot Issue goPreset Command!");
  1979. // };
  1980. // };
  1981. setWM(CAM_WS_READY);
  1982. break;
  1983. };
  1984. case CAM_WS_BUSY:
  1985. {
  1986. // Handle Operation TO
  1987. setWM(CAM_WS_READY);
  1988. break;
  1989. };
  1990. case CAM_WS_READY:
  1991. {
  1992. #ifndef NO_CAMERA_FUSION_ENGINE
  1993. m_pCurrentROI = fusion_fetchROI();
  1994. #else
  1995. #endif
  1996. if (m_pCurrentROI != NULL)
  1997. {
  1998. #ifdef DEBUG_EXTRA
  1999. LOG("HAVE ROI to see!");
  2000. #endif
  2001. setWM(CAM_WS_GO_ABS_POSITION);
  2002. }
  2003. else
  2004. {
  2005. // Idle Work --->
  2006. if (m_sCamData.eco_ir)
  2007. {
  2008. m_mIRProtector.lock();
  2009. if (m_bIRIsOn)
  2010. {
  2011. if (m_bIRTO)
  2012. {
  2013. if (bNewSecondLoop)
  2014. {
  2015. m_bIRTO--;
  2016. }
  2017. }
  2018. else
  2019. {
  2020. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_OFF);
  2021. if (TK)
  2022. {
  2023. if (m_pProtocol->goPreset(TK))
  2024. {
  2025. m_bIRIsOn = false;
  2026. }
  2027. }
  2028. };
  2029. };
  2030. m_mIRProtector.unlock();
  2031. };
  2032. if (m_sCamData.homing_enable)
  2033. {
  2034. if (bNewSecondLoop)
  2035. {
  2036. if (m_nHomingCounter < m_sCamData.homing_to)
  2037. {
  2038. m_nHomingCounter++;
  2039. }
  2040. else
  2041. {
  2042. // LOG("Go Home Position!");
  2043. m_nHomingCounter = 0;
  2044. setWM(CAM_WS_GO_HOMING_PRESET);
  2045. break;
  2046. };
  2047. };
  2048. };
  2049. CAM_TASK * tTASK = fetchCamTask();
  2050. if (tTASK != NULL)
  2051. {
  2052. if (tTASK->movemet_needed)
  2053. {
  2054. CAM_PTZ_CMD * tCMD = tTASK->CMD;
  2055. if (tCMD)
  2056. {
  2057. switch (tCMD->CMD)
  2058. {
  2059. case PTZ_STOP:
  2060. {
  2061. m_nHomingCounter = 0;
  2062. setWM(CAM_WS_STOP_MOVE);
  2063. break;
  2064. };
  2065. case PTZ_MOVE:
  2066. {
  2067. if (tState != CAM_WS_AUTOMATED_MOVE)
  2068. {
  2069. m_nRelativeMoveCounter = 0;
  2070. }
  2071. m_bRelativeMoveMatrix = 0;
  2072. m_fRM_Pan = tCMD->PAN;
  2073. m_fRM_Tilt = tCMD->TILT;
  2074. m_fRM_Zoom = tCMD->ZOOM;
  2075. m_nHomingCounter = 0;
  2076. setWM(CAM_WS_AUTOMATED_MOVE);
  2077. break;
  2078. };
  2079. case PTZ_ABSOLUTE:
  2080. {
  2081. m_pCurrentROI = createCAM_ROI();
  2082. if (m_pCurrentROI != NULL)
  2083. {
  2084. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  2085. if (tTarget != NULL)
  2086. {
  2087. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  2088. tTarget->evt_db_ID = tTASK->source_evt_id;
  2089. m_pCurrentROI->targets.push_back(tTarget);
  2090. m_pCurrentROI->cam_orientation.pan = tCMD->PAN;
  2091. m_pCurrentROI->cam_orientation.tilt = tCMD->TILT;
  2092. m_pCurrentROI->cam_orientation.zoom = tCMD->ZOOM;
  2093. m_nHomingCounter = 0;
  2094. setWM(CAM_WS_GO_ABS_POSITION);
  2095. }
  2096. else
  2097. {
  2098. utilizeROI(m_pCurrentROI);
  2099. };
  2100. };
  2101. break;
  2102. };
  2103. case PTZ_RELOAD_CAMERA:
  2104. {
  2105. LOG("Exit Command Rcpt");
  2106. m_bThreadStatus = TH_ENDED;
  2107. };
  2108. };
  2109. free(tCMD);
  2110. tTASK->CMD = NULL;
  2111. };
  2112. }
  2113. else
  2114. {
  2115. LOG("No Movement -> INSTCAP");
  2116. // No Movement -> Just Capture
  2117. if (m_pBEH)
  2118. {
  2119. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, NULL);
  2120. if (tEVT)
  2121. {
  2122. tEVT->m_db_id = tTASK->source_evt_id;
  2123. m_pBEH->broadcast(tEVT);
  2124. };
  2125. };
  2126. };
  2127. free(tTASK);
  2128. }
  2129. else
  2130. {
  2131. // Lowest Priority to Web Client Commands
  2132. #ifdef DEBUG_EXTRA__
  2133. LOG("Check Web CMD!");
  2134. #endif
  2135. PUSHED = m_pDBC->getNodePushedCMD(m_sNodeData.node_id);
  2136. if (PUSHED != NULL)
  2137. {
  2138. #ifdef DEBUG_EXTRA__
  2139. LOG("HAVE Web CMD!");
  2140. #endif
  2141. m_pDBC->updateNodePushedCMD(PUSHED->id, DBC_CMD_READY_TO_CLEAN);
  2142. if ((PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK) == ARGUS_CAM_PCMD_CMD_MASK)
  2143. {
  2144. switch (PUSHED->CMD)
  2145. {
  2146. case 0x80:
  2147. {
  2148. // Call Home Preset
  2149. LOG("CALL HOME PRESET!");
  2150. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_HOME);
  2151. if (TK)
  2152. {
  2153. LOG(TK);
  2154. if (m_pProtocol->goPreset(TK))
  2155. {
  2156. m_bCameraOnHomePosition = true;
  2157. m_nHomingCounter = 0;
  2158. };
  2159. };
  2160. break;
  2161. };
  2162. case 0x81:
  2163. {
  2164. // Call IR On Preset
  2165. LOG("CALL IR ON PRESET!");
  2166. m_mIRProtector.lock();
  2167. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_ON);
  2168. if (TK)
  2169. {
  2170. LOG(TK);
  2171. if (m_pProtocol->goPreset(TK))
  2172. {
  2173. m_bIRIsOn = true;
  2174. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2175. };
  2176. }
  2177. else
  2178. {
  2179. LOG("PRESET NOT FOUND!");
  2180. }
  2181. m_mIRProtector.unlock();
  2182. break;
  2183. };
  2184. case 0x82:
  2185. {
  2186. // Call IR Off Preset
  2187. LOG("CALL IR OFF PRESET!");
  2188. m_mIRProtector.lock();
  2189. CSTR TK = (m_sCamData.eco_ir) ? getPresetToken(ARGUS_PRESET_TYPE_IR_OFF) : getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2190. if (TK)
  2191. {
  2192. LOG(TK);
  2193. if (m_pProtocol->goPreset(TK))
  2194. {
  2195. m_bIRIsOn = false;
  2196. m_bIRTO = 0;
  2197. };
  2198. }
  2199. else
  2200. {
  2201. LOG("PRESET NOT FOUND!");
  2202. }
  2203. m_mIRProtector.unlock();
  2204. break;
  2205. };
  2206. case 0x83:
  2207. {
  2208. // Call IR Auto Preset
  2209. LOG("CALL IR AUTO PRESET!");
  2210. m_mIRProtector.lock();
  2211. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2212. if (TK)
  2213. {
  2214. LOG(TK);
  2215. if (m_pProtocol->goPreset(TK))
  2216. {
  2217. m_bIRIsOn = true;
  2218. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2219. };
  2220. }
  2221. else
  2222. {
  2223. LOG("PRESET NOT FOUND!");
  2224. }
  2225. m_mIRProtector.unlock();
  2226. break;
  2227. };
  2228. case 0x84:
  2229. {
  2230. // Call Wisher Preset
  2231. LOG("CALL WIPER PRESET!");
  2232. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_WISHER);
  2233. if (TK)
  2234. {
  2235. LOG(TK);
  2236. m_pProtocol->goPreset(TK);
  2237. };
  2238. break;
  2239. };
  2240. };
  2241. }
  2242. else if (tState == CAM_WS_READY || tState == CAM_WS_AUTOMATED_MOVE)
  2243. { // No Way to get here
  2244. // Direct Movment Mode
  2245. if (PUSHED->CMD == ARGUS_CAM_PCMD_STOP)
  2246. {
  2247. m_nHomingCounter = 0;
  2248. setWM(CAM_WS_STOP_MOVE);
  2249. }
  2250. else
  2251. {
  2252. //char tB[64];
  2253. if (tState != CAM_WS_AUTOMATED_MOVE)
  2254. {
  2255. m_nRelativeMoveCounter = 0;
  2256. }
  2257. m_bRelativeMoveMatrix = (PUSHED->CMD) >> 1;
  2258. m_nHomingCounter = 0;
  2259. setWM(CAM_WS_AUTOMATED_MOVE);
  2260. };
  2261. };
  2262. free(PUSHED);
  2263. PUSHED = NULL;
  2264. };
  2265. };
  2266. };
  2267. break;
  2268. };
  2269. case CAM_WS_END:
  2270. {
  2271. LOG("Exit Command Rcpt");
  2272. m_bThreadStatus = TH_ENDED;
  2273. break;
  2274. };
  2275. };
  2276. SLEEP(DEFAULT_THREAD_SLEEP_TIME);
  2277. };
  2278. #ifdef DEBUG
  2279. LOG("CTRL Loop End!");
  2280. #endif
  2281. }
  2282. bool deviceNodeCamera::setNoPositionWait(bool FL)
  2283. {
  2284. m_bSkeepPositioningWait = FL;
  2285. return true;
  2286. }
  2287. bool deviceNodeCamera::testFOV(C3D_DECART L)
  2288. {
  2289. // System Coords -> trans to local and go to funct
  2290. systemAnchor * tSystem = systemAnchor::getInstance();
  2291. if (tSystem == NULL)
  2292. {
  2293. return false;
  2294. }
  2295. C3D_SPH_DEGREES SL;
  2296. #ifdef DEBUG_EXTRA
  2297. LOG("Test FOV local Decart coords");
  2298. #endif
  2299. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2300. {
  2301. return false;
  2302. }
  2303. return testFOV(SL);
  2304. }
  2305. bool deviceNodeCamera::testFOV(C3D_WGS84_LOC L)
  2306. {
  2307. // Global Coords
  2308. systemAnchor * tSystem = systemAnchor::getInstance();
  2309. if (tSystem == NULL)
  2310. {
  2311. return false;
  2312. }
  2313. C3D_SPH_DEGREES SL;
  2314. #ifdef DEBUG_EXTRA
  2315. LOG("Test FOV WGS coords");
  2316. #endif
  2317. if (! tSystem->convertToLocal(&m_oPosition, L, SL))
  2318. {
  2319. return false;
  2320. }
  2321. return testFOV(SL);
  2322. }
  2323. bool deviceNodeCamera::testFOV(C3D_SPH_RADIANS L)
  2324. {
  2325. // Local Coords
  2326. C3D_SPH_DEGREES SL;
  2327. #ifdef DEBUG_EXTRA
  2328. LOG("Test FOV local Spherical(rad) coords");
  2329. #endif
  2330. spherical2spherical(L, SL);
  2331. return testFOV(SL);
  2332. }
  2333. bool deviceNodeCamera::testFOV(C3D_SPH_DEGREES SL)
  2334. {
  2335. #ifdef DEBUG_EXTRA
  2336. char tB[128];
  2337. #endif
  2338. #ifdef DEBUG_EXTRA
  2339. LOG("Test FOV local Spherical(deg) coords");
  2340. #endif
  2341. switch (m_sCamData.triggering_mode)
  2342. {
  2343. case CAM_TRIGGER_STRICT:
  2344. {
  2345. if (SL.r > m_fMaxRange || SL.r < m_fMinRange)
  2346. {
  2347. #ifdef DEBUG_EXTRA
  2348. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2349. LOG(tB);
  2350. #endif
  2351. return false;
  2352. };
  2353. break;
  2354. };
  2355. case CAM_TRIGGER_ALL_NEAR:
  2356. {
  2357. if (SL.r > m_fMaxRange)
  2358. {
  2359. #ifdef DEBUG_EXTRA
  2360. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2361. LOG(tB);
  2362. #endif
  2363. return false;
  2364. };
  2365. break;
  2366. };
  2367. case CAM_TRIGGER_ALL_FAR:
  2368. {
  2369. if (SL.r < m_fMinRange)
  2370. {
  2371. #ifdef DEBUG_EXTRA
  2372. sprintf(tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange);
  2373. LOG(tB);
  2374. #endif
  2375. return false;
  2376. };
  2377. break;
  2378. };
  2379. case CAM_TRIGGER_ALL: return true;
  2380. };
  2381. // float HS = AC_imager_width[m_sCamData.imager_type];
  2382. // float VS = AC_imager_height[m_sCamData.imager_type];
  2383. // float HS2 = HS * HS;
  2384. // float VS2 = VS * VS;
  2385. // float IR = HS / VS;
  2386. // float IR2 = IR * IR;
  2387. if (m_sCamData.pan_angles == 0)
  2388. {
  2389. // Fixed Camera
  2390. float tA = fabsf(SL.fi);
  2391. float tZ = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2392. if (tA > tZ)
  2393. {
  2394. return false;
  2395. }
  2396. }
  2397. else
  2398. {
  2399. if (m_sCamData.pan_angles < 360)
  2400. { // If endless PAN -> PASSED
  2401. // Partial Pan
  2402. switch (m_sCamData.pan_model)
  2403. {
  2404. case 1:
  2405. {
  2406. // Regular Pan
  2407. float tFOV = 0.5f * (m_fMinHFov + (SL.r - m_fMinRange) * m_fR2FL);
  2408. float tRad = deg2rad(SL.fi);
  2409. #ifdef DEBUG_EXTRA
  2410. sprintf(tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad);
  2411. LOG(tB);
  2412. #endif
  2413. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.pan_angles) + tFOV)))
  2414. {
  2415. return false;
  2416. }
  2417. break;
  2418. };
  2419. case 2:
  2420. {
  2421. break;
  2422. };
  2423. case 3:
  2424. {
  2425. break;
  2426. };
  2427. };
  2428. };
  2429. };
  2430. if (m_sCamData.tilt_angles == 0)
  2431. {
  2432. // Fixed Camera
  2433. if ((SL.tetta < (m_fMaxVFov / -2.0f)) || (SL.tetta > (m_fMaxVFov / 2.0f)))
  2434. {
  2435. return false;
  2436. }
  2437. }
  2438. else
  2439. {
  2440. if (m_sCamData.tilt_angles < 90)
  2441. { // if Cam CAN DO 90 -> Pass
  2442. // Partial Tilt
  2443. switch (m_sCamData.tilt_model)
  2444. {
  2445. case 1:
  2446. {
  2447. // Regular Tilt
  2448. float tFOV = 0.5f * (m_fMinVFov + (m_fMaxVFov - m_fMinVFov) * (SL.r / m_fMaxRange));
  2449. float tRad = deg2rad(SL.tetta);
  2450. if ((tRad < (-1.0 * tFOV)) || (tRad > (deg2rad(m_sCamData.tilt_angles) + tFOV)))
  2451. {
  2452. return false;
  2453. }
  2454. break;
  2455. };
  2456. case 2:
  2457. {
  2458. break;
  2459. };
  2460. };
  2461. };
  2462. };
  2463. return true;
  2464. }
  2465. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_WGS84_LOC L)
  2466. {
  2467. systemAnchor * tSystem = systemAnchor::getInstance();
  2468. if (tSystem == NULL)
  2469. {
  2470. return false;
  2471. }
  2472. C3D_SPH_DEGREES SL;
  2473. #ifdef DEBUG_EXTRA
  2474. LOG("Look at WGS coords!");
  2475. #endif
  2476. tSystem->convertToLocal(&m_oPosition, L, SL);
  2477. return lookAt(TargetRefID, SL);
  2478. }
  2479. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_DECART L)
  2480. {
  2481. systemAnchor * tSystem = systemAnchor::getInstance();
  2482. if (tSystem == NULL)
  2483. {
  2484. LOG_ERROR("Cant Get Anchor!");
  2485. return false;
  2486. }
  2487. C3D_SPH_DEGREES SL;
  2488. #ifdef DEBUG_EXTRA
  2489. LOG("Look at System Decart coords!");
  2490. #endif
  2491. tSystem->convertToLocal(&m_oPosition, L, SL);
  2492. return lookAt(TargetRefID, SL);
  2493. }
  2494. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_RADIANS L)
  2495. {
  2496. C3D_SPH_DEGREES SL;
  2497. #ifdef DEBUG_EXTRA
  2498. LOG("Look at spherical(rad) 2 spherical(deg) coords!");
  2499. #endif
  2500. spherical2spherical(L, SL);
  2501. return lookAt(TargetRefID, SL);
  2502. }
  2503. bool deviceNodeCamera::lookAt(uint32_t TargetRefID, C3D_SPH_DEGREES L)
  2504. {
  2505. if (m_bCameraIsStatic)
  2506. {
  2507. //DBC_SNAPSHOT_DATA * tData = (DBC_SNAPSHOT_DATA *) malloc(sizeof(DBC_SNAPSHOT_DATA));
  2508. DBC_SNAPSHOT_DATA * tData = new DBC_SNAPSHOT_DATA();
  2509. if (tData)
  2510. {
  2511. //memset(tData, 0, sizeof(DBC_SNAPSHOT_DATA));
  2512. tData->stream_id = m_sNodeData.aux_parameter;
  2513. tData->assoc_event_ids.push_back(TargetRefID);
  2514. if (m_pBEH)
  2515. {
  2516. EVENT_CONTAINER * tEVT = createBasicEvent(m_sNodeData.node_id, EVT_CLASS_CAMERA_CTRL, EVT_CAMERA_ON_POSITION, NULL, NULL, tData);
  2517. if (tEVT)
  2518. {
  2519. #ifdef DEBUG_EXTRA
  2520. LOG("INSTANT BCAST CAM ONPOS");
  2521. #endif
  2522. m_pBEH->broadcast(tEVT);
  2523. }
  2524. else
  2525. {
  2526. //free(tData);
  2527. delete(tData);
  2528. };
  2529. }
  2530. else
  2531. {
  2532. //free(tData);
  2533. delete(tData);
  2534. };
  2535. };
  2536. return true;
  2537. };
  2538. // char tB[128];
  2539. // sprintf(tB, "Target On %.3f %.3f %.3f", L.r, L.fi, L.tetta );
  2540. // LOG( tB );
  2541. // sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
  2542. // LOG( tB );
  2543. #ifdef DEBUG_EXTRA
  2544. LOG("Look at local spherical deg. coords!(final)");
  2545. #endif
  2546. // if( getWM() == CAM_WS_READY ){
  2547. // C3D_ORIENT_ONVIF LL;
  2548. // spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
  2549. // return absoluteMove( TargetRefID, LL );
  2550. // };
  2551. // Camera is Busy
  2552. if (m_bShineOnTarget)
  2553. {
  2554. m_mIRProtector.lock();
  2555. if (! m_bIRIsOn)
  2556. {
  2557. CSTR TK = getPresetToken(ARGUS_PRESET_TYPE_IR_AUTO);
  2558. if (TK)
  2559. {
  2560. if (m_pProtocol->goPreset(TK))
  2561. {
  2562. m_bIRIsOn = true;
  2563. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2564. };
  2565. };
  2566. }
  2567. else
  2568. {
  2569. m_bIRTO = DEFAULT_SHINE_ON_TARGET_TO;
  2570. }
  2571. m_mIRProtector.unlock();
  2572. };
  2573. // targeting by Presets -> instant ROI
  2574. if (m_bNoAbsPositionning)
  2575. {
  2576. CAM_ROI * tROI = createCAM_ROI();
  2577. if (tROI != NULL)
  2578. {
  2579. CAM_TRACK_RECORD * tTarget = (CAM_TRACK_RECORD *) malloc(sizeof(CAM_TRACK_RECORD));
  2580. if (tTarget != NULL)
  2581. {
  2582. memset(tTarget, 0, sizeof(CAM_TRACK_RECORD));
  2583. tTarget->evt_db_ID = TargetRefID;
  2584. tROI->targets.push_back(tTarget);
  2585. tROI->ts_ms = getMilliseconds();
  2586. spherical2onvif(L, tROI->cam_orientation, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles);
  2587. tROI->cam_position.fi = L.fi;
  2588. tROI->cam_position.tetta = L.tetta;
  2589. tROI->cam_position.r = L.r;
  2590. #ifndef NO_CAMERA_FUSION_ENGINE
  2591. m_mROIsProtector.lock();
  2592. m_vROIS.push_back(tROI);
  2593. m_mROIsProtector.unlock();
  2594. #endif
  2595. }
  2596. else
  2597. {
  2598. LOG_ERROR("No MEM 4 TARGTEG DATA");
  2599. utilizeROI(tROI);
  2600. };
  2601. }
  2602. else
  2603. {
  2604. LOG_ERROR("No MEM 4 ROI");
  2605. }
  2606. return true;
  2607. };
  2608. #ifndef NO_CAMERA_FUSION_ENGINE
  2609. return fusion_consumeData(TargetRefID, L);
  2610. #else
  2611. return true;
  2612. #endif
  2613. }
  2614. bool deviceNodeCamera::makeSnap(uint32_t TargetRefID)
  2615. {
  2616. CAM_TASK * tTask = (CAM_TASK *) malloc(sizeof(CAM_TASK));
  2617. if (tTask)
  2618. {
  2619. memset(tTask, 0, sizeof(CAM_TASK));
  2620. tTask->CMD = (CAM_PTZ_CMD *) malloc(sizeof(CAM_PTZ_CMD));
  2621. if (tTask->CMD)
  2622. {
  2623. tTask->CMD->CMD = PTZ_CAPTURE_ONLY;
  2624. tTask->movemet_needed = false;
  2625. tTask->source_evt_id = TargetRefID;
  2626. return pushCamTask(tTask);
  2627. }
  2628. else
  2629. {
  2630. free(tTask);
  2631. };
  2632. };
  2633. return false;
  2634. }
  2635. bool deviceNodeCamera::connectToStream(uint32_t id)
  2636. {
  2637. /*
  2638. if( id ){
  2639. argusKernelModule * tKM = NULL;
  2640. argusKernel * tKRNL = NULL;
  2641. argusModuleFactory * tMF = NULL;
  2642. if( m_pDBC == NULL ) {
  2643. LOG_ERROR("No Database Connector!");
  2644. return false;
  2645. };
  2646. tKRNL = argusKernel::getInstance();
  2647. if( tKRNL ) {
  2648. tMF = tKRNL->getModuleFactory();
  2649. if( tMF ) {
  2650. tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
  2651. } else {
  2652. LOG_ERROR("No ModuleFactory Instance!");
  2653. return false;
  2654. };
  2655. } else {
  2656. LOG_ERROR("No Kernel Instance!");
  2657. return false;
  2658. };
  2659. if( tKM ) {
  2660. // New Module
  2661. DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
  2662. if( tDATA ) {
  2663. m_sMediaSource.mediaStreamId = id;
  2664. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2665. if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
  2666. m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
  2667. } else {
  2668. if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
  2669. m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource );
  2670. };
  2671. if( m_pSource != NULL ) {
  2672. char tMRL[1024];
  2673. #ifdef DEBUG
  2674. LOG("Source OK");
  2675. #endif
  2676. ((videoLIVE555Source*)m_pSource)->setWM( MS_MODE_STREAM_PROXY | MS_MODE_OVERLAYED_LOOPS | MS_MODE_DECODE_FRAMES );
  2677. int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
  2678. int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
  2679. int pix = -1;
  2680. bool in_16_9 = (((tDATA->width*100) / tDATA->height ) > 140 );
  2681. bool out_16_9 = (((tW*100) / tH ) > 140 );
  2682. updateOpticalParameters( tW, tH );
  2683. if( strlen( tDATA->c_type ) ){
  2684. };
  2685. //if( tW > 0 ){
  2686. // //m_pSource->setProportionalByWidth( tW );
  2687. // m_pSource->setSize( tW, tH );
  2688. //};
  2689. if( in_16_9 != out_16_9 ){
  2690. if( in_16_9 ){
  2691. tH = ((( tW * 1000 ) / 16 ) * 9 ) / 1000;
  2692. } else {
  2693. tW = ((( tH * 1000 ) / 3 ) * 4 ) / 1000;
  2694. };
  2695. };
  2696. if (strncmp(tDATA->mrl_proto, "v4l2", 4) == 0) {
  2697. sprintf( tMRL, tDATA->mrl );
  2698. } else {
  2699. DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
  2700. if( tCAM ) {
  2701. sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
  2702. free( tCAM );
  2703. } else {
  2704. LOG_ERROR("Error Getting CAM Data!");
  2705. delete( m_pSource );
  2706. m_pSource = NULL;
  2707. return false;
  2708. };
  2709. };
  2710. LOG( tMRL );
  2711. if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
  2712. m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
  2713. if ( !m_bSourceConnected ) {
  2714. //delete( m_pSource );
  2715. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2716. delete((videoAVLIBSource*)m_pSource);
  2717. } else {
  2718. delete((videoLIVE555Source*)m_pSource);
  2719. };
  2720. m_pSource = NULL;
  2721. } else {
  2722. m_nActiveStreamID = id;
  2723. #ifdef DEBUG
  2724. LOG("Source is Connected to Output.");
  2725. #endif
  2726. };
  2727. } else {
  2728. LOG_ERROR("Can not Open Video Source!");
  2729. //delete( m_pSource );
  2730. if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
  2731. delete((videoAVLIBSource*)m_pSource);
  2732. } else {
  2733. delete((videoLIVE555Source*)m_pSource);
  2734. };
  2735. m_pSource = NULL;
  2736. };
  2737. } else {
  2738. LOG_ERROR("Video Source Stream Failure!");
  2739. };
  2740. free( tDATA );
  2741. };
  2742. }
  2743. #ifdef DEBUG
  2744. else LOG("No Video Module!")
  2745. #endif
  2746. ;
  2747. };
  2748. LOG("Connect Finished!");
  2749. return m_bSourceConnected;
  2750. */
  2751. if ( id ) return true;
  2752. return true;
  2753. }
  2754. bool deviceNodeCamera::disconnectFromStream(void)
  2755. {
  2756. /*if( m_bSourceConnected ) {
  2757. if( m_pSource ){
  2758. delete( m_pSource );
  2759. m_pSource = NULL;
  2760. };
  2761. m_bSourceConnected = false;
  2762. };
  2763. return !m_bSourceConnected;
  2764. */
  2765. return true;
  2766. }
  2767. bool deviceNodeCamera::validateStream(void)
  2768. {
  2769. /*
  2770. if( m_bSourceConnected ) {
  2771. if( m_pSource ) {
  2772. if( m_pSource->isAttached() ){
  2773. if( m_pSource->getStatus() < MS_STOPED ) return true;
  2774. #ifdef DEBUG
  2775. LOG("Source is Finished!");
  2776. #endif
  2777. };
  2778. #ifdef DEBUG
  2779. LOG("Source is Disconnected!");
  2780. #endif
  2781. } else LOG_ERROR("No Source Object! Set Disconnected!");
  2782. disconnectFromStream();
  2783. };
  2784. return false;
  2785. */
  2786. return true;
  2787. }
  2788. bool deviceNodeCamera::validate()
  2789. {
  2790. if (m_pDBC == NULL)
  2791. {
  2792. return false;
  2793. }
  2794. DBC_CAM_DATA * tDATA = m_pDBC->getCamData(m_sCamData.id);
  2795. if (tDATA == NULL)
  2796. {
  2797. return false;
  2798. }
  2799. if (memcmp(tDATA, &m_sCamData, sizeof(DBC_CAM_DATA)) != 0)
  2800. {
  2801. // Settings Changed
  2802. // memcpy(&m_sCamData, tDATA, sizeof(DBC_CAM_DATA) );
  2803. free(tDATA);
  2804. return false;
  2805. };
  2806. free(tDATA);
  2807. if (! validateStream())
  2808. {
  2809. return false;
  2810. }
  2811. return deviceNode::validate();
  2812. }
  2813. bool deviceNodeCamera::load_presets(void)
  2814. {
  2815. bool bHaveIROFF = false;
  2816. bool bHaveIRON = false;
  2817. bool bHaveIRAUTO = false;
  2818. // Request PRESETS FROM CAMERA?! for some PTZ cameras without presets inpossible to
  2819. // operate by presets
  2820. if (m_pProtocol->getCameraPresets())
  2821. {
  2822. LOG("Camera Presets Loadded");
  2823. }
  2824. else
  2825. {
  2826. LOG_ERROR("Error while loadding Camera Presets!");
  2827. }
  2828. if (m_pDBC == NULL)
  2829. {
  2830. return false;
  2831. }
  2832. DBC_PRESETS_INFO * tData = m_pDBC->getCamPresetInfo(m_sCamData.id);
  2833. if (tData)
  2834. {
  2835. //memcpy(&m_sCamPresets, tData, sizeof(DBC_PRESETS_INFO));
  2836. m_sCamPresets.maxCount = tData->maxCount;
  2837. m_sCamPresets.gRows = tData->gRows;
  2838. m_sCamPresets.gCols = tData->gCols;
  2839. m_sCamPresets.presets.clear();
  2840. #ifdef DEBUG
  2841. char tB[128];
  2842. LOG("Loading Presets!");
  2843. sprintf(tB, "Cam Presets Info: CNT: %d Cols: %d Rows: %d ", m_sCamPresets.maxCount, m_sCamPresets.gCols, m_sCamPresets.gRows);
  2844. LOG(tB);
  2845. #endif
  2846. DBC_INT_LIST * tList = m_pDBC->listCamPresets(m_sCamData.id);
  2847. if (tList)
  2848. {
  2849. for (DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++)
  2850. {
  2851. CAM_PRESET * tData = m_pDBC->getCamPreset(*idx);
  2852. if (tData)
  2853. {
  2854. m_sCamPresets.presets.push_back(tData);
  2855. bHaveIRON = (tData->role == ARGUS_PRESET_TYPE_IR_ON) ? true : bHaveIRON;
  2856. bHaveIROFF = (tData->role == ARGUS_PRESET_TYPE_IR_OFF) ? true : bHaveIROFF;
  2857. bHaveIRAUTO = (tData->role == ARGUS_PRESET_TYPE_IR_AUTO) ? true : bHaveIRAUTO;
  2858. };
  2859. };
  2860. delete(tList);
  2861. };
  2862. if (m_sCamData.eco_ir)
  2863. {
  2864. m_bShineOnTarget = (bHaveIROFF && bHaveIRAUTO);
  2865. }
  2866. else
  2867. {
  2868. m_bShineOnTarget = false;
  2869. }
  2870. return true;
  2871. #ifdef DEBUG
  2872. }
  2873. else
  2874. {
  2875. LOG("No Camera Presets!");
  2876. #endif
  2877. };
  2878. return false;
  2879. }
  2880. void deviceNodeCamera::translateROI2PRESET(float P, float T, float Z, uint8_t & col, uint8_t & row)
  2881. {
  2882. //char tB[128];
  2883. if ( T ) Z = Z;
  2884. row = (uint8_t)(Z * ((float)m_sCamPresets.gRows));
  2885. if (P < 0.5)
  2886. {
  2887. P = P + 1.5f;
  2888. }
  2889. else
  2890. {
  2891. P = P - 0.5f;
  2892. };
  2893. col = (uint8_t) (P * ((float) (m_sCamPresets.gCols * (1 << row)) / 2.0f));
  2894. row++;
  2895. }
  2896. CSTR deviceNodeCamera::getPresetToken(uint8_t CCOL, uint8_t CROW)
  2897. {
  2898. if (m_sCamPresets.presets.size() > 0)
  2899. {
  2900. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2901. {
  2902. if ((*idx)->role == ARGUS_PRESET_TYPE_POSITION)
  2903. {
  2904. if (((*idx)->row == CROW) && ((*idx)->col == CCOL))
  2905. {
  2906. return (CSTR) (*idx)->token;
  2907. }
  2908. }
  2909. }
  2910. }
  2911. return NULL;
  2912. }
  2913. CSTR deviceNodeCamera::getPresetToken(uint8_t specialRole)
  2914. {
  2915. if (m_sCamPresets.presets.size() > 0)
  2916. {
  2917. for (V_PRESETS::iterator idx = m_sCamPresets.presets.begin(); idx < m_sCamPresets.presets.end(); idx++)
  2918. {
  2919. if ((*idx)->role == specialRole)
  2920. {
  2921. return (CSTR) (*idx)->token;
  2922. }
  2923. }
  2924. }
  2925. return NULL;
  2926. }
  2927. #undef LOG
  2928. #undef LOG_ERROR
  2929. //#undef DEBUG_EXTRA