FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
api.h
Go to the documentation of this file.
1#ifndef FERS_API_H
2#define FERS_API_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/**
12 * @brief An opaque handle to an in-memory FERS simulation context.
13 *
14 * This pointer represents a live simulation instance. It is an "opaque" type,
15 * meaning its internal structure is hidden from the API consumer. This design
16 * is intentional to decouple the client from the C++ implementation details of
17 * the simulator core. It ensures that the client code (e.g., in Rust) will not
18 * break even if the internal C++ `FersContext` class is changed, maintaining ABI
19 * stability across library versions.
20 *
21 * @note The client is responsible for managing the lifetime of this handle via
22 * `fers_context_create()` and `fers_context_destroy()`.
23 */
24struct fers_context;
25
26typedef struct fers_context fers_context_t; // NOLINT(*-use-using)
27
28/**
29 * @brief A function pointer type for progress reporting callbacks.
30 *
31 * This callback can be implemented by the client to receive progress updates
32 * during long-running operations like `fers_run_simulation`.
33 *
34 * @param message A descriptive message about the current operation.
35 * @param current The current progress step.
36 * @param total The total number of steps for the operation.
37 * @param user_data An opaque pointer passed back to the caller, useful for
38 * maintaining state (e.g., a class instance or application handle).
39 */
40// NOLINTNEXTLINE(*-use-using): Public C API callback typedef.
41typedef void (*fers_progress_callback_t)(const char* message, int current, int total, void* user_data);
42
43/**
44 * @brief A function pointer type for cooperative simulation cancellation.
45 *
46 * The callback should return non-zero when the active simulation should stop.
47 * It is polled between event-loop iterations and streaming sample chunks.
48 *
49 * @param user_data An opaque pointer passed back to the caller.
50 * @return Non-zero to request cancellation, zero to continue.
51 */
52typedef int (*fers_cancel_callback_t)(void* user_data); // NOLINT(*-use-using)
53
54/**
55 * @brief A function pointer type for VITA 49.2 live telemetry callbacks.
56 *
57 * The JSON strings are valid only for the duration of the callback. Either
58 * argument may be NULL when that payload has not changed.
59 *
60 * @param stats_json Full stream-counter snapshot JSON, or NULL.
61 * @param packet_batch_json Packet trace batch JSON array, or NULL.
62 * @param user_data An opaque pointer passed back to the caller.
63 */
64// NOLINTNEXTLINE(*-use-using): Public C API callback typedef.
65typedef void (*fers_vita49_telemetry_callback_t)(const char* stats_json, const char* packet_batch_json,
66 void* user_data);
67
68
69// --- Context Lifecycle ---
70
71/**
72 * @brief Creates a new FERS simulation context.
73 *
74 * Allocates and initializes a new, empty simulation context in memory. This
75 * context serves as the container for a scenario loaded via one of the
76 * `fers_load_...` or `fers_update_...` functions.
77 *
78 * @note In a C API, RAII is not available. The caller is responsible for
79 * destroying the returned context using `fers_context_destroy()` to
80 * prevent resource leaks.
81 *
82 * @return A non-null opaque pointer (handle) to the simulation context on success.
83 * Returns NULL on failure (e.g., out of memory).
84 */
86
87/**
88 * @brief Destroys a FERS simulation context and releases all associated memory.
89 *
90 * This function must be called for every context created by `fers_context_create()`
91 * to ensure proper cleanup of the underlying C++ objects. Accessing the context
92 * handle after calling this function results in undefined behavior.
93 *
94 * @param context A valid pointer to a `fers_context_t` handle. If context is NULL,
95 * the function performs no action for safety and does not set an error.
96 */
98
99/**
100 * @brief Sets the output directory for simulation results.
101 * @param context A valid `fers_context_t` handle.
102 * @param out_dir A null-terminated UTF-8 string for the output directory path.
103 * @return 0 on success, non-zero on error.
104 */
105int fers_set_output_directory(fers_context_t* context, const char* out_dir);
106
107/**
108 * @brief Resets the context output mode to the default HDF5 output.
109 *
110 * Runtime-only VITA 49.2 endpoint settings are retained for later VITA runs,
111 * but the selected output mode is changed back to HDF5.
112 *
113 * @param context A valid `fers_context_t` handle.
114 * @return 0 on success, non-zero on error.
115 */
117
118/**
119 * @brief Enables the FERS VITA 49.2 UDP streaming profile for a context.
120 *
121 * HDF5 remains the default until this function succeeds. The host is copied by
122 * the library and may be freed by the caller after the call returns.
123 *
124 * @param context A valid `fers_context_t` handle.
125 * @param host Null-terminated destination host name or address.
126 * @param port Destination UDP port in the range 1..65535.
127 * @return 0 on success, non-zero on error.
128 */
129int fers_enable_vita49_udp_output(fers_context_t* context, const char* host, uint16_t port);
130
131/**
132 * @brief Sets the fixed ADC full-scale value used by the FERS VITA 49.2 int16 IQ profile.
133 *
134 * VITA mode requires a positive finite full-scale before simulation starts.
135 * HDF5 output keeps its existing full-buffer scaling behavior.
136 *
137 * @param context A valid `fers_context_t` handle.
138 * @param fullscale Positive finite full-scale value.
139 * @return 0 on success, non-zero on error.
140 */
141int fers_set_vita49_fullscale(fers_context_t* context, double fullscale);
142
143/**
144 * @brief Sets a deterministic FERS VITA 49.2 stream epoch as Unix nanoseconds.
145 *
146 * The epoch must fit the VRT 32-bit UTC seconds timestamp field.
147 *
148 * @param context A valid `fers_context_t` handle.
149 * @param epoch_unix_nanoseconds Unix epoch timestamp in nanoseconds.
150 * @return 0 on success, non-zero on error.
151 */
152int fers_set_vita49_epoch_unix_nanoseconds(fers_context_t* context, uint64_t epoch_unix_nanoseconds);
153
154/**
155 * @brief Sets the FERS VITA 49.2 UDP profile maximum payload size in bytes.
156 *
157 * The default is 1400 bytes to avoid ordinary IP fragmentation.
158 *
159 * @param context A valid `fers_context_t` handle.
160 * @param max_udp_payload Maximum UDP payload size in bytes.
161 * @return 0 on success, non-zero on error.
162 */
163int fers_set_vita49_max_udp_payload(fers_context_t* context, uint16_t max_udp_payload);
164
165/**
166 * @brief Sets the bounded FERS VITA 49.2 sender queue depth in packets.
167 *
168 * When this queue is full, the simulation thread blocks until the pacing thread
169 * sends a packet and frees a slot.
170 *
171 * @param context A valid `fers_context_t` handle.
172 * @param queue_depth Queue depth in packets. Must be greater than zero.
173 * @return 0 on success, non-zero on error.
174 */
175int fers_set_vita49_queue_depth(fers_context_t* context, uint32_t queue_depth);
176
177/**
178 * @brief Enables or disables FERS VITA 49.2 packet trace telemetry.
179 *
180 * Stream counter telemetry is unaffected. Disabling packet trace telemetry avoids
181 * per-packet diagnostic record creation for UI runs that only need live counters.
182 *
183 * @param context A valid `fers_context_t` handle.
184 * @param enabled Non-zero to enable packet trace telemetry, zero to disable it.
185 * @return 0 on success, non-zero on error.
186 */
188
189/**
190 * @brief Log levels for the FERS library.
191 */
192typedef enum // NOLINT(*-use-using,performance-enum-size)
193{
194 FERS_LOG_TRACE, ///< Trace-level diagnostic logging.
195 FERS_LOG_DEBUG, ///< Debug-level diagnostic logging.
196 FERS_LOG_INFO, ///< Informational logging.
197 FERS_LOG_WARNING, ///< Warning logging for recoverable issues.
198 FERS_LOG_ERROR, ///< Error logging for failed operations.
199 FERS_LOG_FATAL, ///< Fatal logging for unrecoverable failures.
200 FERS_LOG_OFF ///< Disables logging output.
202
203/**
204 * @brief A function pointer type for receiving formatted log lines.
205 *
206 * @param level The severity level of the log line.
207 * @param line The full formatted log line, without a trailing newline.
208 * @param user_data An opaque pointer passed back to the caller.
209 */
210typedef void (*fers_log_callback_t)(fers_log_level_t level, const char* line, void* user_data); // NOLINT(*-use-using)
211
212/**
213 * @brief Configures the internal logger.
214 * @param level The minimum severity level to log.
215 * @param log_file_path Optional path to a log file. Pass NULL to disable file logging.
216 * @return 0 on success, non-zero on error.
217 */
218int fers_configure_logging(fers_log_level_t level, const char* log_file_path);
219
220/**
221 * @brief Returns the library version string.
222 *
223 * The returned pointer remains valid for the lifetime of the process and must
224 * not be freed by the caller.
225 */
226const char* fers_get_version(void);
227
228/**
229 * @brief Returns the current internal logger level.
230 */
232
233/**
234 * @brief Registers a callback for formatted log lines.
235 * Pass NULL as callback to disable log callbacks.
236 */
237void fers_set_log_callback(fers_log_callback_t callback, void* user_data);
238
239/**
240 * @brief Submits a log message to the library's unified logging system.
241 * This ensures CLI messages match the format (timestamps, alignment) of library messages.
242 */
243void fers_log(fers_log_level_t level, const char* message);
244
245/**
246 * @brief Sets the number of worker threads for the simulation.
247 * @param num_threads The number of threads to use.
248 * @return 0 on success, non-zero on error. This function clears any previous
249 * thread-local error message at entry, like the other fallible API calls.
250 */
251int fers_set_thread_count(unsigned num_threads);
252
253// --- Scenario Loading & Serialization ---
254
255/**
256 * @brief Loads a scenario into the context from a FERS XML file.
257 *
258 * This is the standard method for initializing a simulation context from a file on
259 * disk. It is essential for interoperability with the CLI and legacy workflows that
260 * rely on the FERS XML format.
261 *
262 * @param context A valid `fers_context_t` handle.
263 * @param xml_filepath A null-terminated UTF-8 string for the input XML file path.
264 * @param validate A boolean (0 or 1) indicating whether to validate the XML
265 * against the embedded FERS schema. Validation is recommended to
266 * ensure scenario correctness.
267 * @return 0 on success, a non-zero error code on failure. Use
268 * `fers_get_last_error_message()` to retrieve error details.
269 */
270int fers_load_scenario_from_xml_file(fers_context_t* context, const char* xml_filepath, int validate);
271
272/**
273 * @brief Loads a scenario into the context from a FERS XML string.
274 *
275 * This function provides a way to load a scenario from an in-memory string,
276 * avoiding file I/O. It is useful for test harnesses or for UIs that manage
277 * scenarios as text content before parsing.
278 *
279 * @param context A valid `fers_context_t` handle.
280 * @param xml_content A null-terminated UTF-8 string containing the FERS scenario in XML format.
281 * @param validate A boolean (0 or 1) indicating whether to validate the XML
282 * against the embedded FERS schema.
283 * @return 0 on success, a non-zero error code on failure. Use
284 * `fers_get_last_error_message()` to retrieve error details.
285 */
286int fers_load_scenario_from_xml_string(fers_context_t* context, const char* xml_content, int validate);
287
288/**
289 * @brief Serializes the current simulation scenario into a JSON string.
290 *
291 * This function is the primary method for the UI to retrieve the full state of
292 * the simulation. JSON is used as the interchange format because it is lightweight,
293 * human-readable, and natively supported by web technologies, making it trivial
294 * to parse and use in the React/TypeScript frontend.
295 *
296 * @note Memory Management: The returned string is allocated by this library and
297 * its ownership is transferred to the caller. It is crucial to free this
298 * string using `fers_free_string()` to prevent memory leaks.
299 *
300 * @param context A valid `fers_context_t` handle.
301 * @return A dynamically allocated, null-terminated C-string containing the
302 * JSON representation of the scenario. Returns NULL on failure.
303 */
305
306/**
307 * @brief Serializes the current simulation scenario into a FERS XML string.
308 *
309 * This function enables exporting the in-memory state back into the standard FERS
310 * XML file format. This is essential for interoperability with legacy tools and
311 * for allowing a user to save a scenario that was created or modified in the UI.
312 *
313 * @note Memory Management: The returned string is dynamically allocated and
314 * its ownership is transferred to the caller. It must be freed using
315 * `fers_free_string()` to prevent memory leaks.
316 *
317 * @param context A valid `fers_context_t` handle.
318 * @return A dynamically allocated, null-terminated C-string containing the
319 * XML representation of the scenario. Returns NULL on failure.
320 */
322
323/**
324 * @brief Returns JSON metadata for the most recent simulation output files.
325 *
326 * The returned JSON describes generated HDF5 file structure and sample ranges.
327 * The caller owns the returned string and must free it with `fers_free_string`.
328 * If no simulation has completed yet, the returned JSON contains an empty `files`
329 * array.
330 *
331 * @param context A valid `fers_context_t` handle.
332 * @return A heap-allocated JSON string, or NULL on error.
333 */
335
336/**
337 * @brief Returns a JSON projection of simulation startup memory and HDF5 payload size.
338 *
339 * The projection includes phase-noise lookup memory, streaming I/Q buffer memory,
340 * rendered HDF5 payload size, current resident memory not attributed to streaming
341 * I/Q buffers where available, and an aggregate projected total. The caller owns
342 * the returned string and must free it with `fers_free_string`.
343 *
344 * @param context A valid `fers_context_t` handle.
345 * @return A heap-allocated JSON string, or NULL on error.
346 */
348
349/**
350 * @brief Updates the simulation scenario from a JSON string.
351 *
352 * This is the primary method for the UI to push its state back to the C++
353 * core. It performs a full replacement of the existing scenario.
354 *
355 * @param context A valid `fers_context_t` handle.
356 * @param scenario_json A null-terminated UTF-8 string containing the FERS scenario in JSON format.
357 * @return 0 on success.
358 * 1 on generic logic error.
359 * 2 on JSON parsing/schema validation error.
360 * Use `fers_get_last_error_message()` to retrieve error details.
361 */
362int fers_update_scenario_from_json(fers_context_t* context, const char* scenario_json);
363
364/**
365 * @brief Updates a single platform's paths and name from JSON without full context recreation.
366 * @param context A valid `fers_context_t` handle.
367 * @param id The unique ID of the platform.
368 * @param json The JSON string for the platform.
369 * @return 0 on success, non-zero on failure.
370 */
371int fers_update_platform_from_json(fers_context_t* context, uint64_t id, const char* json);
372
373/**
374 * @brief Updates the global simulation parameters from JSON without full context recreation.
375 * @param context A valid `fers_context_t` handle.
376 * @param json The JSON string for the parameters.
377 * @return 0 on success, non-zero on failure.
378 */
379int fers_update_parameters_from_json(fers_context_t* context, const char* json);
380
381/**
382 * @brief Updates a single antenna from JSON without full context recreation.
383 * @param context A valid `fers_context_t` handle.
384 * @param json The JSON string for the antenna.
385 * @return 0 on success, non-zero on failure.
386 */
387int fers_update_antenna_from_json(fers_context_t* context, const char* json);
388
389/**
390 * @brief Updates a single waveform from JSON without full context recreation.
391 * @param context A valid `fers_context_t` handle.
392 * @param json The JSON string for the waveform.
393 * @return 0 on success, non-zero on failure.
394 */
395int fers_update_waveform_from_json(fers_context_t* context, const char* json);
396
397/**
398 * @brief Updates a single transmitter from JSON without full context recreation.
399 * @param context A valid `fers_context_t` handle.
400 * @param id The unique ID of the transmitter.
401 * @param json The JSON string for the transmitter.
402 * @return 0 on success, non-zero on failure.
403 */
404int fers_update_transmitter_from_json(fers_context_t* context, uint64_t id, const char* json);
405
406/**
407 * @brief Updates a single receiver from JSON without full context recreation.
408 * @param context A valid `fers_context_t` handle.
409 * @param id The unique ID of the receiver.
410 * @param json The JSON string for the receiver.
411 * @return 0 on success, non-zero on failure.
412 */
413int fers_update_receiver_from_json(fers_context_t* context, uint64_t id, const char* json);
414
415/**
416 * @brief Updates a single target from JSON without full context recreation.
417 * @param context A valid `fers_context_t` handle.
418 * @param id The unique ID of the target.
419 * @param json The JSON string for the target.
420 * @return 0 on success, non-zero on failure.
421 */
422int fers_update_target_from_json(fers_context_t* context, uint64_t id, const char* json);
423
424/**
425 * @brief Updates a monostatic radar from JSON without full context recreation.
426 * @param context A valid `fers_context_t` handle.
427 * @param json The JSON string for the monostatic component.
428 * @return 0 on success, non-zero on failure.
429 */
430int fers_update_monostatic_from_json(fers_context_t* context, const char* json);
431
432/**
433 * @brief Updates a single timing source from JSON without full context recreation.
434 * @param context A valid `fers_context_t` handle.
435 * @param id The unique ID of the timing source.
436 * @param json The JSON string for the timing source.
437 * @return 0 on success, non-zero on failure.
438 */
439int fers_update_timing_from_json(fers_context_t* context, uint64_t id, const char* json);
440
441// --- Error Handling ---
442
443/**
444 * @brief Retrieves the last error message that occurred on the current thread.
445 *
446 * Because C++ exceptions cannot safely propagate across the FFI boundary into
447 * other languages, this function provides the standard C-style error reporting
448 * mechanism. The error state is stored in a thread-local variable to ensure that
449 * concurrent API calls from different threads do not overwrite each other's error
450 * messages. The error is cleared at the start of each fallible API call.
451 *
452 * @note Memory Management: The returned string's ownership is transferred to the
453 * caller. It MUST be freed using `fers_free_string()` to prevent memory leaks.
454 *
455 * @return A dynamically allocated, null-terminated C-string containing the last
456 * error message, or NULL if no error has occurred.
457 */
459
460/**
461 * @brief Returns the last deduplicated rotation-unit warning list for the calling thread as JSON.
462 *
463 * The returned value is a JSON array of strings. It is populated by successful XML/JSON
464 * load and update calls that detect suspicious rotation values. The caller owns the string
465 * and must free it with `fers_free_string()`.
466 *
467 * @return A dynamically allocated JSON array string, or NULL if no warnings are available.
468 */
470
471/**
472 * @brief Frees a string that was allocated and returned by the libfers API.
473 *
474 * This function must be used to release memory for any string returned by
475 * functions like `fers_get_scenario_as_json` or `fers_get_last_error_message`.
476 * It exists to ensure that the memory deallocation mechanism (`free`) matches the
477 * allocation mechanism (`strdup`/`malloc`) used within the C++ library, preventing
478 * potential crashes from mismatched allocators across language boundaries.
479 *
480 * @param str A pointer to the string to be freed. If str is NULL, no action is taken.
481 */
482void fers_free_string(char* str);
483
484
485// --- Simulation Execution ---
486
487/**
488 * @brief Runs the simulation defined in the provided context.
489 *
490 * This function is synchronous and will block the calling thread until the
491 * simulation is complete. This design keeps the API simple. For use in a
492 * responsive UI, it is the responsibility of the caller (e.g., the Tauri
493 * backend) to invoke this function on a separate worker thread to avoid
494 * freezing the user interface.
495 *
496 * @param context A valid `fers_context_t` handle containing a loaded scenario.
497 * @param callback A function pointer to a progress callback. Can be NULL.
498 * @param user_data An opaque pointer passed to the callback function.
499 * @return 0 on success, a non-zero error code on failure. Use
500 * `fers_get_last_error_message()` to retrieve error details.
501 */
502int fers_run_simulation(fers_context_t* context, fers_progress_callback_t callback, void* user_data);
503
504/**
505 * @brief Runs the simulation with optional progress, cancellation, and VITA telemetry callbacks.
506 *
507 * Return values match `fers_run_simulation`, except 2 means the run was
508 * cooperatively cancelled after output finalization and metadata collection.
509 *
510 * @param context A valid `fers_context_t` handle containing a loaded scenario.
511 * @param progress_callback Optional progress callback. Can be NULL.
512 * @param progress_user_data Opaque pointer passed to the progress callback.
513 * @param cancel_callback Optional cancellation callback. Can be NULL.
514 * @param cancel_user_data Opaque pointer passed to the cancellation callback.
515 * @param vita49_telemetry_callback Optional VITA live telemetry callback. Can be NULL.
516 * @param vita49_telemetry_user_data Opaque pointer passed to the VITA telemetry callback.
517 * @return 0 on success, 2 on cancellation, a non-zero error code on failure.
518 */
520 void* progress_user_data, fers_cancel_callback_t cancel_callback, void* cancel_user_data,
521 fers_vita49_telemetry_callback_t vita49_telemetry_callback,
522 void* vita49_telemetry_user_data);
523
524
525// --- Utility Functions ---
526
527/**
528 * @brief Generates a KML file for visualizing the scenario in the context.
529 *
530 * This utility exists to provide a simple, out-of-the-box method for users to
531 * validate and visualize the geographic layout and motion paths of their
532 * scenarios in common external tools like Google Earth.
533 *
534 * @param context A valid `fers_context_t` handle containing a loaded scenario.
535 * @param output_kml_filepath A null-terminated UTF-8 string for the output KML file path.
536 * @return 0 on success, a non-zero error code on failure. Use
537 * `fers_get_last_error_message()` to retrieve KML generation details.
538 */
539int fers_generate_kml(const fers_context_t* context, const char* output_kml_filepath);
540
541// --- Antenna Pattern Utilities ---
542
543/**
544 * @brief Represents a sampled 2D antenna gain pattern.
545 * Gains are in linear scale (not dB), normalized to the antenna's peak gain.
546 * The data is structured as a flat array in row-major order (elevation rows, then azimuth columns).
547 * @note The `gains` array must be freed using `fers_free_antenna_pattern_data`.
548 */
549typedef struct // NOLINT(*-use-using)
550{
551 double* gains; ///< Flat array of gain values [el_count * az_count].
552 size_t az_count; ///< Number of samples along azimuth (-180 to +180 deg).
553 size_t el_count; ///< Number of samples along elevation (-90 to +90 deg).
554 double max_gain; ///< Peak gain found in the pattern, in linear scale.
556
557
558/**
559 * @brief Samples the gain pattern of a specified antenna and provides the data.
560 *
561 * This function calculates the antenna's far-field gain at a specified resolution
562 * over the full sphere of directions (azimuth and elevation). The resulting gain
563 * values are linear (not in dB) and normalized relative to the pattern's peak gain.
564 * This is a stateless utility useful for UI previews and analysis.
565 *
566 * @param context A valid `fers_context_t` handle containing a loaded scenario with the antenna.
567 * @param antenna_id The unique ID of the antenna asset to sample.
568 * @param az_samples The desired number of sample points along the azimuth axis.
569 * Must be at least 2 to span the full azimuth range.
570 * @param el_samples The desired number of sample points along the elevation axis.
571 * Must be at least 2 to span the full elevation range.
572 * @param frequency_hz The frequency in Hz to use for gain calculation (affects aperture antennas).
573 * @return A pointer to a `fers_antenna_pattern_data_t` struct containing the results.
574 * Returns NULL on failure (e.g., antenna not found). The caller owns the
575 * returned struct and must free it with `fers_free_antenna_pattern_data`.
576 */
577fers_antenna_pattern_data_t* fers_get_antenna_pattern(const fers_context_t* context, uint64_t antenna_id,
578 size_t az_samples, size_t el_samples, double frequency_hz);
579
580/**
581 * @brief Frees the memory allocated for an antenna pattern data structure.
582 * @param data A pointer to the `fers_antenna_pattern_data_t` struct to free.
583 */
585
586
587// --- Path Interpolation Utilities ---
588
589/**
590 * @brief Defines the interpolation methods available for path generation.
591 * This enum provides a language-agnostic way to specify the desired
592 * interpolation algorithm when calling the path generation functions.
593 */
594typedef enum // NOLINT(*-use-using,performance-enum-size)
595{
600
601/**
602 * @brief Units used for external rotation angles and rates.
603 */
604typedef enum // NOLINT(*-use-using,performance-enum-size)
605{
609
610/**
611 * @brief Represents a single waypoint for a motion path.
612 * Coordinates are in the scenario's defined coordinate system (e.g., ENU meters).
613 */
614typedef struct // NOLINT(*-use-using)
615{
616 double time; /**< Time in seconds. */
617 double x; /**< X coordinate in meters (East in ENU). */
618 double y; /**< Y coordinate in meters (North in ENU). */
619 double z; /**< Z coordinate in meters (Up/Altitude in ENU). */
621
622/**
623 * @brief Represents a single waypoint for a rotation path.
624 * Angles are in compass units (CW from North) selected by the caller.
625 */
626typedef struct // NOLINT(*-use-using)
627{
628 double time; /**< Time in seconds. */
629 double azimuth; /**< Azimuth angle in compass units (0=North, pi/2 or 90=East). */
630 double elevation; /**< Elevation angle in compass units (positive up). */
632
633/**
634 * @brief Represents a single interpolated point on a motion path.
635 * Includes position and velocity in the scenario's coordinate frame.
636 */
637typedef struct // NOLINT(*-use-using)
638{
639 double x; /**< X position in meters. */
640 double y; /**< Y position in meters. */
641 double z; /**< Z position in meters. */
642 double vx; /**< X velocity in m/s. */
643 double vy; /**< Y velocity in m/s. */
644 double vz; /**< Z velocity in m/s. */
646
647/**
648 * @brief Represents a single interpolated point on a rotation path.
649 * Angles are in compass units (CW from North) selected by the caller.
650 */
651typedef struct // NOLINT(*-use-using)
652{
653 double azimuth; /**< Azimuth angle in compass units. */
654 double elevation; /**< Elevation angle in compass units. */
656
657
658/**
659 * @brief A container for an array of interpolated motion path points.
660 * @note The `points` array must be freed using `fers_free_interpolated_motion_path`.
661 */
662typedef struct // NOLINT(*-use-using)
663{
664 fers_interpolated_point_t* points; ///< Heap-allocated interpolated motion points.
665 size_t count; ///< Number of interpolated motion points.
667
668/**
669 * @brief A container for an array of interpolated rotation path points.
670 * @note The `points` array must be freed using `fers_free_interpolated_rotation_path`.
671 */
672typedef struct // NOLINT(*-use-using)
673{
674 fers_interpolated_rotation_point_t* points; ///< Heap-allocated interpolated rotation points.
675 size_t count; ///< Number of interpolated rotation points.
677
678
679/**
680 * @brief Calculates an interpolated motion path from a set of waypoints.
681 * This function is a stateless utility that computes the path without needing a
682 * full simulation context. It is useful for UI previews.
683 *
684 * @param waypoints An array of `fers_motion_waypoint_t` structs.
685 * @param waypoint_count The number of waypoints in the array.
686 * @param interp_type The interpolation algorithm to use.
687 * @param num_points The desired number of points in the output interpolated path.
688 * @return A pointer to a `fers_interpolated_path_t` struct containing the results.
689 * Returns NULL on failure. The caller owns the returned struct and must
690 * free it with `fers_free_interpolated_motion_path`.
691 */
693 size_t waypoint_count, fers_interp_type_t interp_type,
694 size_t num_points);
695
696/**
697 * @brief Frees the memory allocated for an interpolated motion path.
698 * @param path A pointer to the `fers_interpolated_path_t` struct to free.
699 */
701
702/**
703 * @brief Calculates an interpolated rotation path from a set of waypoints.
704 * This function is a stateless utility for UI previews.
705 *
706 * @param waypoints An array of `fers_rotation_waypoint_t` structs.
707 * @param waypoint_count The number of waypoints in the array.
708 * @param interp_type The interpolation algorithm to use (STATIC, LINEAR, CUBIC).
709 * @param angle_unit The unit used by the waypoint angles and desired output angles.
710 * @param num_points The desired number of points in the output interpolated path.
711 * @return A pointer to a `fers_interpolated_rotation_path_t` struct containing the results.
712 * Returns NULL on failure. The caller owns the returned struct and must
713 * free it with `fers_free_interpolated_rotation_path`.
714 */
716 size_t waypoint_count,
717 fers_interp_type_t interp_type,
718 fers_angle_unit_t angle_unit, size_t num_points);
719
720/**
721 * @brief Frees the memory allocated for an interpolated rotation path.
722 * @param path A pointer to the `fers_interpolated_rotation_path_t` struct to free.
723 */
725
726// --- Preview Link Calculation ---
727
728/**
729 * @brief Quality of the radio link based on SNR.
730 */
731typedef enum // NOLINT(*-use-using,performance-enum-size)
732{
733 FERS_LINK_STRONG, // SNR > 0 dB
734 FERS_LINK_WEAK // SNR < 0 dB (Geometric possibility but sub-noise)
736
737/**
738 * @brief Type of visual link to render.
739 */
740typedef enum // NOLINT(*-use-using,performance-enum-size)
741{
742 FERS_LINK_MONOSTATIC, // Combined Tx/Rx path
743 FERS_LINK_BISTATIC_TX_TGT, // Illuminator path
744 FERS_LINK_BISTATIC_TGT_RX, // Scattered path
745 FERS_LINK_DIRECT_TX_RX // Interference path
747
748/**
749 * @brief Represents a single renderable line segment metadata.
750 * Geometry is resolved client-side.
751 */
752typedef struct // NOLINT(*-use-using)
753{
754 fers_link_type_t type; /**< Type of the link (Monostatic, Bistatic, etc.). */
755 fers_link_quality_t quality; /**< Signal quality (Strong/Weak). */
756 char label[128]; /**< Pre-formatted label (e.g., "-95 dBm"). */
757 uint64_t source_id; /**< ID of the source component (e.g. Transmitter). */
758 uint64_t dest_id; /**< ID of the destination component (e.g. Receiver/Target). */
759 uint64_t origin_id; /**< ID of the originating Transmitter (for scattered paths). */
760 double rcs; /**< RCS in m^2 for this path. Negative if not applicable (e.g., non-monostatic links). */
761 double actual_power_dbm; /**< Received power in dBm with actual RCS applied. -999 if not applicable. */
762 double display_value; /**< Numeric value represented by label, in the label's unit. */
764
765/**
766 * @brief A container for a list of visual links.
767 * @note The `links` array is owned by this struct and must be freed using `fers_free_preview_links`.
768 */
769typedef struct // NOLINT(*-use-using)
770{
771 fers_visual_link_t* links; ///< Heap-allocated visual link array.
772 size_t count; ///< Number of visual links in the array.
774
775/**
776 * @brief Calculates visual links for a specific simulation time.
777 * @param context The simulation context.
778 * @param time The simulation time in seconds.
779 * @return A pointer to a link list. Caller must free with fers_free_preview_links.
780 */
782
783/**
784 * @brief Frees the memory allocated for a preview link list.
785 * @param list The list to free.
786 */
788
789#ifdef __cplusplus
790}
791#endif
792
793#endif
char * fers_get_scenario_as_xml(fers_context_t *context)
Serializes the current simulation scenario into a FERS XML string.
Definition api.cpp:728
int fers_set_vita49_queue_depth(fers_context_t *context, uint32_t queue_depth)
Sets the bounded FERS VITA 49.2 sender queue depth in packets.
int fers_update_antenna_from_json(fers_context_t *context, const char *json)
Updates a single antenna from JSON without full context recreation.
Definition api.cpp:867
int fers_run_simulation_ex(fers_context_t *context, fers_progress_callback_t progress_callback, void *progress_user_data, fers_cancel_callback_t cancel_callback, void *cancel_user_data, fers_vita49_telemetry_callback_t vita49_telemetry_callback, void *vita49_telemetry_user_data)
Runs the simulation with optional progress, cancellation, and VITA telemetry callbacks.
Definition api.cpp:1225
void fers_free_antenna_pattern_data(fers_antenna_pattern_data_t *data)
Frees the memory allocated for an antenna pattern data structure.
Definition api.cpp:1582
fers_angle_unit_t
Units used for external rotation angles and rates.
Definition api.h:605
@ FERS_ANGLE_UNIT_DEG
Definition api.h:606
@ FERS_ANGLE_UNIT_RAD
Definition api.h:607
void(* fers_progress_callback_t)(const char *message, int current, int total, void *user_data)
A function pointer type for progress reporting callbacks.
Definition api.h:41
void fers_log(fers_log_level_t level, const char *message)
Submits a log message to the library's unified logging system.
Definition api.cpp:392
int fers_load_scenario_from_xml_file(fers_context_t *context, const char *xml_filepath, int validate)
Loads a scenario into the context from a FERS XML file.
Definition api.cpp:605
int(* fers_cancel_callback_t)(void *user_data)
A function pointer type for cooperative simulation cancellation.
Definition api.h:52
char * fers_get_last_warning_messages_json()
Returns the last deduplicated rotation-unit warning list for the calling thread as JSON.
Definition api.cpp:1097
int fers_update_waveform_from_json(fers_context_t *context, const char *json)
Updates a single waveform from JSON without full context recreation.
Definition api.cpp:893
int fers_update_transmitter_from_json(fers_context_t *context, uint64_t id, const char *json)
Updates a single transmitter from JSON without full context recreation.
Definition api.cpp:916
int fers_use_hdf5_output(fers_context_t *context)
Resets the context output mode to the default HDF5 output.
Definition api.cpp:440
char * fers_get_last_error_message()
Retrieves the last error message that occurred on the current thread.
Definition api.cpp:1084
int fers_enable_vita49_udp_output(fers_context_t *context, const char *host, uint16_t port)
Enables the FERS VITA 49.2 UDP streaming profile for a context.
void fers_free_interpolated_motion_path(fers_interpolated_path_t *path)
Frees the memory allocated for an interpolated motion path.
Definition api.cpp:1379
void(* fers_log_callback_t)(fers_log_level_t level, const char *line, void *user_data)
A function pointer type for receiving formatted log lines.
Definition api.h:210
int fers_update_parameters_from_json(fers_context_t *context, const char *json)
Updates the global simulation parameters from JSON without full context recreation.
Definition api.cpp:842
int fers_set_vita49_packet_trace_enabled(fers_context_t *context, int enabled)
Enables or disables FERS VITA 49.2 packet trace telemetry.
Definition api.cpp:589
int fers_generate_kml(const fers_context_t *context, const char *output_kml_filepath)
Generates a KML file for visualizing the scenario in the context.
Definition api.cpp:1241
fers_log_level_t
Log levels for the FERS library.
Definition api.h:193
@ FERS_LOG_FATAL
Fatal logging for unrecoverable failures.
Definition api.h:199
@ FERS_LOG_DEBUG
Debug-level diagnostic logging.
Definition api.h:195
@ FERS_LOG_ERROR
Error logging for failed operations.
Definition api.h:198
@ FERS_LOG_OFF
Disables logging output.
Definition api.h:200
@ FERS_LOG_INFO
Informational logging.
Definition api.h:196
@ FERS_LOG_TRACE
Trace-level diagnostic logging.
Definition api.h:194
@ FERS_LOG_WARNING
Warning logging for recoverable issues.
Definition api.h:197
char * fers_get_memory_projection_json(fers_context_t *context)
Returns a JSON projection of simulation startup memory and HDF5 payload size.
Definition api.cpp:781
int fers_set_output_directory(fers_context_t *context, const char *out_dir)
Sets the output directory for simulation results.
Definition api.cpp:419
int fers_set_vita49_epoch_unix_nanoseconds(fers_context_t *context, uint64_t epoch_unix_nanoseconds)
Sets a deterministic FERS VITA 49.2 stream epoch as Unix nanoseconds.
void fers_context_destroy(fers_context_t *context)
Destroys a FERS simulation context and releases all associated memory.
Definition api.cpp:118
fers_context_t * fers_context_create()
Creates a new FERS simulation context.
Definition api.cpp:97
int fers_update_target_from_json(fers_context_t *context, uint64_t id, const char *json)
Updates a single target from JSON without full context recreation.
Definition api.cpp:966
void fers_free_preview_links(fers_visual_link_list_t *list)
Frees the memory allocated for a preview link list.
Definition api.cpp:1667
fers_interpolated_path_t * fers_get_interpolated_motion_path(const fers_motion_waypoint_t *waypoints, size_t waypoint_count, fers_interp_type_t interp_type, size_t num_points)
Calculates an interpolated motion path from a set of waypoints.
Definition api.cpp:1302
fers_antenna_pattern_data_t * fers_get_antenna_pattern(const fers_context_t *context, uint64_t antenna_id, size_t az_samples, size_t el_samples, double frequency_hz)
Samples the gain pattern of a specified antenna and provides the data.
Definition api.cpp:1494
int fers_update_receiver_from_json(fers_context_t *context, uint64_t id, const char *json)
Updates a single receiver from JSON without full context recreation.
Definition api.cpp:941
int fers_run_simulation(fers_context_t *context, fers_progress_callback_t callback, void *user_data)
Runs the simulation defined in the provided context.
Definition api.cpp:1211
void fers_free_string(char *str)
Frees a string that was allocated and returned by the libfers API.
Definition api.cpp:1109
fers_log_level_t fers_get_log_level()
Returns the current internal logger level.
Definition api.cpp:379
fers_visual_link_list_t * fers_calculate_preview_links(const fers_context_t *context, double time)
Calculates visual links for a specific simulation time.
Definition api.cpp:1595
fers_interp_type_t
Defines the interpolation methods available for path generation.
Definition api.h:595
@ FERS_INTERP_CUBIC
Definition api.h:598
@ FERS_INTERP_STATIC
Definition api.h:596
@ FERS_INTERP_LINEAR
Definition api.h:597
const char * fers_get_version(void)
Returns the library version string.
Definition api.cpp:377
int fers_configure_logging(fers_log_level_t level, const char *log_file_path)
Configures the internal logger.
Definition api.cpp:353
void(* fers_vita49_telemetry_callback_t)(const char *stats_json, const char *packet_batch_json, void *user_data)
A function pointer type for VITA 49.2 live telemetry callbacks.
Definition api.h:65
void fers_free_interpolated_rotation_path(fers_interpolated_rotation_path_t *path)
Frees the memory allocated for an interpolated rotation path.
Definition api.cpp:1480
void fers_set_log_callback(fers_log_callback_t callback, void *user_data)
Registers a callback for formatted log lines.
Definition api.cpp:381
char * fers_get_scenario_as_json(fers_context_t *context)
Serializes the current simulation scenario into a JSON string.
Definition api.cpp:701
int fers_set_vita49_fullscale(fers_context_t *context, double fullscale)
Sets the fixed ADC full-scale value used by the FERS VITA 49.2 int16 IQ profile.
Definition api.cpp:505
int fers_update_monostatic_from_json(fers_context_t *context, const char *json)
Updates a monostatic radar from JSON without full context recreation.
Definition api.cpp:991
fers_interpolated_rotation_path_t * fers_get_interpolated_rotation_path(const fers_rotation_waypoint_t *waypoints, size_t waypoint_count, fers_interp_type_t interp_type, fers_angle_unit_t angle_unit, size_t num_points)
Calculates an interpolated rotation path from a set of waypoints.
Definition api.cpp:1391
int fers_update_platform_from_json(fers_context_t *context, uint64_t id, const char *json)
Updates a single platform's paths and name from JSON without full context recreation.
Definition api.cpp:806
fers_link_type_t
Type of visual link to render.
Definition api.h:741
@ FERS_LINK_BISTATIC_TX_TGT
Definition api.h:743
@ FERS_LINK_MONOSTATIC
Definition api.h:742
@ FERS_LINK_BISTATIC_TGT_RX
Definition api.h:744
@ FERS_LINK_DIRECT_TX_RX
Definition api.h:745
int fers_update_timing_from_json(fers_context_t *context, uint64_t id, const char *json)
Updates a single timing source from JSON without full context recreation.
Definition api.cpp:1021
int fers_load_scenario_from_xml_string(fers_context_t *context, const char *xml_content, int validate)
Loads a scenario into the context from a FERS XML string.
Definition api.cpp:656
int fers_update_scenario_from_json(fers_context_t *context, const char *scenario_json)
Updates the simulation scenario from a JSON string.
Definition api.cpp:1045
char * fers_get_last_output_metadata_json(fers_context_t *context)
Returns JSON metadata for the most recent simulation output files.
Definition api.cpp:758
int fers_set_vita49_max_udp_payload(fers_context_t *context, uint16_t max_udp_payload)
Sets the FERS VITA 49.2 UDP profile maximum payload size in bytes.
int fers_set_thread_count(unsigned num_threads)
Sets the number of worker threads for the simulation.
Definition api.cpp:400
fers_link_quality_t
Quality of the radio link based on SNR.
Definition api.h:732
@ FERS_LINK_WEAK
Definition api.h:734
@ FERS_LINK_STRONG
Definition api.h:733
Represents a sampled 2D antenna gain pattern.
Definition api.h:550
size_t el_count
Number of samples along elevation (-90 to +90 deg).
Definition api.h:553
size_t az_count
Number of samples along azimuth (-180 to +180 deg).
Definition api.h:552
double * gains
Flat array of gain values [el_count * az_count].
Definition api.h:551
double max_gain
Peak gain found in the pattern, in linear scale.
Definition api.h:554
A container for an array of interpolated motion path points.
Definition api.h:663
fers_interpolated_point_t * points
Heap-allocated interpolated motion points.
Definition api.h:664
size_t count
Number of interpolated motion points.
Definition api.h:665
Represents a single interpolated point on a motion path.
Definition api.h:638
double vz
Z velocity in m/s.
Definition api.h:644
double x
X position in meters.
Definition api.h:639
double y
Y position in meters.
Definition api.h:640
double z
Z position in meters.
Definition api.h:641
double vx
X velocity in m/s.
Definition api.h:642
double vy
Y velocity in m/s.
Definition api.h:643
A container for an array of interpolated rotation path points.
Definition api.h:673
fers_interpolated_rotation_point_t * points
Heap-allocated interpolated rotation points.
Definition api.h:674
size_t count
Number of interpolated rotation points.
Definition api.h:675
Represents a single interpolated point on a rotation path.
Definition api.h:652
double azimuth
Azimuth angle in compass units.
Definition api.h:653
double elevation
Elevation angle in compass units.
Definition api.h:654
Represents a single waypoint for a motion path.
Definition api.h:615
double x
X coordinate in meters (East in ENU).
Definition api.h:617
double time
Time in seconds.
Definition api.h:616
double y
Y coordinate in meters (North in ENU).
Definition api.h:618
double z
Z coordinate in meters (Up/Altitude in ENU).
Definition api.h:619
Represents a single waypoint for a rotation path.
Definition api.h:627
double azimuth
Azimuth angle in compass units (0=North, pi/2 or 90=East).
Definition api.h:629
double elevation
Elevation angle in compass units (positive up).
Definition api.h:630
double time
Time in seconds.
Definition api.h:628