Main USHER daemon coordinating flight-controller triggers and camera backends. More...
#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <errno.h>#include <fcntl.h>#include "version.h"#include <math.h>#include <poll.h>#include <signal.h>#include <spawn.h>#include <stddef.h>#include <stdbool.h>#include <string.h>#include <sys/resource.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/un.h>#include <sys/wait.h>#include <time.h>#include <unistd.h>#include "ai_cam_pipe.h"#include "spotter_cam_pipe.h"#include "lwir_spotter.h"#include "camera_speedtest.h"#include "ear_camera_backend.h"#include "ear_cam_pipe.h"#include "loom_camera_backend.h"#include "camera_backend_registry.h"#include "dipla_camera_backend.h"#include "chdk_camera_backend.h"#include "spotter_camera_backend.h"#include "lwir_cam_pipe.h"#include "serial.h"#include "serial_tx.h"#include "image_exif.h"#include "image_mock_transform.h"#include "image_lens.h"#include "local_pipe.h"#include "usher_protocol.h"#include "camera_control.h"#include <sys/random.h>#include "pose_log.h"#include "capture_arbiter.h"#include "camera_profile.h"#include "socket.h"#include "path_utils.h"
Go to the source code of this file.
Data Structures | |
| struct | option_alias |
| Long-to-short option mapping; borrowed values are passed to standard getopt. More... | |
| struct | capture_job |
| Pool-owned worker request; ownership transfers only after thread creation succeeds. More... | |
| struct | captured_image |
| Per-image handoff from acquisition to publication, EXIF and optional analysis. More... | |
| struct | soda_job |
| Saved-file analysis job; retaining pixels here would multiply decoder memory. More... | |
Enumerations | |
| enum | camera_stream_state { CAMERA_STREAM_CLOSED , CAMERA_STREAM_ACTIVE , CAMERA_STREAM_UNAVAILABLE , CAMERA_STREAM_DRAINED } |
Functions | |
| static int | normalize_long_options (int argc, char *const argv[], char *normalized[], size_t capacity, const struct option_alias aliases[], size_t alias_count) |
| Translate supported long options into the short-option parser's input. | |
| static void * | handle_msg_shoot (void *ptr) |
| Consume one optical ticket, then finish images outside the lane where safe. | |
| static bool | capture_image (const union dc_shot_union *shoot, struct captured_image *image, int camera_id, const struct camera_backend *backend) |
| Acquire pixels or a completed file for a single camera. | |
| static bool | finish_image (const union dc_shot_union *shoot, struct captured_image *image) |
| Complete publication and metadata before releasing survey ownership. | |
| static void | handle_received_message (void) |
| Dispatch one complete UART frame without running slow camera work inline. | |
| static void | start_shoot_worker (const union dc_shot_union *shoot, uint8_t camera_mask, uint32_t request_id) |
| Dispatch admitted image bits while preserving bounded legacy/local policies. | |
| static void | start_lwir_worker (const union dc_shot_union *shoot, uint32_t request_id, uint64_t received_us) |
| Dispatch a single-flight thermal request without waiting for USB recovery. | |
| static void | service_capture_arbiter (uint64_t now_us) |
| Bridge survey decisions to current backend readiness from the serial event loop. | |
| static void | capture_arbiter_failed (const union dc_shot_union *shoot, uint8_t mask) |
| Release per-camera survey admission on a failure before normal completion. | |
| static void | handle_targeted_stop (uint32_t camera_id, uint32_t session_id) |
| Request the stop phase for a matching point session. | |
| static void | handle_targeted_start (uint32_t camera_id, uint32_t session_id) |
| Start a point session for the addressed backend or backends. | |
| static bool | prepare_session_backend (unsigned camera_id) |
| Ensure a point-session backend has a registered owner. | |
| static bool | camera_point_valid (const struct camera_point_result *point) |
| Check whether a backend result is suitable for the point wire format. | |
| static void | send_msg_cam_point (uint32_t camera_id, uint32_t session_id, const struct camera_point_result *point) |
| Cache and attempt to queue a terminal point-session result. | |
| static void | flush_cam_points (void) |
| Submit unsent point-session results to the UART transmit queue. | |
| static void | service_camera_backends (void) |
| Collect stream updates and completed point-session results. | |
| static void | drain_camera_backends (void) |
| Ask active streams and sessions to drain, then service remaining results. | |
| static void | send_msg_cam_point_update (uint32_t camera_id, const struct camera_point_result *point) |
| Keep only the newest stream result per camera across UART backpressure. | |
| static void | flush_cam_point_updates (void) |
| Publish fresh stream mailboxes without changing stopped-session result caches. | |
| static int | run_soda (const char *filename, const union dc_shot_union *shoot, int camera_id) |
| Run one analysis child directly with bounded runtime and termination grace. | |
| static void | defer_soda (const char *filename, const union dc_shot_union *shoot, int camera_id) |
| Queue analysis of a saved original without retaining camera or pixel buffers. | |
| static void | defer_saved_analysis (const char *filename, const union dc_shot_union *shoot, int camera_id, const struct capture_timing *timing) |
| Submit a published image to the bounded saved-analysis backlog. | |
| static void | stop_soda_backlog (void) |
| Join the analysis worker without draining session-only pending jobs. | |
| static void | start_pangea (void) |
| Launch optional mapping as a separate process with no inherited UART descriptors. | |
| static void | stop_pangea (void) |
| Bound optional map-worker shutdown rather than waiting for its input backlog. | |
| static void | release_worker_slot (void) |
| End worker ownership after publication, distinct from releasing the capture ticket. | |
| static struct capture_job * | capture_job_acquire_locked (void) |
| Reserve a zeroed slot in the bounded job pool. | |
| static void | capture_job_release_locked (struct capture_job *job) |
| Return a job slot while the caller owns the pool mutex. | |
| static void | capture_job_release (struct capture_job *job) |
| Return a job slot from a worker that does not hold the pool lock. | |
| static void | send_msg_image_buffer (void) |
| Consume the newest buffered payload for a legacy image request. | |
| static void | send_msg_status (void) |
| Queue a snapshot of USHER's capture counters. | |
| static void | print_usage (const char *program) |
| Print the invocation modes and build-specific defaults. | |
| static int | lock_local_instance (void) |
| Reserve the shared local serial endpoint namespace. | |
| static pid_t | start_local_serial_bridge (void) |
| Launch the PTY bridge for a hardware-free session. | |
| static int | wait_for_path (const char *path) |
| Give the new serial bridge time to publish one endpoint. | |
| static void | stop_local_serial_bridge (void) |
| Stop the owned simulator bridge and release the local lock. | |
| static void | handle_signal (int signal_number) |
| Request service shutdown from a signal handler. | |
| static void | notify_systemd_ready (void) |
| Send READY=1 to systemd when launched with a notify socket. | |
| static int | camera_backend_select (enum camera_backend_type type, bool test_mode) |
| Install the startup backend, optionally with local test hooks. | |
| static struct camera_backend | camera_backend_get (enum camera_backend_type type) |
| Return an immutable capability description without selecting or opening a camera. | |
| static struct camera_backend | camera_identity_get (int camera_id) |
| Resolve metadata and hooks for a concrete protocol camera identity. | |
| static void | camera_close_owner (unsigned camera_id) |
| Withdraw one backend from service and release its resources. | |
| static int | camera_register_stream (const struct camera_backend *backend) |
| Admit an optional stream once per owner, without opening its sensor. | |
| static enum camera_backend_type | camera_type_for_id (int camera_id) |
| Resolve runtime routing without mutating the global selected backend. | |
| static int | camera_prepare (int camera_id) |
| Select and lazily initialize a backend under the caller's camera ownership. | |
| static bool | lwir_ready_or_start_recovery (void) |
| Check thermal readiness or start at most one background recovery attempt. | |
| static void | lwir_mark_backoff (void) |
| Rate-limit thermal recovery so a missing USB camera does not consume every request. | |
| static void | cameras_deinit (void) |
| Tear down registered cameras and independently owned analysis workers. | |
| static int | local_backend_shoot (char *filename, size_t filename_size, int image_number) |
| Capture a local fixture under the selected optical camera identity. | |
| static void | handle_control_message (void) |
| Process negotiation or dispatch an addressed control request. | |
| static void | flush_control_results (void) |
| Pass dirty control receipts to the UART transmit queue. | |
| static void | wake_event_loop (void) |
| Prompt the event loop to recheck shared state. | |
| static int | event_wake_init (void) |
| Set up the self-pipe before installing its producers. | |
| static void | drain_event_wake (void) |
| Consume pending wake hints without monopolizing the event loop. | |
| static void | event_wake_close (void) |
| Withdraw the wake descriptors and close the self-pipe. | |
| static void | queue_shot_result (uint32_t request_id, int32_t number, unsigned camera_id, uint32_t status) |
| Hand one camera's terminal shot result to the serial owner. | |
| static void | queue_image_results (uint32_t request_id, int32_t number, uint8_t camera_mask, uint32_t status) |
| Report a shared outcome separately for each addressed image camera. | |
| static void | flush_shot_results (void) |
| Transfer a bounded batch of shot results to the UART transmit queue. | |
| static bool | usher_running (void) |
| Read service cancellation state through the capture flag accessor. | |
| static uint64_t | monotonic_time_us (void) |
| Read USHER's monotonic clock for local latency and event ordering. | |
| static int | event_loop_timeout_ms (void) |
| Select the next event-loop polling budget. | |
| static void | sleep_microseconds (uint64_t microseconds) |
| Pause for an interval using nanosleep's remaining-time result. | |
| static bool | set_exposure_latency (unsigned camera_id, const char *value) |
| Install a camera's calibrated exposure-to-delivery delay bounds. | |
| static void | send_clock_probe (uint64_t now_us) |
| Opportunistically send a low-priority flight-controller clock probe. | |
| static void | camera_record_pose (const uint8_t *payload, uint16_t length) |
| Feed one acoustic sample from the pose stream while a listening session is open. | |
| static void | record_clocked_pose (void) |
| Validate and enqueue a token-bound pose sample with clock evidence. | |
| int | main (int argc, char *argv[]) |
| Configure USHER and run its multiplexed UART/local-UDP event loop. | |
| static void | resolve_capture_pose (const union dc_shot_union *request, struct captured_image *image) |
| Resolve live pose evidence associated with an acquired image. | |
| static void * | recover_lwir_camera (void *unused) |
| Retry thermal startup outside both UART reception and the optical lane. | |
| static void * | handle_lwir_shoot (void *pointer) |
| Own thermal capture and its last-frame metadata independently of optical work. | |
| static void | chdk_start_cooldown_locked (void) |
| Pause new CHDK attempts after a failed request; the caller holds mut. | |
| static void * | handle_chdk_finish (void *pointer) |
| Write metadata for one captured CHDK image after the camera lane was released. | |
| static bool | start_chdk_finish (const struct capture_job *job, const struct captured_image *image) |
| Hand a captured image to the finisher, waiting if the previous one is still writing. | |
| static void * | handle_chdk_shoot (void *pointer) |
| Capture one CHDK request and release the camera lane before metadata is written. | |
| static uint32_t | camera_control_capabilities (uint8_t camera_id) |
| Resolve the currently advertised control capabilities. | |
| static void | queue_control_result (const struct usher_control_result *result) |
| Stage a worker's result for serial transmission. | |
| static void * | handle_chdk_control (void *pointer) |
| Execute an admitted lens command away from the serial owner. | |
| static bool | admit_chdk_control_locked (const struct usher_control_request *request, uint64_t now) |
Admit a control into the exclusive CHDK lane under mut. | |
| static void | negotiate_camera_controls (void) |
| Establish or renew a camera-control lease from the current UART message. | |
| static bool | start_chdk_worker (const union dc_shot_union *shoot, uint32_t request_id) |
| Schedule a shot on CHDK's independent capture lane. | |
| static bool | wait_owned_child (pid_t *child, unsigned timeout_ms) |
| Poll an owned subprocess for exit. | |
| static void * | handle_soda_backlog (void *unused) |
| Run saved-file analysis with fresh priority and idle catch-up. | |
Detailed Description
Main USHER daemon coordinating flight-controller triggers and camera backends.
The event loop receives validated UART frames, queues bounded capture jobs, dispatches backend work on detached workers, records metadata, and returns status. It deliberately keeps serial I/O separate from slow camera processes so one capture cannot block command reception. Backend failure is isolated per camera wherever possible; systemd owns whole-daemon restart for irrecoverable transport failures.
- Ownership at a glance
- The event loop owns protocol dispatch and survey admission. Optical tickets serialize CHDK/AIcam access; live LWIR has a separate worker and recovery lock. A split-phase image retains its backend completion table after the optical lane is released. Live SODA uses a separate single worker and owns filenames only. Keep these boundaries distinct: accepting a trigger, owning pixels and saving a geotagged original are three different events.
- Warning
- Bounded workers prevent software backlog growth; they do not isolate shared power, storage, kernel stalls or the whole board's memory consumption.
Definition in file usher.c.
Macro Definition Documentation
◆ ANGLE_BFP_SCALE
◆ CAPTURE_JOB_CAPACITY
| #define CAPTURE_JOB_CAPACITY (MAX_PROCESSING_THREADS + 1) |
◆ CHDK_RETRY_COOLDOWN_US
◆ DEBUG_HEARTBEAT_SECONDS
◆ EVENT_LOOP_ACTIVE_TIMEOUT_MS
◆ EVENT_LOOP_TIMEOUT_MS
◆ IMAGE_SIZE
◆ LWIR_RETRY_COOLDOWN_US
◆ LWIR_RETRY_POLL_US
◆ LWIR_WAIT_MAX_US
◆ MAX_BACKEND_RESULTS_PER_PASS
◆ MAX_FILENAME
◆ MAX_IMAGE_BUFFERS
◆ MAX_PROCESSING_THREADS
◆ POSITION_BFP_SCALE
◆ RAD_TO_DEG
◆ SERIAL_READ_BUFFER_SIZE
◆ SHOT_RESULT_CAPACITY
◆ SODA
◆ SODA_BACKLOG_CAPACITY
◆ SODA_SHUTDOWN_GRACE_MS
◆ SODA_WAIT_INTERVAL_US
◆ SPEED_BFP_SCALE
◆ USHER_AI_CAM_PHOTO_DIR
◆ USHER_CHDK_PHOTO_DIR
◆ USHER_LOCAL_APP_DEVICE
◆ USHER_LOCAL_LOCK_FILE
◆ USHER_LOCAL_PHOTO_DIR
◆ USHER_LOCAL_SIM_DEVICE
◆ USHER_LWIR_CAM_PHOTO_DIR
◆ USHER_MAX_ARGUMENTS
◆ USHER_MAX_PARSED_ARGUMENTS
| #define USHER_MAX_PARSED_ARGUMENTS (USHER_MAX_ARGUMENTS * 2 + 1) |
◆ USHER_MOCK_IMAGE
◆ USHER_POSE_LOG_DIR
◆ USHER_SERIAL_DEVICE
◆ USHER_SODA
◆ USHER_SODA_IDLE_MS
◆ USHER_SODA_RETRY_MS
◆ USHER_SODA_TIMEOUT_MS
◆ USHER_SPOTTERCAM_PHOTO_DIR
| #define USHER_SPOTTERCAM_PHOTO_DIR USHER_AI_CAM_PHOTO_DIR |
Enumeration Type Documentation
◆ camera_stream_state
| enum camera_stream_state |
Function Documentation
◆ admit_chdk_control_locked()
|
static |
Admit a control into the exclusive CHDK lane under mut.
- Parameters
-
request Validated command to copy into the reserved slot. now Current local monotonic time in microseconds.
- Returns
- False for busy, cooldown, or shutdown; true if handled, even if worker creation fails.
Claim the same lane used by CHDK capture. If spawn fails, release the lane and stage a failure receipt rather than leaving a pending request.
◆ camera_backend_get()
|
static |
◆ camera_backend_select()
|
static |
Install the startup backend, optionally with local test hooks.
- Parameters
-
type Requested registry backend. test_mode True to replace hardware capture with simulation.
- Returns
- Zero on selection, or -1 if the registry has no such backend.
Preserve the selected camera identity in test mode while removing native capture operations so a mock job cannot acquire the hardware.
◆ camera_close_owner()
|
static |
Withdraw one backend from service and release its resources.
- Parameters
-
camera_id Owner slot, including the default slot.
Clear dispatch state, drain an active point stream, then release the initialized backend. Clear its result caches before the slot is reused.
◆ camera_control_capabilities()
|
static |
Resolve the currently advertised control capabilities.
- Parameters
-
camera_id Protocol camera ID.
- Returns
- Supported command bits, or zero when controls are unavailable.
Advertise physical lens operations only when the asynchronous CHDK lane and its required hooks are available, never in mock capture modes.
◆ camera_identity_get()
|
static |
Resolve metadata and hooks for a concrete protocol camera identity.
- Parameters
-
camera_id Protocol camera ID.
- Returns
- Registry entry for the current routing mode.
Keep identity lookup separate from selecting the global backend so a second sensor's result does not change capture configuration.
◆ camera_point_valid()
|
static |
Check whether a backend result is suitable for the point wire format.
- Parameters
-
point Nullable candidate point.
- Returns
- True when marked valid and within the coordinate, height, and quality bounds.
Reject the all-zero geographic placeholder; passing this check does not establish survey accuracy.
◆ camera_prepare()
|
static |
Select and lazily initialize a backend under the caller's camera ownership.
- Parameters
-
camera_id Image-camera identity, not a mask.
- Returns
- Zero when ready, negative on invalid input, shutdown or backend failure.
A failed optional camera must not stop the other bits of a mixed request.
◆ camera_record_pose()
|
static |
◆ camera_register_stream()
|
static |
◆ camera_type_for_id()
|
static |
◆ cameras_deinit()
|
static |
◆ capture_arbiter_failed()
|
static |
◆ capture_image()
|
static |
Acquire pixels or a completed file for a single camera.
- Parameters
-
shoot Original pose-tagged request; not automatically exposure-time pose. [out] image Per-image state passed to finish_image() on success. camera_id Sensor identity used for metadata and independent survey accounting. backend Driver selected under the caller's camera ownership.
- Returns
- True when finish_image() is owed, including pending split-phase captures.
- Note
- A negative acquire result must not fall through to a second exposure. Only the driver's explicit positive fallback result allows synchronous shooting.
◆ capture_job_acquire_locked()
|
static |
◆ capture_job_release()
|
static |
Return a job slot from a worker that does not hold the pool lock.
- Parameters
-
job Previously reserved slot, no longer in use by the caller.
Take mut around pool bookkeeping; callers already holding it must use capture_job_release_locked() instead.
◆ capture_job_release_locked()
|
static |
◆ chdk_start_cooldown_locked()
|
static |
◆ defer_saved_analysis()
|
static |
Submit a published image to the bounded saved-analysis backlog.
- Parameters
-
filename Path of the nonempty original JPEG. shoot Trigger evidence copied into the job. camera_id Camera identity used to route the analysis. timing Optional capture timing copied into the job.
Save file identity with the job so the worker can detect a later replacement. If the backlog is unavailable, preserve the original for offline processing rather than blocking capture.
◆ defer_soda()
|
static |
Queue analysis of a saved original without retaining camera or pixel buffers.
- Parameters
-
filename Nonempty regular image file, unchanged while queued. shoot Pose/number associated with that saved image, copied into the job. camera_id Sensor-specific SODA route.
Overflow keeps existing queued work and leaves the new original on disk. Worker-creation failure retains the job so a later submission can retry startup.
◆ drain_camera_backends()
|
static |
◆ drain_event_wake()
|
static |
◆ event_loop_timeout_ms()
|
static |
Select the next event-loop polling budget.
- Returns
- Active or idle timeout, in milliseconds.
Keep the shorter timeout while work may need servicing even without another UART input. Read capture/control state and shot results under their respective locks instead of nesting them.
◆ event_wake_close()
|
static |
◆ event_wake_init()
|
static |
◆ finish_image()
|
static |
Complete publication and metadata before releasing survey ownership.
- Parameters
-
shoot Original request, retained as provenance if exposure pose is available. [in,out] image Acquired image and its original driver's completion hooks.
Native completion can wait for a JPEG here without holding the optical lane. Metadata-dependent drivers still call this under their capture ownership. Live analysis is submitted only after saving; local/test callers retain the synchronous behavior expected by their tools and regression fixtures.
◆ flush_cam_point_updates()
|
static |
◆ flush_cam_points()
|
static |
◆ flush_control_results()
|
static |
◆ flush_shot_results()
|
static |
Transfer a bounded batch of shot results to the UART transmit queue.
The event loop is the only consumer. Leave the head queued until transmit admission succeeds, and release the result lock around that call so a worker can append without waiting on the UART path.
◆ handle_chdk_control()
|
static |
Execute an admitted lens command away from the serial owner.
- Parameters
-
pointer Address of the request in the reserved CHDK control slot.
- Returns
- NULL after releasing the CHDK lane.
Copy the job, execute under exclusive device ownership and report observation evidence only for applied controls. An unsuccessful operation sets a cooldown before another command or capture may use the lane.
◆ handle_chdk_finish()
|
static |
◆ handle_chdk_shoot()
|
static |
Capture one CHDK request and release the camera lane before metadata is written.
- Parameters
-
pointer Dedicated single-flight request storage, retained until the capture ends.
- Returns
- NULL after teardown and signalling worker completion.
A captured image moves to handle_chdk_finish(), which owns the shot result, so EXIF and publication overlap the next camera operation.
◆ handle_control_message()
|
static |
◆ handle_lwir_shoot()
|
static |
◆ handle_msg_shoot()
|
static |
Consume one optical ticket, then finish images outside the lane where safe.
- Parameters
-
ptr Pool-owned capture_job, released on every worker exit.
- Returns
- NULL, as required by pthread entry points.
The worker slot and camera lane have different lifetimes: publication may still own a bounded worker slot after the next acquisition has started.
◆ handle_received_message()
|
static |
Dispatch one complete UART frame without running slow camera work inline.
The serial event-loop owner calls this once per parsed message. Camera masks are split into independent backend work; EARcam receipt-time tagging is separate from photographic queueing. New protocols must validate lengths and session ownership before causing camera or service side effects.
◆ handle_signal()
|
static |
Request service shutdown from a signal handler.
- Parameters
-
signal_number Signal delivered by the OS; all installed cases request shutdown.
Notify the event loop rather than closing camera or UART state in the handler. Owners perform teardown in ordinary execution context.
◆ handle_soda_backlog()
|
static |
Run saved-file analysis with fresh priority and idle catch-up.
- Parameters
-
unused Unused pthread argument.
- Returns
- NULL when stopped; pending filenames remain on disk, not in a durable job queue.
One lower-priority worker limits concurrent decoding. It never owns a camera slot. An already running analysis is not preempted when a trigger arrives.
◆ handle_targeted_start()
|
static |
Start a point session for the addressed backend or backends.
- Parameters
-
camera_id Camera ID, or USHER_CAMERA_ALL for broadcast. session_id Nonzero session identifier from the caller.
Treat a duplicate START as idempotent and clear old result state only for a new ID. Prefer the configured point stream when present.
◆ handle_targeted_stop()
|
static |
Request the stop phase for a matching point session.
- Parameters
-
camera_id Camera ID, or USHER_CAMERA_ALL for broadcast. session_id Nonzero session identifier.
Ignore a stale session. For a repeated STOP, resend a cached result when available instead of rerunning the stop transition.
◆ local_backend_shoot()
|
static |
Capture a local fixture under the selected optical camera identity.
- Parameters
-
[out] filename Output path; use only on success. filename_size Capacity including the terminator. image_number Photo number.
- Returns
- Zero on capture, or -1 on invalid identity or capture failure.
Supply the concrete camera identity so the fixture uses the appropriate prefix while remaining distinct from a physical capture.
◆ lock_local_instance()
|
static |
◆ lwir_mark_backoff()
|
static |
◆ lwir_ready_or_start_recovery()
|
static |
◆ main()
| int main | ( | int | argc, |
| char * | argv[] ) |
Configure USHER and run its multiplexed UART/local-UDP event loop.
- Returns
- Process status suitable for systemd restart policy.
After argument validation, startup claims the fixed local payload endpoint before touching shared UART or camera resources. This rejects a second process early when the systemd service is already active. USHER then validates selected backends, starts optional persistent services, initializes non-blocking transport, and drains serial bytes into the protocol parser. Shutdown wakes and drains detached workers before releasing backend resources.
◆ monotonic_time_us()
|
static |
◆ negotiate_camera_controls()
|
static |
Establish or renew a camera-control lease from the current UART message.
Pair a fresh session with the peer's nonce, report available capabilities, and require a timely matching echo before accepting commands. Replacing the session clears old receipt and ordering state.
◆ normalize_long_options()
|
static |
Translate supported long options into the short-option parser's input.
- Parameters
-
argc Original argument count. argv Original argument vector. [out] normalized Output vector borrowing strings from argvandaliases.capacity Number of pointer slots including room for the terminator. aliases Accepted long names, short spellings and operand rules. alias_count Number of entries in aliases.
- Returns
- Normalized count, or -1 on invalid input or insufficient capacity.
Split inline operands without copying their text and preserve arguments after the option terminator. Keep both input tables alive.
◆ notify_systemd_ready()
|
static |
◆ prepare_session_backend()
|
static |
Ensure a point-session backend has a registered owner.
- Parameters
-
camera_id Protocol camera ID.
- Returns
- True once a complete session backend is initialized.
Check all lifecycle hooks before initialization and reuse an existing owner rather than reopening a session-capable device.
◆ print_usage()
|
static |
◆ queue_control_result()
|
static |
◆ queue_image_results()
|
static |
Report a shared outcome separately for each addressed image camera.
- Parameters
-
request_id Correlation ID, or zero for a legacy request. number Flight-controller photo number. camera_mask Bitmask indexed by camera ID minus one. status Outcome to report for each selected camera.
Expand only image-camera bits so a shared admission failure retains per-camera correlation without generating terminal results for non-image backends.
◆ queue_shot_result()
|
static |
Hand one camera's terminal shot result to the serial owner.
- Parameters
-
request_id Correlation ID; zero denotes a legacy request without an acknowledgement. number Flight-controller photo number. camera_id Camera that owns the outcome. status Wire result code.
Do not block a capture worker on UART backpressure. Count drops if the bounded queue fills, and wake the loop even for legacy work.
◆ record_clocked_pose()
|
static |
◆ recover_lwir_camera()
|
static |
◆ release_worker_slot()
|
static |
◆ resolve_capture_pose()
|
static |
Resolve live pose evidence associated with an acquired image.
- Parameters
-
request Original trigger whose photo number is retained. [in,out] image Image and timing evidence to qualify.
Prefer frame-bound timing when available. Wait briefly for a pose bracket, but promote the aligned pose to exposure pose only when the time evidence represents exposure, not merely frame delivery.
◆ run_soda()
|
static |
Run one analysis child directly with bounded runtime and termination grace.
- Parameters
-
filename Saved original to analyze, never deleted by this function. shoot Immutable image-associated pose used to form arguments. camera_id Sensor route selecting the SODA option.
- Returns
- Child exit status, or -1 for spawn/wait/cancellation/deadline failure.
- Note
- Direct argv avoids shell interpretation. Successful exit means processing completed, not that an object was detected or that each side effect is unique.
◆ send_clock_probe()
|
static |
◆ send_msg_cam_point()
|
static |
Cache and attempt to queue a terminal point-session result.
- Parameters
-
camera_id Concrete backend ID. session_id Nonzero identifier for the session being completed. point Backend result, or NULL for no valid point.
Keep the result after successful transmission so a repeated STOP can recover it. Invalid points carry status but no coordinates.
◆ send_msg_cam_point_update()
|
static |
◆ send_msg_image_buffer()
|
inlinestatic |
◆ send_msg_status()
|
inlinestatic |
◆ service_camera_backends()
|
static |
◆ service_capture_arbiter()
|
static |
Bridge survey decisions to current backend readiness from the serial event loop.
- Parameters
-
now_us Current MORA monotonic time in microseconds.
Readiness is a snapshot, not a reservation. Dispatch still checks driver admission. Retain one popped result across a full UART TX queue rather than discarding it merely because the wire was briefly busy.
◆ set_exposure_latency()
|
static |
Install a camera's calibrated exposure-to-delivery delay bounds.
- Parameters
-
camera_id Supported image camera identifier. value Comma-separated minimum and maximum delays in milliseconds.
- Returns
- True if both bounds were accepted; false leaves the setting unchanged.
Round outward when converting to integer microseconds so unit conversion never narrows the supplied uncertainty interval.
◆ sleep_microseconds()
|
static |
◆ start_chdk_finish()
|
static |
◆ start_chdk_worker()
|
static |
Schedule a shot on CHDK's independent capture lane.
- Parameters
-
shoot Trigger copied into the lane's single job slot. request_id Correlation ID, or zero for an unacknowledged request.
- Returns
- True when the detached worker was started.
Share admission with lens control. Release survey admission and report failure if shutdown, cooldown, contention, or thread setup prevents a shot.
◆ start_local_serial_bridge()
|
static |
◆ start_lwir_worker()
|
static |
Dispatch a single-flight thermal request without waiting for USB recovery.
- Parameters
-
[in] shoot Request copied into worker-owned storage on admission. [in] request_id Correlation ID returned to the flight controller; distinct from photo number. [in] received_us Monotonic time when the request was admitted, used to reject stale queued work.
This function is called by the serial owner. Failed admission releases matching survey ownership so a missing thermal camera cannot remain permanently busy.
◆ start_pangea()
|
static |
◆ start_shoot_worker()
|
static |
Dispatch admitted image bits while preserving bounded legacy/local policies.
- Parameters
-
shoot Request to copy; the caller need not retain its storage. camera_mask Selected image cameras; live CHDK and LWIR have independent lanes. request_id Per-request reply identity, distinct from the photo number.
Survey jobs retain their ledger ownership; local/test jobs stay FIFO.
◆ stop_local_serial_bridge()
|
static |
◆ stop_pangea()
|
static |
◆ stop_soda_backlog()
|
static |
Join the analysis worker without draining session-only pending jobs.
- Precondition
- Set keep_running to zero first so an active run_soda() follows its shutdown deadline.
Joining ensures analysis no longer touches state that camera cleanup may release. Originals survive; pending analysis is not automatically persisted.
◆ usher_running()
|
static |
◆ wait_for_path()
|
static |
Give the new serial bridge time to publish one endpoint.
- Parameters
-
path Endpoint path to check.
- Returns
- Zero if found during polling, or -1 if it never appears.
Poll with a fixed attempt limit so failure to create a link is detected rather than waiting indefinitely for readiness.
◆ wait_owned_child()
|
static |
Poll an owned subprocess for exit.
- Parameters
-
[in,out] child Positive child PID, reset to -1 when ownership ends. timeout_ms Polling budget in milliseconds.
- Returns
- True if reaped or no longer a child; false on deadline or wait error.
Retain the PID on failure so later cleanup still knows which child it owns.
◆ wake_event_loop()
|
static |
Variable Documentation
◆ backend_service_pending
◆ camera
|
static |
◆ camera_available
|
static |
◆ camera_initialized
|
static |
◆ camera_owners
|
static |
◆ camera_source_image
|
static |
True when –spottercam was selected: camera id USHER_CAMERA_AICAM still means "the AI camera" on the wire (unchanged for the flight controller/NPS), but camera_prepare() and cameras_deinit() route it to the object-detection backend instead of plain ai_cam_pipe capture. Plain –aicam behavior is completely unaffected.
◆ camera_stream_states
|
static |
◆ camera_unavailable
◆ camera_warned
◆ capture_job_used
|
static |
◆ capture_jobs
|
static |
◆ chdk_async_capture_enabled
◆ chdk_capture_in_progress
◆ chdk_capture_job
|
static |
◆ chdk_control_job
|
static |
◆ [struct]
| struct { ... } chdk_finish |
◆ chdk_finish_in_progress
◆ chdk_retry_after_us
◆ clock_probe_count
◆ clock_probes_enabled
◆ clock_rejected_count
◆ clock_reply_count
◆ configured_camera_backend
|
static |
◆ control_confirmed
◆ control_high_water
◆ control_negotiated_us
◆ control_nonce
◆ [struct]
| struct { ... } control_results[8] |
◆ control_session
◆ debug_enabled
◆ dirty
◆ earcam_requested
◆ environ
|
extern |
◆ event_wake_reader
◆ event_wake_writer
◆ [struct]
| struct { ... } exposure_latency[4] |
◆ fc_clock
|
static |
◆ id
◆ image
| struct captured_image image |
◆ image_buffer
|
static |
◆ image_count
◆ image_idx
◆ is_shooting
◆ job
| struct capture_job job |
◆ keep_running
◆ last_photo_request_us
◆ live_soda_mutex
|
static |
◆ local_bridge_owned
◆ local_bridge_requested
◆ local_capture_only
◆ local_lock_fd
◆ local_mode
◆ loomcam_enabled
◆ loomcam_model
|
static |
◆ loomcam_references
|
static |
◆ lwir_active_received_us
◆ lwir_async_recovery_enabled
◆ lwir_busy_skipped_count
◆ lwir_camera_mutex
|
static |
◆ lwir_capture_in_progress
◆ lwir_handoff_in_progress
◆ lwir_recovery_in_progress
◆ lwir_retry_after_us
|
static |
◆ maximum_us
◆ minimum_us
◆ mock_image
|
static |
◆ mock_lens_profile
◆ mock_map_cache
|
static |
◆ mock_map_enabled
◆ mock_map_horizontal_fov
◆ mock_map_vertical_fov
◆ mock_transform_enabled
◆ motion_compensation_enabled
◆ mut
◆ next_capture_ticket
◆ next_clock_probe_us
◆ next_job_ticket
◆ optical_camera_id
|
static |
◆ pangea_camera_profile
◆ pangea_directory
◆ pangea_pause_file
◆ pangea_pid
◆ pending
◆ [struct]
| struct { ... } point_sessions[CAMERA_BACKEND_MAX_ID] |
◆ point_update_pending
|
static |
◆ point_updates
|
static |
◆ pose_log_dir
|
static |
◆ received_us
◆ request_id
◆ requested_camera_backend
|
static |
◆ result
| union usher_cam_point_result_union result |
◆ serial_receive_monotonic_us
◆ shooting_count
◆ shooting_thread_count
◆ shot
| union dc_shot_union shot |
◆ shot_result_count
◆ shot_result_dropped
◆ shot_result_head
◆ shot_result_mutex
|
static |
◆ shot_results
|
static |
◆ socat_pid
◆ soda_available
|
static |
◆ soda_backlog
|
static |
◆ soda_backlog_active
◆ soda_backlog_completed
◆ soda_backlog_count
◆ soda_backlog_failed
◆ soda_backlog_head
◆ soda_backlog_overflow
◆ soda_backlog_started
◆ soda_backlog_stop
◆ soda_backlog_thread
◆ soda_busy_deferred_count
◆ stop_requested
◆ superseded_capture_count
◆ test_capture_enabled
◆ valid
◆ waiting_capture
|
static |
◆ [struct]
| struct { ... } waiting_lwir |