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.

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