Enpose API — C
Enpose 6-DoF tracking API
Loading...
Searching...
No Matches
enpose_api.h
1
21#pragma once
22
23#include <stddef.h>
24#include <stdint.h>
25#include <stdbool.h>
26
32#ifdef __cplusplus
33extern "C" {
34#endif
35
43
45typedef struct EnposeDeviceInfo {
46 char ip[46];
47 uint32_t serial;
50
66typedef struct EnposeMarkerPose {
67 uint64_t timestamp;
68 uint16_t marker_id;
69 double x;
70 double y;
71 double z;
72 double rotation[9];
75 uint8_t sensors;
85
88
97EnposeStatus enpose_discover(EnposeDeviceInfo **out_devices, size_t *out_count);
98
101
111EnposePoseStream *enpose_pose_stream_connect(const char *ip, bool create_thread);
112
124 bool block,
125 EnposeMarkerPose **out_poses,
126 size_t *out_count);
127
130
133
134#ifdef __cplusplus
135} /* extern "C" */
136#endif
/* enpose_c_api */
138
140/*
141 * Compile-time check that these declarations still describe the same memory
142 * layout as the Rust definitions they mirror (rust/src/ffi.rs carries the
143 * layout table and the list of mirrors). A field reordered or retyped on
144 * either side breaks the build here — in every C and C++ translation unit that
145 * includes this header, the C++ wrapper included — instead of silently
146 * misreading every device and pose at run time.
147 *
148 * Field widths are checked alongside the offsets: widening a field can leave
149 * every offset and the total size untouched by consuming the padding next to
150 * it (uint16_t -> uint32_t for marker_id, say), while the two sides then
151 * disagree about how many of those bytes carry the value.
152 *
153 * 64-bit targets only: a 32-bit x86 ABI aligns double to 4 and produces a
154 * different, equally valid layout. Skipped as well on pre-C11 compilers, which
155 * have no static assertion to use.
156 */
157#if defined(UINTPTR_MAX) && UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFULL
158
159#if defined(__cplusplus)
160#define ENPOSE_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
161#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
162#define ENPOSE_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
163#else
164/* Pre-C11: no static assertion to use. Expand to a harmless repeated
165 * declaration rather than to nothing, which would leave a stray semicolon at
166 * file scope. */
167#define ENPOSE_STATIC_ASSERT(cond, msg) extern int enpose_static_assert_unavailable
168#endif
169
170ENPOSE_STATIC_ASSERT(sizeof(EnposeStatus) == sizeof(int), "EnposeStatus is a C int");
171ENPOSE_STATIC_ASSERT(sizeof(bool) == 1, "bool crosses the ABI as one byte");
172
173/* Offset and width of one field, in one line. */
174#define ENPOSE_ASSERT_FIELD(type, field, off, width) \
175 ENPOSE_STATIC_ASSERT(offsetof(type, field) == (off), #type "." #field " offset"); \
176 ENPOSE_STATIC_ASSERT(sizeof(((type *)0)->field) == (width), #type "." #field " width")
177
178ENPOSE_STATIC_ASSERT(sizeof(EnposeDeviceInfo) == 56, "EnposeDeviceInfo size");
179ENPOSE_ASSERT_FIELD(EnposeDeviceInfo, ip, 0, 46);
180ENPOSE_ASSERT_FIELD(EnposeDeviceInfo, serial, 48, 4);
181ENPOSE_ASSERT_FIELD(EnposeDeviceInfo, compatible, 52, 1);
182
183ENPOSE_STATIC_ASSERT(sizeof(EnposeMarkerPose) == 136, "EnposeMarkerPose size");
184ENPOSE_ASSERT_FIELD(EnposeMarkerPose, timestamp, 0, 8);
185ENPOSE_ASSERT_FIELD(EnposeMarkerPose, marker_id, 8, 2);
186ENPOSE_ASSERT_FIELD(EnposeMarkerPose, x, 16, 8);
187ENPOSE_ASSERT_FIELD(EnposeMarkerPose, y, 24, 8);
188ENPOSE_ASSERT_FIELD(EnposeMarkerPose, z, 32, 8);
189ENPOSE_ASSERT_FIELD(EnposeMarkerPose, rotation, 40, 72);
190ENPOSE_ASSERT_FIELD(EnposeMarkerPose, position_rmse, 112, 8);
191ENPOSE_ASSERT_FIELD(EnposeMarkerPose, rotation_rmse, 120, 8);
192ENPOSE_ASSERT_FIELD(EnposeMarkerPose, sensors, 128, 1);
193ENPOSE_ASSERT_FIELD(EnposeMarkerPose, observed_emitters, 129, 1);
194
195#undef ENPOSE_ASSERT_FIELD
196
197#undef ENPOSE_STATIC_ASSERT
198
199#endif /* 64-bit target */
EnposeStatus enpose_discover(EnposeDeviceInfo **out_devices, size_t *out_count)
Discover Enpose devices on the local network.
void enpose_pose_stream_free(EnposePoseStream *stream)
Disconnect and free a pose stream handle.
EnposePoseStream * enpose_pose_stream_connect(const char *ip, bool create_thread)
Connect a pose stream to the device at ip (an IPv4 string).
void enpose_marker_pose_array_free(EnposeMarkerPose *poses, size_t count)
Release an array returned by enpose_pose_stream_receive().
EnposeStatus enpose_pose_stream_receive(EnposePoseStream *stream, bool block, EnposeMarkerPose **out_poses, size_t *out_count)
Return the poses received from the stream.
EnposeStatus
Result code returned by the fallible functions.
Definition enpose_api.h:37
struct EnposePoseStream EnposePoseStream
Opaque handle to a live pose stream.
Definition enpose_api.h:87
void enpose_device_info_array_free(EnposeDeviceInfo *devices, size_t count)
Release an array returned by enpose_discover().
@ ENPOSE_ERR_PANIC
Internal error; the call was aborted cleanly.
Definition enpose_api.h:41
@ ENPOSE_OK
The call succeeded.
Definition enpose_api.h:38
@ ENPOSE_ERR_IO
An I/O error occurred (e.g.
Definition enpose_api.h:40
@ ENPOSE_ERR_INVALID_ARG
A required argument was null/invalid.
Definition enpose_api.h:39
C view of one discovered device.
Definition enpose_api.h:45
char ip[46]
Null-terminated IPv4 address string.
Definition enpose_api.h:46
uint32_t serial
Factory serial number.
Definition enpose_api.h:47
bool compatible
True if the device's protocol version matches.
Definition enpose_api.h:48
Pose of one tracked marker in world coordinates.
Definition enpose_api.h:66
double rotation[9]
Row-major 3x3 rotation, model frame to world.
Definition enpose_api.h:72
uint64_t timestamp
Microseconds since the device started.
Definition enpose_api.h:67
uint16_t marker_id
Marker identifier.
Definition enpose_api.h:68
double z
Definition enpose_api.h:71
uint8_t sensors
Number of sensors that contributed.
Definition enpose_api.h:75
double x
World position in meters (first model emitter).
Definition enpose_api.h:69
double position_rmse
RMS position error, in meters (units of x/y/z).
Definition enpose_api.h:73
double rotation_rmse
RMS rotation error (radians, axis-angle magnitude).
Definition enpose_api.h:74
uint8_t observed_emitters
Number of marker emitters (LEDs) whose measurements contributed to this pose.
Definition enpose_api.h:83
double y
Definition enpose_api.h:70