Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
capture_arbiter.c
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#define _POSIX_C_SOURCE 200809L
19/**
20 * @file capture_arbiter.c
21 * @brief Bounded camera-independent capture admission, coverage and timing evidence.
22 * @details The serial owner offers intentions; camera workers report acquired and
23 * published images. Public state access uses guard, and internal state helpers
24 * require that lock. No camera callback runs under it. File parsing happens before
25 * taking the lock so an invalid profile or sidecar cannot retain camera admission.
26 * An intention is not an image: only verified publication may credit coverage.
27 */
28#include "capture_arbiter.h"
29#include "boot_id.h"
30#include "camera_profile.h"
31#include "motion_compensation.h"
32
33#include <errno.h>
34#include <fcntl.h>
35#include <math.h>
36#include <pthread.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <sys/stat.h>
41#include <time.h>
42#include <unistd.h>
43
44#include "exifite.h"
45#include "sensor_capture.h"
46
47#define ARBITER_COUNT(array) (sizeof(array) / sizeof((array)[0]))
48
49/** @brief One camera's intent; acquired means pixels are owned, not yet durable. */
52 uint32_t mask;
53 uint64_t received_us;
55};
56
57/** @brief FC pose and bounded local clock mapping, rather than a precise exposure claim. */
65
66static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
67/* Keep the 3 MiB ledger in zero-initialized static storage, off worker stacks. */
69static struct coverage_state *covered;
72/* Fixed camera slices stop a fast sensor from evicting another sensor's pending view. */
75static unsigned capacity[COVERAGE_CAMERAS] = {1, 1, 1};
78static uint32_t session, scope_mask, saved_count;
79static uint64_t scope_us;
81static double latitude, longitude;
82static uint64_t service_us[COVERAGE_CAMERAS] = {1000000, 1000000, 1000000};
85static double minimum_overlap = 0.3;
86static const uint64_t scope_lifetime_us = 750000;
87static const uint64_t intent_lifetime_us = 2000000;
88static struct capture_pose poses[512];
89static size_t pose_head, pose_count;
90static uint32_t gps_week, gps_tow_ms;
91static uint64_t gps_changed_us;
92
93/**
94 * @brief Read the local clock used for capture deadlines and pose alignment.
95 * @return Monotonic microseconds, or zero when the clock read fails.
96 * @details Use the same time base for age and ordering checks so wall-clock
97 * corrections do not make old evidence appear fresh.
98 */
99static uint64_t monotonic_us(void)
100{
101 struct timespec now;
102 if (clock_gettime(CLOCK_MONOTONIC, &now)) return 0;
103 return (uint64_t)now.tv_sec * 1000000 + now.tv_nsec / 1000;
104}
105
106/**
107 * @brief Obtain a nonzero token for a new survey session.
108 * @param[out] token Destination; use only on success.
109 * @return True for a complete, nonzero token and successful descriptor close.
110 * @details Accumulate short reads and retry interruptions instead of accepting
111 * a partial token. Zero is reserved for inactive session state.
112 */
113static bool random_session(uint32_t *token)
114{
115 const int descriptor = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
116 if (descriptor < 0) return false;
117 size_t received = 0;
118 while (received < sizeof(*token)) {
119 const ssize_t count = read(descriptor, (unsigned char *)token + received, sizeof(*token) - received);
120 if (count < 0 && errno == EINTR) continue;
121 if (count <= 0) break;
122 received += (size_t)count;
123 }
124 const bool valid = close(descriptor) == 0 && received == sizeof(*token) && *token != 0;
125 return valid;
126}
127
128/** @brief Record a terminal outcome without allowing telemetry backlog to block camera release. */
129static void report(const struct capture_intent *intent, unsigned camera_id, uint32_t outcome)
130{
131 fprintf(stderr, "USHER SURVEY: session=%u shot=%d camera=%u result=%u saved=%u\n",
132 session, intent->shot.data.nr, camera_id, outcome, saved_count);
134 fprintf(stderr, "USHER SURVEY: result telemetry full; capture continues\n");
135 return;
136 }
139 result->data.session = session;
140 result->data.number = intent->shot.data.nr;
141 result->data.camera_id = camera_id;
142 result->data.result = outcome;
143 result->data.saved_count = saved_count;
144}
145
146/**
147 * @brief Retire an intention and record its terminal outcome.
148 * @param[in,out] intent Owned entry to clear.
149 * @param outcome Result code to report to each camera in the intent mask.
150 * @details Report per camera before clearing the slot. The caller holds the
151 * arbiter lock, and result queue overflow must not prevent retirement.
152 */
153static void expire(struct capture_intent *intent, uint32_t outcome)
154{
155 for (unsigned camera_id = 1; camera_id <= COVERAGE_CAMERAS; ++camera_id)
156 if (intent->mask & (1U << (camera_id - 1))) report(intent, camera_id, outcome);
157 *intent = (struct capture_intent) {0};
158}
159
160/**
161 * @brief Check whether the active survey scope is still current.
162 * @param now_us Current local monotonic time in microseconds.
163 * @return True for an active session with in-window scope evidence.
164 * @details Check ordering before subtracting unsigned times; a timestamp
165 * later than the query is not evidence that the scope is fresh.
166 */
167static bool fresh_scope(uint64_t now_us)
168{
169 return session && scope_active && now_us >= scope_us && now_us - scope_us <= scope_lifetime_us;
170}
171
172/** @brief Convert FC units and estimate geometric detail using this camera's calibration. */
173static bool project(const union dc_shot_union *shot, unsigned camera_id, double uncertainty,
174 struct coverage_candidate *candidate)
175{
176 if (!origin_set || camera_id < 1 || camera_id > COVERAGE_CAMERAS || !calibrated[camera_id - 1]) return false;
177 const struct coverage_pose pose = {
178 .latitude_deg = shot->data.lat / 1e7, .longitude_deg = shot->data.lon / 1e7,
179 .agl_m = shot->data.groundalt / 256.0,
180 .roll_deg = shot->data.phi * (57.29577951308232 / 4096.0),
181 .pitch_deg = shot->data.theta * (57.29577951308232 / 4096.0),
182 .yaw_deg = shot->data.psi * (57.29577951308232 / 4096.0), .uncertainty_m = uncertainty
183 };
184 *candidate = (struct coverage_candidate) {.camera_id = camera_id};
185 const struct coverage_camera *camera = &cameras[camera_id - 1];
186 if (!coverage_project(camera, &pose, latitude, longitude, &candidate->footprint)) return false;
187 double twice_area = 0;
188 for (size_t index = 0; index < 4; ++index) {
189 const struct coverage_point *first = &candidate->footprint.corner[index];
190 const struct coverage_point *second = &candidate->footprint.corner[(index + 1) % 4];
191 twice_area += first->east * second->north - first->north * second->east;
192 }
193 const double metres_per_pixel = sqrt(fabs(twice_area) / (2.0 * camera->width * camera->height));
194 if (!isfinite(metres_per_pixel) || metres_per_pixel <= 0) return false;
195 candidate->quality = (uint8_t)fmax(1.0, fmin(255.0, floor(1 / metres_per_pixel)));
196 return true;
197}
198
199/** @brief Take the short arc across heading wrap, using widened subtraction before conversion. */
200static double angle_delta(int32_t first, int32_t second)
201{
202 return remainder(((int64_t)second - first) / 4096.0, 6.283185307179586);
203}
204
205/** @brief Forecast a short continuation only when mapped motion is suitably well behaved. */
206static bool predict(uint64_t time_us, union dc_shot_union *shot, double *uncertainty)
207{
208 if (pose_count < 2) return false;
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)];
211 /* Do not extend an old straight segment through a turn or missing telemetry. */
212 if (time_us < latest->time_us || time_us - latest->time_us > 500000
213 || latest->time_us <= previous->time_us || latest->time_us - previous->time_us > 200000) return false;
214 const double elapsed = (time_us - latest->time_us) / 1e6;
215 const double sample_time = (latest->time_us - previous->time_us) / 1e6;
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;
219 if (fabs(roll_rate) > 0.15 || fabs(pitch_rate) > 0.15 || fabs(yaw_rate) > 0.25
220 || fabs(latest->shot.data.phi / 4096.0) > 0.6 || fabs(latest->shot.data.theta / 4096.0) > 0.6) return false;
221 *shot = latest->shot;
222 const double radians = 0.017453292519943295;
223 const double speed = shot->data.vground / 524288.0, course = shot->data.course / 4096.0;
224 const double predicted_latitude = shot->data.lat / 1e7 + speed * elapsed * cos(course) / 6378137 / radians;
225 const double predicted_longitude = shot->data.lon / 1e7
226 + speed * elapsed * sin(course) / (6378137 * cos(shot->data.lat / 1e7 * radians)) / radians;
227 if (fabs(predicted_latitude) > 85 || fabs(predicted_longitude) > 180) return false;
228 shot->data.lat = (int32_t)llround(predicted_latitude * 1e7);
229 shot->data.lon = (int32_t)llround(predicted_longitude * 1e7);
230 shot->data.phi += (int32_t)llround(roll_rate * elapsed * 4096);
231 shot->data.theta += (int32_t)llround(pitch_rate * elapsed * 4096);
232 shot->data.psi = (int32_t)llround(remainder(shot->data.psi / 4096.0 + yaw_rate * elapsed, 6.283185307179586) * 4096);
233 *uncertainty = latest->accuracy_m + speed * (latest->error_us / 1e6 + elapsed * 0.25)
234 + 5 * elapsed * elapsed + shot->data.groundalt / 256.0 * (0.02 + elapsed * 0.1);
235 return isfinite(*uncertainty) && *uncertainty <= 15;
236}
237
238bool capture_arbiter_load_camera(const char *filename)
239{
241 if (!usher_camera_profile_read(filename, &profile)) {
242 fprintf(stderr, "USHER SURVEY: camera profile rejected: invalid bounded flat profile\n");
243 return false;
244 }
245 if (profile.camera_id < 1 || profile.camera_id > COVERAGE_CAMERAS) {
246 fprintf(stderr, "USHER SURVEY: camera profile rejected: prefix must be c, a or l\n");
247 return false;
248 }
249 const struct coverage_camera *camera = &profile.calibration;
250 const struct coverage_pose pose = {.agl_m = 10};
251 struct coverage_footprint footprint;
252 if (!coverage_project(camera, &pose, 0, 0, &footprint)) {
253 fprintf(stderr, "USHER SURVEY: camera profile rejected: invalid calibration\n");
254 return false;
255 }
256
257 bool accepted = false;
258 const char *error = "coverage initialization";
259 pthread_mutex_lock(&guard);
260 if (!covered) {
261 /* 1024 cells * 4 m = 4096 m per side. Centre the ledger on the first trusted
262 * saved exposure (chosen later); -2048 is a metre offset, not image resolution. */
263 if (!coverage_init(&coverage_ledger, -2048, -2048, 4)) goto unlock;
264 uint32_t token = 0;
265 error = "session token";
266 if (!random_session(&token)) goto unlock;
268 session = token;
269 }
270 cameras[profile.camera_id - 1] = *camera;
271 calibrated[profile.camera_id - 1] = true;
272 accepted = true;
273unlock:
274 pthread_mutex_unlock(&guard);
275 if (!accepted) fprintf(stderr, "USHER SURVEY: camera profile rejected: %s\n", error);
276 return accepted;
277}
278
280{
281 pthread_mutex_lock(&guard);
283 pthread_mutex_unlock(&guard);
284}
285
286bool capture_arbiter_set_overlap(double overlap)
287{
288 if (!isfinite(overlap) || overlap < 0 || overlap > 0.9) return false;
289 pthread_mutex_lock(&guard);
290 minimum_overlap = overlap;
291 pthread_mutex_unlock(&guard);
292 return true;
293}
294
295bool capture_arbiter_set_camera_capacity(unsigned camera_id, unsigned limit)
296{
297 if (camera_id < 1 || camera_id > COVERAGE_CAMERAS || limit < 1 || limit > 2) return false;
298 pthread_mutex_lock(&guard);
299 capacity[camera_id - 1] = limit;
300 pthread_mutex_unlock(&guard);
301 return true;
302}
303
305{
306 pthread_mutex_lock(&guard);
307 const uint32_t token = session;
308 pthread_mutex_unlock(&guard);
309 return token;
310}
311
312void capture_arbiter_set_scope(const union usher_capture_arbiter_state_union *scope, uint64_t now_us)
313{
314 if (!scope || scope->data.active > 1 || scope->data.camera_mask > USHER_CAMERA_MASK_ALL) return;
315 pthread_mutex_lock(&guard);
316 if (!session || scope->data.session != session) goto done;
317 scope_active = scope->data.active != 0;
319 scope_us = now_us;
320 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index) {
321 struct capture_intent *intent = &waiting[index];
323 else {
324 struct capture_intent removed = *intent;
325 removed.mask &= ~scope_mask;
327 intent->mask &= scope_mask;
328 }
329 }
330done:
331 pthread_mutex_unlock(&guard);
332}
333
335{
336 if (!request || request->data.camera_mask > USHER_CAMERA_MASK_ALL) return false;
337 bool accepted = false;
338 pthread_mutex_lock(&guard);
339 if (!session || request->data.session != session) goto done;
340 accepted = true;
341 struct capture_intent offered = {.shot = request->data.shot, .mask = request->data.camera_mask & 7U, .received_us = now_us};
342 if (!offered.mask) goto done;
343 if (!fresh_scope(now_us)) {
345 goto done;
346 }
347 offered.mask &= scope_mask;
348 /* Do not create another exposure for a request still owned by that camera. */
349 for (size_t index = 0; index < ARBITER_COUNT(active); ++index)
350 if (active[index].mask && active[index].shot.data.nr == offered.shot.data.nr) offered.mask &= ~active[index].mask;
351 for (unsigned camera_index = 0; camera_index < COVERAGE_CAMERAS; ++camera_index) {
352 const uint32_t bit = 1U << camera_index;
353 if (!(offered.mask & bit)) continue;
354 const size_t begin = camera_index * COVERAGE_CANDIDATES;
355 size_t free_entry = ARBITER_COUNT(waiting), oldest = begin;
356 bool duplicate = false;
357 for (size_t index = begin; index < begin + COVERAGE_CANDIDATES; ++index) {
358 const struct capture_intent *intent = &waiting[index];
359 if (intent->mask && intent->shot.data.nr == offered.shot.data.nr) duplicate = true;
360 if (!intent->mask && free_entry == ARBITER_COUNT(waiting)) free_entry = index;
361 if (intent->received_us < waiting[oldest].received_us) oldest = index;
362 }
363 if (duplicate) continue;
364 const size_t destination = free_entry != ARBITER_COUNT(waiting) ? free_entry : oldest;
365 if (waiting[destination].mask) expire(&waiting[destination], USHER_CAPTURE_ARBITER_SUPERSEDED);
366 waiting[destination] = (struct capture_intent) {.shot = offered.shot, .mask = bit, .received_us = now_us};
367 }
368done:
369 pthread_mutex_unlock(&guard);
370 return accepted;
371}
372
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)
375{
376 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index) {
377 struct capture_intent *intent = &waiting[index];
378 if (intent->mask && (!fresh_scope(now_us) || now_us < intent->received_us
380 }
381 unsigned free_slots = 0;
382 for (size_t index = 0; index < ARBITER_COUNT(active); ++index) if (!active[index].mask) ++free_slots;
383 if (!free_slots) return false;
384 for (unsigned camera_id = 1; camera_id <= COVERAGE_CAMERAS; ++camera_id) {
385 unsigned in_flight = 0;
386 for (size_t index = 0; index < ARBITER_COUNT(active); ++index)
387 if (active[index].mask & (1U << (camera_id - 1))) ++in_flight;
388 if (in_flight >= capacity[camera_id - 1]) ready_mask &= ~(1U << (camera_id - 1));
389 }
390 /* An unavailable sensor must not head-of-line block another bit of the FC mask. */
391 size_t oldest = ARBITER_COUNT(waiting);
392 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index)
393 if ((waiting[index].mask & ready_mask) && (oldest == ARBITER_COUNT(waiting)
394 || waiting[index].received_us < waiting[oldest].received_us)) oldest = index;
395 if (oldest == ARBITER_COUNT(waiting)) return false;
396 struct capture_intent *intent = &waiting[oldest];
397 uint32_t selected = intent->mask & ready_mask;
398 for (unsigned camera_id = 1; camera_id <= COVERAGE_CAMERAS; ++camera_id) {
399 const uint32_t bit = 1U << (camera_id - 1);
400 if (!(selected & bit)) continue;
401 struct coverage_candidate candidate;
402 union dc_shot_union current;
403 double uncertainty = 0;
404 if (predict(now_us, &current, &uncertainty) && project(&current, camera_id, uncertainty, &candidate)) {
405 const double gain = coverage_gain(covered, &candidate);
406 struct coverage_candidate opportunities[COVERAGE_CANDIDATES] = {0};
407 size_t count = 0;
408 for (unsigned step = 0; step < ARBITER_COUNT(opportunities); ++step) {
409 const uint64_t planned = now_us + step * 75000;
410 union dc_shot_union prediction;
411 double error = 0;
412 struct coverage_candidate opportunity;
413 if (!predict(planned, &prediction, &error) || !project(&prediction, camera_id, error, &opportunity)) break;
414 opportunity.ready_us = planned;
415 opportunity.deadline_us = planned + 75000;
416 opportunities[count++] = opportunity;
417 }
418 const int choice = coverage_choose(covered, opportunities, count, now_us, service_us[camera_id - 1]);
419 fprintf(stderr, "USHER SURVEY: shot=%d camera=%u coverage_score_m2=%.1f mode=%s\n",
420 intent->shot.data.nr, camera_id, gain, enforce ? "enforce" : "observe");
421 if (choice > 0) fprintf(stderr, "USHER SURVEY: lookahead=%d defer_us=%llu\n", choice,
422 (unsigned long long)(opportunities[choice].ready_us - now_us));
423 /* Zero gain is not proof of redundancy: uncertainty-expanded coverage is. */
424 if (enforce && coverage_wholly_saved(covered, &candidate)) {
426 selected &= ~bit;
427 intent->mask &= ~bit;
428 } else if (enforce && choice > 0 && now_us - intent->received_us < 225000
429 && gain > 0 && gain < coverage_gain(covered, &opportunities[choice]) * 0.5
430 && have_saved[camera_id - 1]
431 && coverage_overlap(covered, &opportunities[choice], &last_saved[camera_id - 1]) >= minimum_overlap)
432 selected &= ~bit;
433 }
434 }
435 if (!selected) return false;
436 /* Forecasts guide selection; the returned request must retain its original pose. */
437 *shot = intent->shot;
438 *mask = (uint8_t)selected;
439 for (unsigned index = 0; index < COVERAGE_CAMERAS; ++index)
440 if (selected & (1U << index)) {
441 for (size_t slot = 0; slot < ARBITER_COUNT(active); ++slot) if (!active[slot].mask) {
442 active[slot] = (struct capture_intent) {.shot = intent->shot, .mask = 1U << index, .received_us = now_us};
443 break;
444 }
445 }
446 intent->mask &= ~selected;
447 return true;
448}
449
450bool capture_arbiter_take(uint32_t ready_mask, uint64_t now_us, union dc_shot_union *shot, uint8_t *mask)
451{
452 if (!shot || !mask) return false;
453 pthread_mutex_lock(&guard);
454 const bool taken = take_locked(ready_mask, now_us, shot, mask);
455 pthread_mutex_unlock(&guard);
456 return taken;
457}
458
459void capture_arbiter_complete(const union dc_shot_union *shot, unsigned camera_id, bool saved,
460 bool exposure_pose_valid, double uncertainty_m, uint64_t now_us)
461{
462 if (!shot || camera_id < 1 || camera_id > COVERAGE_CAMERAS) return;
463 pthread_mutex_lock(&guard);
464 struct capture_intent *intent = NULL;
465 for (size_t index = 0; index < ARBITER_COUNT(active); ++index)
466 if (active[index].mask == (1U << (camera_id - 1)) && active[index].shot.data.nr == shot->data.nr) {
467 intent = &active[index];
468 break;
469 }
470 if (!intent) goto done;
471 /* Do not overwrite split-phase acquisition timing with later disk/EXIF latency. */
472 if (!intent->acquired && now_us >= intent->received_us && now_us - intent->received_us >= 10000
473 && now_us - intent->received_us <= 30000000) {
474 const uint64_t measured = now_us - intent->received_us;
475 const uint64_t averaged = (3 * service_us[camera_id - 1] + measured) / 4;
476 service_us[camera_id - 1] = averaged > 10000 ? averaged : 10000;
477 }
478 if (saved) {
479 ++saved_count;
480 /* File success and trusted ground coverage are separate facts. */
481 if (exposure_pose_valid && isfinite(uncertainty_m) && uncertainty_m >= 0 && now_us >= intent->received_us) {
482 if (!origin_set) {
483 /* Anchor once: moving it would silently assign saved cells to different ground. */
484 latitude = shot->data.lat / 1e7;
485 longitude = shot->data.lon / 1e7;
486 origin_set = true;
487 }
488 struct coverage_candidate candidate;
489 if (project(shot, camera_id, uncertainty_m, &candidate) && coverage_commit(covered, &candidate)) {
490 last_saved[camera_id - 1] = candidate;
491 have_saved[camera_id - 1] = true;
492 }
493 }
494 }
496 *intent = (struct capture_intent) {0};
497done:
498 pthread_mutex_unlock(&guard);
499}
500
502{
503 if (!result) return false;
504 pthread_mutex_lock(&guard);
505 const bool available = result_count != 0;
506 if (available) {
508 result->data.ready_mask = ready_mask & 7U;
510 --result_count;
511 }
512 pthread_mutex_unlock(&guard);
513 return available;
514}
515
517{
518 pthread_mutex_lock(&guard);
519 bool pending = false;
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;
522 pthread_mutex_unlock(&guard);
523 return pending;
524}
525
526bool capture_arbiter_owns(int32_t number)
527{
528 pthread_mutex_lock(&guard);
529 bool owns = false;
530 for (size_t index = 0; index < ARBITER_COUNT(active); ++index)
531 if (active[index].mask && active[index].shot.data.nr == number) owns = true;
532 pthread_mutex_unlock(&guard);
533 return owns;
534}
535
536void capture_arbiter_acquired(int32_t number, unsigned camera_id, uint64_t now_us)
537{
538 if (camera_id < 1 || camera_id > COVERAGE_CAMERAS) return;
539 pthread_mutex_lock(&guard);
540 for (size_t index = 0; index < ARBITER_COUNT(active); ++index) {
541 struct capture_intent *intent = &active[index];
542 if (intent->mask != (1U << (camera_id - 1)) || intent->shot.data.nr != number) continue;
543 if (now_us >= intent->received_us && now_us - intent->received_us <= 5000000) {
544 const uint64_t elapsed = now_us - intent->received_us;
545 if (!intent->acquired) service_us[camera_id - 1] = elapsed > 10000 ? elapsed : 10000;
546 intent->acquired = true;
547 }
548 break;
549 }
550 pthread_mutex_unlock(&guard);
551}
552
554{
555 pthread_mutex_lock(&guard);
556 scope_active = false;
557 /* Withdraw future intent, not pixels already acquired and still owed publication. */
558 for (size_t index = 0; index < ARBITER_COUNT(waiting); ++index) expire(&waiting[index], USHER_CAPTURE_ARBITER_EXPIRED);
559 pthread_mutex_unlock(&guard);
560}
561
563{
564 pthread_mutex_lock(&guard);
565 pose_count = 0;
566 pose_head = 0;
567 gps_changed_us = 0;
568 pthread_mutex_unlock(&guard);
569}
570
571void capture_arbiter_pose_sample(const union usher_pose_sample_union *sample, uint64_t earliest_us, uint64_t latest_us)
572{
573 pthread_mutex_lock(&guard);
574 if (!sample || !earliest_us || latest_us < earliest_us || latest_us - earliest_us > 100000
576 || (uint32_t)(sample->data.sample_end_us - sample->data.sample_begin_us) > 10000
577 || !(sample->data.flags & USHER_POSE_SAMPLE_GPS_PRESENT) || sample->data.gps_fix < 3
578 || !sample->data.gps_hacc_cm || sample->data.gps_hacc_cm > 1000
579 || sample->data.gps_tow_ms >= 604800000U
580 || llabs((long long)sample->data.shot.data.lat) > 850000000
581 || llabs((long long)sample->data.shot.data.lon) > 1800000000
582 || sample->data.shot.data.groundalt <= 0 || sample->data.shot.data.groundalt > 10000 * 256
583 || sample->data.shot.data.vground < 0 || sample->data.shot.data.vground > 100 * 524288) {
584 pose_count = 0;
585 goto done;
586 }
587 const uint64_t middle = earliest_us + (latest_us - earliest_us) / 2;
588 /* The midpoint is useful for interpolation only when its uncertainty travels with it. */
589 if (pose_count && middle <= poses[(pose_head + pose_count - 1) % ARBITER_COUNT(poses)].time_us) goto done;
590 if (sample->data.gps_week || sample->data.gps_tow_ms) {
591 if (!gps_changed_us || gps_week != sample->data.gps_week || gps_tow_ms != sample->data.gps_tow_ms) {
592 if (gps_changed_us && (sample->data.gps_week < gps_week
593 || (sample->data.gps_week == gps_week && sample->data.gps_tow_ms < gps_tow_ms))) pose_count = 0;
594 gps_week = sample->data.gps_week;
595 gps_tow_ms = sample->data.gps_tow_ms;
596 gps_changed_us = middle;
597 } else if (middle < gps_changed_us || middle - gps_changed_us >= 2000000) {
598 pose_count = 0;
599 goto done;
600 }
601 }
602 union dc_shot_union aligned = sample->data.shot;
603 double accuracy_m = fmax(3.0, sample->data.gps_hacc_cm / 100.0);
604 const bool projected = (sample->data.flags & USHER_POSE_SAMPLE_GPS_HELD) != 0;
605 const uint32_t age_ms = sample->data.flags >> USHER_POSE_SAMPLE_GPS_AGE_SHIFT;
606 if (projected) {
607 const double north = sample->data.velocity_north_bfp / 524288.0;
608 const double east = sample->data.velocity_east_bfp / 524288.0;
609 const double speed = hypot(north, east), age_s = age_ms / 1000.0;
610 if (age_ms > 500 || !(sample->data.gps_valid_fields & ((1U << 3) | (1U << 4)))
611 || speed > 100 || sample->data.gps_sacc_cm_s > 1000
612 || !compensate_ground_position(&aligned.data.lat, &aligned.data.lon, speed, atan2(east, north), age_s)) {
613 pose_count = 0;
614 goto done;
615 }
616 accuracy_m += fmax(1.0, sample->data.gps_sacc_cm_s / 100.0) * age_s + 5.0 * age_s * age_s;
617 }
620 --pose_count;
621 }
623 .shot = aligned, .time_us = middle, .error_us = (latest_us - earliest_us + 1) / 2,
624 .accuracy_m = accuracy_m, .navigation_age_ms = projected ? age_ms : 0, .navigation_projected = projected
625 };
626done:
627 pthread_mutex_unlock(&guard);
628}
629
630/**
631 * @brief Interpolate a scalar fixed-point pose field.
632 * @param first Value at the earlier sample.
633 * @param second Value at the later sample.
634 * @param fraction Position between the endpoints, from zero to one.
635 * @return Nearest representable value in the original fixed-point units.
636 * @details Widen before subtracting to accommodate opposite signed endpoints.
637 * Use wrapped angular deltas instead for headings and attitude.
638 */
639static int32_t interpolate(int32_t first, int32_t second, double fraction)
640{
641 return (int32_t)llround(first + fraction * ((int64_t)second - first));
642}
643
644/**
645 * @brief Interpolate a qualified pose from bounded sample history.
646 * @param time_us Query time in local monotonic microseconds.
647 * @param time_error_us Timing uncertainty around the query, in microseconds.
648 * @param[out] shot Interpolated pose; use only on success.
649 * @param[out] uncertainty_m Estimated position uncertainty in metres; use only on success.
650 * @param[in,out] observation Optional destination for navigation provenance on success.
651 * @return True if the query is bracketed and passes motion and uncertainty checks.
652 * @details Do not extrapolate beyond recorded pose samples. Reject discontinuous
653 * or widely spaced pairs before interpolating scalars and wrapped angles.
654 * Combine timing, navigation accuracy, and attitude change as a conservative
655 * operational check, not a surveyed accuracy guarantee.
656 */
657static bool pose_at(uint64_t time_us, uint64_t time_error_us, union dc_shot_union *shot,
658 double *uncertainty_m, struct capture_observation *observation)
659{
660 if (!shot || !uncertainty_m || time_error_us > 100000) return false;
661 bool valid = false;
662 pthread_mutex_lock(&guard);
663 for (size_t index = 1; index < pose_count; ++index) {
664 const struct capture_pose *before = &poses[(pose_head + index - 1) % ARBITER_COUNT(poses)];
665 const struct capture_pose *after = &poses[(pose_head + index) % ARBITER_COUNT(poses)];
666 if (time_us < before->time_us || time_us > after->time_us) continue;
667 const uint64_t span = after->time_us - before->time_us;
668 if (!span || span > 200000) break;
669 const double fraction = (double)(time_us - before->time_us) / span;
670 const double roll_change = angle_delta(before->shot.data.phi, after->shot.data.phi);
671 const double pitch_change = angle_delta(before->shot.data.theta, after->shot.data.theta);
672 if (fabs(roll_change) > 0.1 || fabs(pitch_change) > 0.1
673 || fabs(before->shot.data.phi / 4096.0) > 0.6 || fabs(after->shot.data.phi / 4096.0) > 0.6
674 || fabs(before->shot.data.theta / 4096.0) > 0.6 || fabs(after->shot.data.theta / 4096.0) > 0.6
675 || llabs((long long)after->shot.data.lat - before->shot.data.lat) > 10000
676 || llabs((long long)after->shot.data.lon - before->shot.data.lon) > 10000) break;
677 *shot = before->shot;
678 shot->data.lat = interpolate(before->shot.data.lat, after->shot.data.lat, fraction);
679 shot->data.lon = interpolate(before->shot.data.lon, after->shot.data.lon, fraction);
680 shot->data.alt = interpolate(before->shot.data.alt, after->shot.data.alt, fraction);
681 shot->data.groundalt = interpolate(before->shot.data.groundalt, after->shot.data.groundalt, fraction);
682 shot->data.phi = (int32_t)llround(before->shot.data.phi + fraction * roll_change * 4096);
683 shot->data.theta = (int32_t)llround(before->shot.data.theta + fraction * pitch_change * 4096);
684 shot->data.psi = (int32_t)llround(before->shot.data.psi
685 + fraction * angle_delta(before->shot.data.psi, after->shot.data.psi) * 4096);
686 shot->data.course = (int32_t)llround(before->shot.data.course
687 + fraction * angle_delta(before->shot.data.course, after->shot.data.course) * 4096);
688 shot->data.vground = interpolate(before->shot.data.vground, after->shot.data.vground, fraction);
689 const double speed = fmax(before->shot.data.vground, after->shot.data.vground) / 524288.0;
690 /* Clock width, sample spacing and attitude change are an engineering error
691 * margin, not a statistical covariance or a guarantee of surveyed accuracy. */
692 *uncertainty_m = fmax(before->accuracy_m, after->accuracy_m)
693 + speed * (time_error_us + before->error_us + after->error_us + span / 2) / 1e6
694 + shot->data.groundalt / 256.0 * tan(hypot(roll_change, pitch_change));
695 valid = isfinite(*uncertainty_m) && *uncertainty_m <= 15;
696 if (valid && observation) {
697 observation->navigation_projected = before->navigation_projected || after->navigation_projected;
698 observation->navigation_age_ms = before->navigation_age_ms > after->navigation_age_ms
699 ? before->navigation_age_ms : after->navigation_age_ms;
700 }
701 break;
702 }
703 pthread_mutex_unlock(&guard);
704 return valid;
705}
706
707bool capture_arbiter_pose_at(uint64_t time_us, uint64_t time_error_us, union dc_shot_union *shot, double *uncertainty_m)
708{
709 return pose_at(time_us, time_error_us, shot, uncertainty_m, NULL);
710}
711
712bool capture_arbiter_observation_pose(struct capture_observation *observation, uint64_t wait_us)
713{
714 if (!observation) return false;
715 observation->pose_valid = false;
716 if (!capture_observation_valid(observation) || wait_us > 200000) return false;
717 const uint64_t span = observation->latest_us - observation->earliest_us;
718 if (span > 200000) return false;
719 const uint64_t time = observation->earliest_us + span / 2;
720 const uint64_t started = monotonic_us();
721 if (!started || time > started || started - time > 30000000) return false;
722 for (;;) {
723 if (pose_at(time, (span + 1) / 2, &observation->pose, &observation->pose_uncertainty_m, observation)) {
724 observation->pose_valid = true;
725 return true;
726 }
727 const uint64_t now = monotonic_us();
728 if (!now || now < started || now - started >= wait_us) return false;
729 pthread_mutex_lock(&guard);
730 const bool following_sample_missing = !pose_count
731 || poses[(pose_head + pose_count - 1) % ARBITER_COUNT(poses)].time_us < time;
732 pthread_mutex_unlock(&guard);
733 if (!following_sample_missing) return false;
734 const struct timespec delay = {.tv_nsec = 5000000};
735 if (nanosleep(&delay, NULL) && errno != EINTR) return false;
736 }
737}
738
739bool capture_arbiter_frame_timing(const char *filename, unsigned camera_id, struct capture_observation *observation)
740{
741 if (!filename || !observation || camera_id < 1 || camera_id > COVERAGE_CAMERAS) return false;
742 *observation = (struct capture_observation) {0};
743 struct stat before, after, path;
744 if (lstat(filename, &path) || !S_ISREG(path.st_mode)) return false;
745 const int descriptor = open(filename, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
746 if (descriptor < 0) return false;
747 FILE *input = fdopen(descriptor, "rb");
748 if (!input) { close(descriptor); return false; }
749 unsigned char payload[EXIF_MAX_PAYLOAD];
750 size_t size = 0;
751 struct exif_view view;
752 struct exif_value value;
753 struct sensor_capture record;
754 uint32_t width, height;
755 unsigned components;
756 bool valid = false;
757 if (fstat(descriptor, &before) || !S_ISREG(before.st_mode) || before.st_size <= 0
758 || before.st_dev != path.st_dev || before.st_ino != path.st_ino
759 || exif_read_stream(input, payload, sizeof(payload), &size)
760 || exif_parse(&view, payload, size)
761 || !exif_get(&view, EXIF_CAMERA, SENSOR_CAPTURE_TAG, &value)
762 || value.format != EXIF_UNDEFINED || !sensor_capture_decode(&record, value.data, value.size)
763 || fseek(input, 0, SEEK_SET)
764 || exif_jpeg_dimensions(input, &width, &height, &components)
765 || width != record.width || height != record.height
766 || fstat(descriptor, &after) || lstat(filename, &path)
767 || after.st_size != before.st_size || after.st_mtim.tv_sec != before.st_mtim.tv_sec
768 || after.st_mtim.tv_nsec != before.st_mtim.tv_nsec
769 || path.st_dev != before.st_dev || path.st_ino != before.st_ino) goto done;
770 char boot[37];
771 usher_boot_id(boot);
772 if (strcmp(record.boot_id, boot)) goto done;
773 pthread_mutex_lock(&guard);
774 const bool calibrated_frame = !calibrated[camera_id - 1]
775 || (width == cameras[camera_id - 1].width && height == cameras[camera_id - 1].height);
776 pthread_mutex_unlock(&guard);
777 if (!calibrated_frame) goto done;
778 const uint64_t time = record.monotonic_us, error = record.time_error_us;
779 const uint64_t now = monotonic_us();
780 *observation = (struct capture_observation) {
781 .sequence = record.sequence, .sensor_timestamp_ns = record.sensor_timestamp_ns, .frame_bound = true
782 };
783 valid = true;
784 if (!time || time <= error || time > now || now - time > 30000000
785 || error > 100000 || time > UINT64_MAX - error) goto done;
786 observation->earliest_us = time - error;
787 observation->latest_us = time + error;
788 observation->kind = CAPTURE_TIME_SENSOR_EXPOSURE;
789done:
790 if (fclose(input)) valid = false;
791 if (!valid) *observation = (struct capture_observation) {0};
792 return valid;
793}
794
795bool capture_arbiter_frame_pose(const char *filename, unsigned camera_id, const union dc_shot_union *request,
796 union dc_shot_union *exposure, double *uncertainty_m)
797{
798 struct capture_observation observation = {0};
799 if (!request || !exposure || !uncertainty_m
800 || !capture_arbiter_frame_timing(filename, camera_id, &observation)
801 || !capture_arbiter_observation_pose(&observation, 0)) return false;
802 *exposure = observation.pose;
803 exposure->data.nr = request->data.nr;
804 *uncertainty_m = observation.pose_uncertainty_m;
805 return true;
806}
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.
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.
static size_t result_head
bool capture_arbiter_set_overlap(double overlap)
Set the overlap floor for deliberate predictive delay, not FC shot spacing.
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.
static double angle_delta(int32_t first, int32_t second)
Take the short arc across heading wrap, using widened subtraction before conversion.
void capture_arbiter_pose_invalidate(void)
Forget pose history when synchronization is lost; keep saved coverage.
void capture_arbiter_set_enforce(bool enabled)
Enable coverage-based suppression and limited delay, or observe decisions only.
static void expire(struct capture_intent *intent, uint32_t outcome)
Retire an intention and record its terminal outcome.
bool capture_arbiter_pending(void)
Check whether waiting or active survey work remains.
static struct capture_intent active[2 *COVERAGE_CAMERAS]
static bool fresh_scope(uint64_t now_us)
Check whether the active survey scope is still current.
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.
static struct coverage_state * covered
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.
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.
static double minimum_overlap
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.
static bool have_saved[COVERAGE_CAMERAS]
static pthread_mutex_t guard
bool capture_arbiter_owns(int32_t number)
Identify a shot whose active survey ownership must not be superseded.
static const uint64_t scope_lifetime_us
static uint64_t scope_us
static uint64_t service_us[COVERAGE_CAMERAS]
static struct coverage_candidate last_saved[COVERAGE_CAMERAS]
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.
static unsigned capacity[COVERAGE_CAMERAS]
static bool origin_set
static size_t pose_count
uint32_t capture_arbiter_session_id(void)
Return the peer-session token, or zero when survey mode is not configured.
static double latitude
static union usher_capture_arbiter_result_union results[64]
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.
static uint32_t gps_week
bool capture_arbiter_set_camera_capacity(unsigned camera_id, unsigned limit)
Set admission from a backend's actual capacity, independent of camera ID.
#define ARBITER_COUNT(array)
bool capture_arbiter_result(union usher_capture_arbiter_result_union *result, uint32_t ready_mask)
Pop a bounded best-effort result for UART transmission.
void capture_arbiter_acquired(int32_t number, unsigned camera_id, uint64_t now_us)
Learn acquisition latency separately from slower JPEG publication.
static uint32_t scope_mask
static struct capture_pose poses[512]
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.
static struct coverage_camera cameras[COVERAGE_CAMERAS]
static uint32_t session
static size_t pose_head
static const uint64_t intent_lifetime_us
static size_t result_count
static bool enforce
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.
static struct capture_intent waiting[COVERAGE_CANDIDATES *COVERAGE_CAMERAS]
bool capture_arbiter_load_camera(const char *filename)
Load one camera's measured profile without guessing geometry from its ID.
static uint64_t monotonic_us(void)
Read the local clock used for capture deadlines and pose alignment.
static uint32_t saved_count
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.
static double longitude
static struct coverage_state coverage_ledger
static bool scope_active
void capture_arbiter_stop(void)
Cancel waiting intentions, retaining active-image ownership and saved coverage.
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.
static bool calibrated[COVERAGE_CAMERAS]
static uint32_t gps_tow_ms
static bool random_session(uint32_t *token)
Obtain a nonzero token for a new survey session.
static int32_t interpolate(int32_t first, int32_t second, double fraction)
Interpolate a scalar fixed-point pose field.
static uint64_t gps_changed_us
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.
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.
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.
@ CAPTURE_TIME_SENSOR_EXPOSURE
size_t size
Definition chdk_pipe.c:143
int descriptor
Definition chdk_pipe.c:142
void(* close)(struct usbfs_handle *)
Definition chdkbridge.c:57
int(* open)(const struct usbfs_device *, struct usbfs_handle *)
Definition chdkbridge.c:56
double coverage_gain(const struct coverage_state *state, const struct coverage_candidate *candidate)
Score additional detail in conservatively contained cells without mutation.
bool coverage_commit(struct coverage_state *state, const struct coverage_candidate *candidate)
Credit a successfully saved observation, retaining the best detail per cell.
bool coverage_init(struct coverage_state *state, double east, double north, double cell_m)
Clear the ledger and set its fixed spatial domain.
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.
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.
bool coverage_wholly_saved(const struct coverage_state *state, const struct coverage_candidate *candidate)
Check whether skipping this observation is geometrically conservative.
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.
#define COVERAGE_CAMERAS
#define COVERAGE_CANDIDATES
static int record(const union dc_shot_union *shot)
Retrieve a point and admit a new observation only when its credit is free.
static bool enabled(void)
Report explicit opt-in independently of process or model readiness.
union dc_shot_union request
static struct latest_measurement latest
static bool pending
static bool started
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
@ EXIF_UNDEFINED
Definition exifite.h:70
@ EXIF_CAMERA
Definition exifite.h:59
struct jpeg_error_mgr error
Definition lwir_image.c:60
static struct usher_camera_profile profile
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.
static pthread_cond_t available
Definition pose_log.c:73
static size_t count
Definition pose_log.c:79
static uint64_t accepted
Definition pose_log.c:81
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.
#define SENSOR_CAPTURE_TAG
One camera's intent; acquired means pixels are owned, not yet durable.
union dc_shot_union shot
enum capture_time_kind kind
union dc_shot_union pose
FC pose and bounded local clock mapping, rather than a precise exposure claim.
union dc_shot_union shot
uint32_t navigation_age_ms
bool navigation_projected
uint64_t error_us
Measured pinhole calibration for the delivered image, including its mount.
One feasible observation; deadlines constrain acquisition start, not saving.
struct coverage_footprint footprint
uint64_t ready_us
Earliest acquisition start; all candidates must share a monotonic time domain.
Convex ground quadrilateral with a conservative boundary margin.
struct coverage_point corner[4]
Local ground coordinates in metres, east and north of the projection origin.
double north
Metres north of the shared local geographic reference.
double east
Metres east of the shared local geographic reference.
Pose estimate and its positional margin for a single observation.
double pitch_deg
Aircraft pitch in degrees.
Fixed coverage ledger; zero cells are unknown, not necessarily unphotographed.
Borrowed bytes plus enough type information for safe interpretation.
Definition exifite.h:119
const unsigned char * data
Definition exifite.h:120
size_t size
Definition exifite.h:121
uint16_t format
Definition exifite.h:123
Borrowed view of a validated APP1 payload.
Definition exifite.h:131
One measured camera calibration loaded from the flat PANGEA profile format.
struct dc_shot_union::@351207206061007345226276304225222200157171312155 data
Best-effort USHER-to-FC terminal result for one camera and shot number.
FC-to-USHER spatial observation request, not a physical shutter acknowledgement.
FC-to-USHER survey authorization, independent of individual shot requests.
struct usher_capture_arbiter_state_union::@064116166145364176124043337373233207372124166232 data
union dc_shot_union shot
struct usher_pose_sample_union::@042015206147200076364072004013147106310343341221 data
static struct camera_backend camera
Definition usher.c:521
bool valid
Definition usher.c:537
struct usher_control_result result
Definition usher.c:377
uint64_t received_us
Definition usher.c:536
union dc_shot_union shot
Definition usher.c:534
#define USHER_CAPTURE_ARBITER_EXPIRED
#define USHER_CAPTURE_ARBITER_COVERED
#define USHER_POSE_SAMPLE_GPS_HELD
#define USHER_POSE_SAMPLE_GPS_PRESENT
#define USHER_CAPTURE_ARBITER_SUPERSEDED
#define USHER_CAMERA_MASK_LWIR
#define USHER_CAMERA_MASK_AICAM
static bool usher_pose_flags_valid(uint32_t flags)
Check the structural consistency of pose-sample GPS flags.
#define USHER_CAPTURE_ARBITER_SAVED
#define USHER_POSE_SAMPLE_GPS_AGE_SHIFT
#define USHER_CAMERA_MASK_ALL
#define USHER_CAPTURE_ARBITER_FAILED
#define USHER_CAMERA_MASK_CHDK