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.

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