Loading...
Searching...
No Matches
capture_arbiter.c
Go to the documentation of this file.
119 const ssize_t count = read(descriptor, (unsigned char *)token + received, sizeof(*token) - received);
128/** @brief Record a terminal outcome without allowing telemetry backlog to block camera release. */
137 union usher_capture_arbiter_result_union *result = &results[(result_head + result_count++) % ARBITER_COUNT(results)];
176 if (!origin_set || camera_id < 1 || camera_id > COVERAGE_CAMERAS || !calibrated[camera_id - 1]) return false;
199/** @brief Take the short arc across heading wrap, using widened subtraction before conversion. */
209 const struct capture_pose *latest = &poses[(pose_head + pose_count - 1) % ARBITER_COUNT(poses)];
210 const struct capture_pose *previous = &poses[(pose_head + pose_count - 2) % ARBITER_COUNT(poses)];
213 || latest->time_us <= previous->time_us || latest->time_us - previous->time_us > 200000) return false;
216 const double roll_rate = angle_delta(previous->shot.data.phi, latest->shot.data.phi) / sample_time;
217 const double pitch_rate = angle_delta(previous->shot.data.theta, latest->shot.data.theta) / sample_time;
218 const double yaw_rate = angle_delta(previous->shot.data.psi, latest->shot.data.psi) / sample_time;
220 || fabs(latest->shot.data.phi / 4096.0) > 0.6 || fabs(latest->shot.data.theta / 4096.0) > 0.6) return false;
224 const double predicted_latitude = shot->data.lat / 1e7 + speed * elapsed * cos(course) / 6378137 / radians;
312void capture_arbiter_set_scope(const union usher_capture_arbiter_state_union *scope, uint64_t now_us)
314 if (!scope || scope->data.active > 1 || scope->data.camera_mask > USHER_CAMERA_MASK_ALL) return;
318 scope_mask = scope->data.camera_mask & (USHER_CAMERA_MASK_CHDK | USHER_CAMERA_MASK_AICAM | USHER_CAMERA_MASK_LWIR);
334bool capture_arbiter_offer(const union usher_capture_arbiter_shoot_union *request, uint64_t now_us)
341 struct capture_intent offered = {.shot = request->data.shot, .mask = request->data.camera_mask & 7U, .received_us = now_us};
350 if (active[index].mask && active[index].shot.data.nr == offered.shot.data.nr) offered.mask &= ~active[index].mask;
366 waiting[destination] = (struct capture_intent) {.shot = offered.shot, .mask = bit, .received_us = now_us};
373/** @brief Make one admission decision while guard is held; no callbacks or dynamic allocation. */
374static bool take_locked(uint32_t ready_mask, uint64_t now_us, union dc_shot_union *shot, uint8_t *mask)
379 || now_us - intent->received_us > intent_lifetime_us)) expire(intent, USHER_CAPTURE_ARBITER_EXPIRED);
382 for (size_t index = 0; index < ARBITER_COUNT(active); ++index) if (!active[index].mask) ++free_slots;
404 if (predict(now_us, ¤t, &uncertainty) && project(¤t, camera_id, uncertainty, &candidate)) {
413 if (!predict(planned, &prediction, &error) || !project(&prediction, camera_id, error, &opportunity)) break;
418 const int choice = coverage_choose(covered, opportunities, count, now_us, service_us[camera_id - 1]);
431 && coverage_overlap(covered, &opportunities[choice], &last_saved[camera_id - 1]) >= minimum_overlap)
442 active[slot] = (struct capture_intent) {.shot = intent->shot, .mask = 1U << index, .received_us = now_us};
450bool capture_arbiter_take(uint32_t ready_mask, uint64_t now_us, union dc_shot_union *shot, uint8_t *mask)
466 if (active[index].mask == (1U << (camera_id - 1)) && active[index].shot.data.nr == shot->data.nr) {
481 if (exposure_pose_valid && isfinite(uncertainty_m) && uncertainty_m >= 0 && now_us >= intent->received_us) {
489 if (project(shot, camera_id, uncertainty_m, &candidate) && coverage_commit(covered, &candidate)) {
501bool capture_arbiter_result(union usher_capture_arbiter_result_union *result, uint32_t ready_mask)
520 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index) if (waiting[index].mask) pending = true;
521 for (size_t index = 0; index < ARBITER_COUNT(active); ++index) if (active[index].mask) pending = true;
558 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index) expire(&waiting[index], USHER_CAPTURE_ARBITER_EXPIRED);
571void capture_arbiter_pose_sample(const union usher_pose_sample_union *sample, uint64_t earliest_us, uint64_t latest_us)
589 if (pose_count && middle <= poses[(pose_head + pose_count - 1) % ARBITER_COUNT(poses)].time_us) goto done;
591 if (!gps_changed_us || gps_week != sample->data.gps_week || gps_tow_ms != sample->data.gps_tow_ms) {
593 || (sample->data.gps_week == gps_week && sample->data.gps_tow_ms < gps_tow_ms))) pose_count = 0;
612 || !compensate_ground_position(&aligned.data.lat, &aligned.data.lon, speed, atan2(east, north), age_s)) {
624 .accuracy_m = accuracy_m, .navigation_age_ms = projected ? age_ms : 0, .navigation_projected = projected
681 shot->data.groundalt = interpolate(before->shot.data.groundalt, after->shot.data.groundalt, fraction);
688 shot->data.vground = interpolate(before->shot.data.vground, after->shot.data.vground, fraction);
697 observation->navigation_projected = before->navigation_projected || after->navigation_projected;
707bool capture_arbiter_pose_at(uint64_t time_us, uint64_t time_error_us, union dc_shot_union *shot, double *uncertainty_m)
723 if (pose_at(time, (span + 1) / 2, &observation->pose, &observation->pose_uncertainty_m, observation)) {
739bool capture_arbiter_frame_timing(const char *filename, unsigned camera_id, struct capture_observation *observation)
795bool capture_arbiter_frame_pose(const char *filename, unsigned camera_id, const union dc_shot_union *request,
Read Linux's boot-unique identifier for pose-log session provenance.
static void usher_boot_id(char result[37])
Fill a 36-character boot UUID or the stable fallback "unknown".
Definition boot_id.h:36
bool usher_camera_profile_read(const char *filename, struct usher_camera_profile *profile)
Read a bounded PANGEA_CAMERA_V1 key=value calibration file.
Definition camera_profile.c:132
Public C API for reading PANGEA camera calibration profiles.
static bool project(const union dc_shot_union *shot, unsigned camera_id, double uncertainty, struct coverage_candidate *candidate)
Convert FC units and estimate geometric detail using this camera's calibration.
Definition capture_arbiter.c:173
bool capture_arbiter_set_overlap(double overlap)
Set the overlap floor for deliberate predictive delay, not FC shot spacing.
Definition capture_arbiter.c:286
static bool take_locked(uint32_t ready_mask, uint64_t now_us, union dc_shot_union *shot, uint8_t *mask)
Make one admission decision while guard is held; no callbacks or dynamic allocation.
Definition capture_arbiter.c:374
static double angle_delta(int32_t first, int32_t second)
Take the short arc across heading wrap, using widened subtraction before conversion.
Definition capture_arbiter.c:200
void capture_arbiter_pose_invalidate(void)
Forget pose history when synchronization is lost; keep saved coverage.
Definition capture_arbiter.c:562
void capture_arbiter_set_enforce(bool enabled)
Enable coverage-based suppression and limited delay, or observe decisions only.
Definition capture_arbiter.c:279
static void expire(struct capture_intent *intent, uint32_t outcome)
Retire an intention and record its terminal outcome.
Definition capture_arbiter.c:153
bool capture_arbiter_pending(void)
Check whether waiting or active survey work remains.
Definition capture_arbiter.c:516
static bool fresh_scope(uint64_t now_us)
Check whether the active survey scope is still current.
Definition capture_arbiter.c:167
void capture_arbiter_pose_sample(const union usher_pose_sample_union *sample, uint64_t earliest_us, uint64_t latest_us)
Add a pose only after the caller has established bounded clock alignment.
Definition capture_arbiter.c:571
bool capture_arbiter_frame_timing(const char *filename, unsigned camera_id, struct capture_observation *observation)
Read embedded capture identity from a stable JPEG; true need not qualify timing.
Definition capture_arbiter.c:739
bool capture_arbiter_take(uint32_t ready_mask, uint64_t now_us, union dc_shot_union *shot, uint8_t *mask)
Admit the oldest ready camera intention after optional coverage evaluation.
Definition capture_arbiter.c:450
static bool predict(uint64_t time_us, union dc_shot_union *shot, double *uncertainty)
Forecast a short continuation only when mapped motion is suitably well behaved.
Definition capture_arbiter.c:206
bool capture_arbiter_owns(int32_t number)
Identify a shot whose active survey ownership must not be superseded.
Definition capture_arbiter.c:526
static struct coverage_candidate last_saved[COVERAGE_CAMERAS]
Definition capture_arbiter.c:83
bool capture_arbiter_frame_pose(const char *filename, unsigned camera_id, const union dc_shot_union *request, union dc_shot_union *exposure, double *uncertainty_m)
Associate embedded exposure evidence with this JPEG before geotagging.
Definition capture_arbiter.c:795
uint32_t capture_arbiter_session_id(void)
Return the peer-session token, or zero when survey mode is not configured.
Definition capture_arbiter.c:304
void capture_arbiter_set_scope(const union usher_capture_arbiter_state_union *scope, uint64_t now_us)
Refresh survey authorization or cancel waiting work when scope is withdrawn.
Definition capture_arbiter.c:312
bool capture_arbiter_set_camera_capacity(unsigned camera_id, unsigned limit)
Set admission from a backend's actual capacity, independent of camera ID.
Definition capture_arbiter.c:295
bool capture_arbiter_result(union usher_capture_arbiter_result_union *result, uint32_t ready_mask)
Pop a bounded best-effort result for UART transmission.
Definition capture_arbiter.c:501
void capture_arbiter_acquired(int32_t number, unsigned camera_id, uint64_t now_us)
Learn acquisition latency separately from slower JPEG publication.
Definition capture_arbiter.c:536
void capture_arbiter_complete(const union dc_shot_union *shot, unsigned camera_id, bool saved, bool exposure_pose_valid, double uncertainty_m, uint64_t now_us)
Release admission and optionally credit verified saved coverage.
Definition capture_arbiter.c:459
bool capture_arbiter_observation_pose(struct capture_observation *observation, uint64_t wait_us)
Resolve one bounded observation; wait_us is 0 on the serial thread, at most 200000 in workers.
Definition capture_arbiter.c:712
static struct capture_intent waiting[COVERAGE_CANDIDATES *COVERAGE_CAMERAS]
Definition capture_arbiter.c:73
bool capture_arbiter_load_camera(const char *filename)
Load one camera's measured profile without guessing geometry from its ID.
Definition capture_arbiter.c:238
static uint64_t monotonic_us(void)
Read the local clock used for capture deadlines and pose alignment.
Definition capture_arbiter.c:99
static void report(const struct capture_intent *intent, unsigned camera_id, uint32_t outcome)
Record a terminal outcome without allowing telemetry backlog to block camera release.
Definition capture_arbiter.c:129
void capture_arbiter_stop(void)
Cancel waiting intentions, retaining active-image ownership and saved coverage.
Definition capture_arbiter.c:553
static bool pose_at(uint64_t time_us, uint64_t time_error_us, union dc_shot_union *shot, double *uncertainty_m, struct capture_observation *observation)
Interpolate a qualified pose from bounded sample history.
Definition capture_arbiter.c:657
static bool random_session(uint32_t *token)
Obtain a nonzero token for a new survey session.
Definition capture_arbiter.c:113
static int32_t interpolate(int32_t first, int32_t second, double fraction)
Interpolate a scalar fixed-point pose field.
Definition capture_arbiter.c:639
bool capture_arbiter_pose_at(uint64_t time_us, uint64_t time_error_us, union dc_shot_union *shot, double *uncertainty_m)
Interpolate within trusted nearby pose samples, never across a long gap.
Definition capture_arbiter.c:707
bool capture_arbiter_offer(const union usher_capture_arbiter_shoot_union *request, uint64_t now_us)
Split a survey request into bounded per-camera intentions.
Definition capture_arbiter.c:334
Session-scoped survey admission and saved-image evidence for USHER.
static bool capture_observation_valid(const struct capture_observation *observation)
Check that an observation supplies a usable time interval.
Definition capture_timing.h:63
double coverage_gain(const struct coverage_state *state, const struct coverage_candidate *candidate)
Score additional detail in conservatively contained cells without mutation.
Definition coverage_scheduler.c:199
bool coverage_commit(struct coverage_state *state, const struct coverage_candidate *candidate)
Credit a successfully saved observation, retaining the best detail per cell.
Definition coverage_scheduler.c:204
bool coverage_init(struct coverage_state *state, double east, double north, double cell_m)
Clear the ledger and set its fixed spatial domain.
Definition coverage_scheduler.c:105
bool coverage_project(const struct coverage_camera *camera, const struct coverage_pose *pose, double origin_latitude_deg, double origin_longitude_deg, struct coverage_footprint *footprint)
Project delivered-image corners onto a local flat ground plane.
Definition coverage_scheduler.c:46
int coverage_choose(const struct coverage_state *state, const struct coverage_candidate *candidates, size_t count, uint64_t now_us, uint64_t service_us)
Choose the first observation of the best feasible one- or two-shot plan.
Definition coverage_scheduler.c:218
bool coverage_wholly_saved(const struct coverage_state *state, const struct coverage_candidate *candidate)
Check whether skipping this observation is geometrically conservative.
Definition coverage_scheduler.c:252
double coverage_overlap(const struct coverage_state *state, const struct coverage_candidate *first, const struct coverage_candidate *second)
Estimate conservative overlap for deciding whether a delay is acceptable.
Definition coverage_scheduler.c:269
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
Definition dipla_camera_backend.c:206
static bool enabled(void)
Report explicit opt-in independently of process or model readiness.
Definition dipla_camera_backend.c:75
Bounded C11 EXIF metadata and JPEG streaming interfaces.
int exif_parse(struct exif_view *view, const unsigned char *payload, size_t size)
Validate an EXIF APP1 payload and create a borrowed view.
Definition exifite.c:257
bool exif_get(const struct exif_view *view, enum exif_directory directory, uint16_t tag, struct exif_value *value)
Look up a directory-local tag without copying its bytes.
Definition exifite.c:310
#define EXIF_MAX_PAYLOAD
APP1 payload ceiling: the JPEG length includes its own two bytes.
Definition exifite.h:51
int exif_jpeg_dimensions(FILE *input, uint32_t *width, uint32_t *height, unsigned *components)
Inspect the frame header without allocating or decoding image pixels.
Definition exifite.c:1309
int exif_read_stream(FILE *input, unsigned char *payload, size_t capacity, size_t *size)
Read capture EXIF from an already-open JPEG without reopening its path.
Definition exifite.c:1013
Advance a position along ground velocity by a bounded elapsed interval.
static int compensate_ground_position(int32_t *latitude, int32_t *longitude, double speed, double course, double delay)
Correct latitude/longitude for horizontal platform motion during capture.
Definition motion_compensation.h:42
Exact bounded SENSOR02 capture evidence, independent of TIFF byte order.
static bool sensor_capture_decode(struct sensor_capture *record, const unsigned char *data, size_t size)
Decode a complete SENSOR02 record.
Definition sensor_capture.h:136
One camera's intent; acquired means pixels are owned, not yet durable.
Definition capture_arbiter.c:50
Definition capture_timing.h:41
FC pose and bounded local clock mapping, rather than a precise exposure claim.
Definition capture_arbiter.c:58
Measured pinhole calibration for the delivered image, including its mount.
Definition coverage_scheduler.h:41
One feasible observation; deadlines constrain acquisition start, not saving.
Definition coverage_scheduler.h:84
uint64_t ready_us
Earliest acquisition start; all candidates must share a monotonic time domain.
Definition coverage_scheduler.h:86
Convex ground quadrilateral with a conservative boundary margin.
Definition coverage_scheduler.h:79
Local ground coordinates in metres, east and north of the projection origin.
Definition coverage_scheduler.h:73
double north
Metres north of the shared local geographic reference.
Definition coverage_scheduler.h:73
Pose estimate and its positional margin for a single observation.
Definition coverage_scheduler.h:59
Fixed coverage ledger; zero cells are unknown, not necessarily unphotographed.
Definition coverage_scheduler.h:93
Borrowed bytes plus enough type information for safe interpretation.
Definition exifite.h:119
Definition sensor_capture.h:33
One measured camera calibration loaded from the flat PANGEA profile format.
Definition camera_profile.h:41
Definition usher_protocol.h:51
struct dc_shot_union::@351207206061007345226276304225222200157171312155 data
Best-effort USHER-to-FC terminal result for one camera and shot number.
Definition usher_protocol.h:368
FC-to-USHER spatial observation request, not a physical shutter acknowledgement.
Definition usher_protocol.h:358
FC-to-USHER survey authorization, independent of individual shot requests.
Definition usher_protocol.h:349
struct usher_capture_arbiter_state_union::@064116166145364176124043337373233207372124166232 data
Definition usher_protocol.h:261
int32_t velocity_north_bfp
Definition usher_protocol.h:267
struct usher_pose_sample_union::@042015206147200076364072004013147106310343341221 data
#define USHER_CAPTURE_ARBITER_SUPERSEDED
Definition usher_protocol.h:335
static bool usher_pose_flags_valid(uint32_t flags)
Check the structural consistency of pose-sample GPS flags.
Definition usher_protocol.h:250
#define USHER_POSE_SAMPLE_GPS_AGE_SHIFT
Definition usher_protocol.h:242