Loading...
Searching...
No Matches
loomcam.c
Go to the documentation of this file.
84 if (index && description->data[index - 1] != ' ' && description->data[index - 1] != ';') continue;
110static bool description_field(const struct exif_value *description, const char *key, char value[64])
122static bool description_number(const struct exif_value *description, const char *key, double *number)
208 if (!inference_context_open(&context, settings, "loom_features_v1", error, sizeof(error))) return false;
213 if (tensor->type != ONNX_FLOAT32 || tensor->bytes / sizeof(float) > 4096 - values) valid_shape = false;
222 *record_size = loom_onnx_features_pack(record, capacity, &context.model, sequence, timestamp_ns);
240static bool match_previous_photos(const struct loom_frame *frame, struct camera_point_result *point)
245 if (!return_settings(frame->settings, &settings, &options) || options.frame == LOOM_RETURN_NONE) return false;
252 if (exif_read_jpeg(frame->image, payload, sizeof(payload), &size) || exif_parse(&view, payload, size) ||
258 if (!description_lookup(&description, "observation_pose_aligned=", aligned_value, &aligned_found)) return false;
259 if (aligned_found && strcmp(aligned_value, "true") && strcmp(aligned_value, "false")) return false;
265 if (!description_number(&description, "observation_lat_deg=", &latitude) || fabs(latitude) > 85 ||
266 !description_number(&description, "observation_lon_deg=", &longitude) || fabs(longitude) > 180 ||
267 !description_number(&description, "observation_alt_m=", &altitude) || fabs(altitude) > 2000000 ||
295 if (!description_field(&description, "observation_sequence=", identity) || !ini_uint(identity, &observed_sequence) ||
296 !description_field(&description, "sensor_timestamp_ns=", identity) || !ini_uint(identity, &observed_time))
300 } else if (!description_field(&description, "nr=", identity) || !ini_uint(identity, &shot_number) ||
330 !loom_features_unpack(record.data, record.size, features, 4096, information, sizeof(information),
343 const bool use_home_position = (aligned || options.frame == LOOM_RETURN_SIMULATED) && home_configured;
363 const double target_longitude = remainder(origin_longitude + target.east / (earth * scale) / radians, 360);
404 if (!inference_settings_find("loomcam", "loom_cam", discovered, sizeof(discovered))) return true;
407 if (inference_settings_read(settings, path, loom_return_setting, options, error, sizeof(error))) {
432 fprintf(stderr, "loomcam: strict return requires an ONNX model and a declared return_vector_frame\n");
486 else if (!strcmp(argv[index], "--seed") && ++index < argc && parse_sequence(argv[index], &seed)) {}
599 if (strcmp(argv[index], "--self-test") == 0 && argc == LOOM_SINGLE_OPTION_ARGC) return self_test();
static bool ini_uint(const char *text, uint64_t *number)
Parse digits-only uint64; overflow and signs are rejected.
Definition bounded_ini.h:52
static bool ini_real(const char *text, double *number)
Parse finite decimal/exponent notation, rejecting range errors and suffixes.
Definition bounded_ini.h:67
static bool ini_read_file(const char *filename, char *buffer, size_t capacity, size_t *length)
Read a nonempty regular file smaller than capacity and append NUL.
Definition bounded_ini.h:98
Shared capability and lifecycle contract for USHER camera backends.
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
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
int exif_read_jpeg(const char *filename, unsigned char *payload, size_t capacity, size_t *size)
Read the single EXIF APP1 segment before the first JPEG scan.
Definition exifite.c:1022
#define EXIF_MAX_PAYLOAD
APP1 payload ceiling: the JPEG length includes its own two bytes.
Definition exifite.h:51
Shared IMX500 tensor-info wire layout and bounded decoding policy.
#define IMX500_TENSOR_INFO_BYTES
Full accessible metadata required before following record offsets.
Definition imx500_tensor.h:49
bool inference_jpeg_prepare(struct inference_context *context, const char *filename, char *error, size_t capacity)
Stream a JPEG into an open context's single declared image input.
Definition inference_jpeg.c:167
Bounded JPEG-to-tensor preparation without running the graph or modifying the input file.
bool inference_context_run(struct inference_context *context, char *error, size_t capacity)
Run the currently prepared tensors using the context's timeout policy.
Definition inference_model.c:346
bool inference_context_open(struct inference_context *context, const struct inference_settings *settings, const char *adapter, char *error, size_t capacity)
Verify a bundle, map bounded tensors and bind one warm session.
Definition inference_model.c:277
void inference_context_close(struct inference_context *context)
Release the session before unmapping its borrowed tensor storage.
Definition inference_model.c:373
bool inference_model_parse(struct inference_model *model, char *contents, size_t length, char *error, size_t capacity)
Parse a descriptor, not graph bytes; graph integrity remains a separate read-time check.
Definition inference_model.c:189
Integrity-checked model contracts and independently owned tensor workspaces.
bool inference_settings_find(const char *application, const char *module, char *filename, size_t capacity)
Discover application_settings.ini in adjacent, development-module, then installed-share order.
Definition inference_settings.c:202
bool inference_settings_read(struct inference_settings *settings, const char *filename, ini_field_handler extra, void *context, char *error, size_t capacity)
Parse one flat INI, delegate application keys and resolve paths against the selected file.
Definition inference_settings.c:158
void inference_settings_init(struct inference_settings *settings, enum inference_backend backend)
Reset storage and select conservative thread/timeout defaults.
Definition inference_settings.c:28
Shared application_settings.ini discovery with module-owned extra keys.
int loomcam_photo_main(int argc, char **argv)
Dispatch the saved-photo CLI through its C linkage boundary.
bool loom_features_unpack(const unsigned char *record, size_t size, float *values, size_t capacity, uint8_t *information, size_t information_size, size_t *count, uint64_t *sequence, uint64_t *sensor_timestamp_ns)
Validate and decode an exact-sized binary record into bounded output.
Definition loom_features.c:136
LOOM-owned bounded feature validation and evidence serialization.
#define LOOM_FEATURES_TAG
LOOM-owned camera-directory tag; its value is a LOOMNN02 opaque record.
Definition loom_features.h:30
bool loom_onnx_features_valid(const unsigned char *record, size_t size, const char *model_sha256, const char *descriptor_sha256)
Validate the exact binary layout and optionally require the same trained feature space.
Definition loom_onnx_features.c:102
size_t loom_onnx_features_pack(unsigned char *record, size_t capacity, const struct inference_model *model, uint64_t sequence, uint64_t sensor_timestamp_ns)
Encode a complete LOOMOX01 record without fabricating an IMX500 metadata header.
Definition loom_onnx_features.c:39
bool loom_onnx_return_vector(const unsigned char *record, size_t size, const char *model_sha256, const char *descriptor_sha256, float values[3])
Decode an explicitly declared two/three-value return-vector record.
Definition loom_onnx_features.c:142
void loom_return_options_init(struct loom_return_options *options)
Initialize return limits with feature-only semantics by default.
Definition loom_return.c:40
bool loom_return_options_valid(const struct loom_return_options *options)
Check that optional destination coordinates are either both present or both omitted.
Definition loom_return.c:47
bool loom_return_vector_attitude(enum loom_return_frame frame, double first, double second, double roll_deg, double pitch_deg, double yaw_deg, double max_tilt_deg, struct loom_return_point *direction)
Convert a declared two-component vector to earth-frame east/north with attitude gating.
Definition loom_return.c:86
bool loom_return_update(struct loom_return_state *state, const struct loom_return_config *config, uint32_t sequence, struct loom_return_point candidate, struct loom_return_point *target)
Admit a fresh bounded target and limit its movement.
Definition loom_return.c:171
bool loom_return_setting(void *context, const char *key, const char *value)
Parse one LOOM-owned settings field, rejecting duplicates and unknown keys.
Definition loom_return.c:55
bool loom_return_simulate(struct loom_return_state *state, const struct loom_return_config *config, uint32_t sequence, struct loom_return_point *target)
Produce small mean-reverting target fluctuations for explicit PC simulation.
Definition loom_return.c:191
bool loom_return_direction(const struct loom_return_config *config, struct loom_return_point position, struct loom_return_point direction, double confidence, struct loom_return_point *target)
Convert an earth-frame direction into a HOME-bounded target.
Definition loom_return.c:138
Bounded direction-to-target policy, independent of inference and FC transport.
static int simulation_mode(int argc, char **argv)
Describe whether PC imagery can run a selected ONNX graph.
Definition loomcam.c:417
static bool description_number(const struct exif_value *description, const char *key, double *number)
Read a required finite numeric metadata field.
Definition loomcam.c:122
#define LOOM_SELF_TEST_SEQUENCE
Nonzero fixtures deliberately expose failure to clear previous state.
Definition loomcam.c:51
static int return_line(char *line, size_t capacity, unsigned timeout_ms)
Split one bounded ASCII command, rejecting binary/trailing/oversized input.
Definition loomcam.c:452
int main(int argc, char **argv)
Parse one saved-photo request and emit exactly one correlated result line.
Definition loomcam.c:592
#define LOOM_SELF_TEST_SEQUENCE_OVERFLOW
First integer outside the accepted uint32_t correlation range.
Definition loomcam.c:55
static bool match_previous_photos(const struct loom_frame *frame, struct camera_point_result *point)
Interpret retained same-photo neural vectors under the declared return contract.
Definition loomcam.c:240
static bool run_onnx_in_memory(const struct inference_settings *settings, const struct loom_return_options *options, const char *image, uint64_t sequence, uint64_t timestamp_ns, unsigned char *record, size_t capacity, size_t *record_size)
Generate bounded LOOM feature evidence for an existing JPEG.
Definition loomcam.c:200
#define LOOM_SELF_TEST_LATITUDE
Nonzero latitude fixture checks that no-match clears stale evidence.
Definition loomcam.c:53
static int return_server(int argc, char **argv)
Keep bounded T1 state separate from the waypoint transport transaction.
Definition loomcam.c:478
static bool read_onnx_descriptor_identity(const struct inference_settings *settings, char graph[65], char descriptor[65])
Read the graph and descriptor identities declared by the model metadata.
Definition loomcam.c:155
#define LOOM_DECIMAL_RADIX
The CLI accepts decimal photo numbers, never signed or truncated IDs.
Definition loomcam.c:46
static uint64_t feature_u64(const unsigned char *bytes)
Decode an unsigned field from LOOM's little-endian record.
Definition loomcam.c:180
loom_cli_layout
argv[0] is the program name; a sole flag gives two total arguments.
Definition loomcam.c:48
static int self_test(void)
Hardware-free check that the empty matcher cannot manufacture a waypoint.
Definition loomcam.c:567
static bool parse_sequence(const char *text, uint32_t *sequence)
Parse a nonzero correlation sequence without truncation or signed input.
Definition loomcam.c:384
static bool description_field(const struct exif_value *description, const char *key, char value[64])
Require a uniquely identified flight-description value.
Definition loomcam.c:110
static bool description_optional_number(const struct exif_value *description, const char *key, double default_value, double *number)
Read numeric metadata with a default for absence only.
Definition loomcam.c:135
static bool description_lookup(const struct exif_value *description, const char *key, char value[64], bool *found)
Read one bounded observation field from an already-fetched EXIF description.
Definition loomcam.c:75
static bool return_settings(const char *path, struct inference_settings *settings, struct loom_return_options *options)
Reuse common path/INI policy without opening a model or camera.
Definition loomcam.c:396
Definition camera_backend.h:50
Borrowed bytes plus enough type information for safe interpretation.
Definition exifite.h:119
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
Definition inference_model.h:43
Parsed descriptor with self-referencing tensor-name pointers; do not copy after parsing.
Definition inference_model.h:31
struct onnx_tensor outputs[ONNX_TENSOR_LIMIT]
Definition inference_model.h:36
Per-application configuration; all resolved paths belong to this caller-owned value.
Definition inference_settings.h:39
char descriptor[INFERENCE_PATH_CAPACITY]
Definition inference_settings.h:43
Borrowed per-invocation input; no member owns or acquires a camera.
Definition loomcam.c:63
Module-owned inference settings, separate from universal runtime settings.
Definition loom_return.h:65
Local ground point in metres east/north of the reference origin.
Definition loom_return.h:31
Caller-owned sequence and smoothing state; first observation seeds target.
Definition loom_return.h:51
Named concrete tensor view; its aligned backing storage must outlive the session.
Definition onnx_session.h:44
One timestamped geographic position for a replay annotation.
Definition ear_heatmap_overlay.c:79