22#define PV2_PROTO_VERSION 2u
23#define PV2_CMD_MAX_LEN 20u
26#define PV2_FT_STATE 0x01u
27#define PV2_FT_INIT 0x02u
28#define PV2_FT_STATUS 0x03u
29#define PV2_FT_REPLAY 0x04u
30#define PV2_FT_CAPS 0x05u
31#define PV2_FT_FLIGHT 0x06u
32#define PV2_FT_POWER 0x07u
33#define PV2_FT_NAV 0x08u
34#define PV2_FT_MOTORS 0x09u
35#define PV2_FT_SYSTEM 0x0Au
36#define PV2_FT_EVENT 0x0Bu
37#define PV2_FT_PARAM 0x0Cu
38#define PV2_FT_CALIB 0x0Du
39#define PV2_FT_ACK 0x0Eu
40#define PV2_FT_CHECKS 0x0Fu
42#define PV2_FT_LOG_ENTRY 0x10u
43#define PV2_FT_LOG_DATA 0x11u
44#define PV2_FT_CMD 0x20u
47#define PV2_OP_SEND_INIT 0x01u
48#define PV2_OP_STATE_DECIM 0x02u
49#define PV2_OP_HEARTBEAT 0x10u
50#define PV2_OP_RC 0x11u
51#define PV2_OP_ARM 0x12u
52#define PV2_OP_DISARM 0x13u
53#define PV2_OP_TAKEOFF 0x14u
54#define PV2_OP_LAND 0x15u
55#define PV2_OP_RTH 0x16u
56#define PV2_OP_HOLD 0x17u
57#define PV2_OP_KILL 0x18u
58#define PV2_OP_SET_MODE 0x19u
59#define PV2_OP_PARAM_GET 0x20u
60#define PV2_OP_PARAM_SET 0x21u
61#define PV2_OP_PARAM_SAVE 0x22u
62#define PV2_OP_PARAM_DEFAULTS 0x23u
63#define PV2_OP_PARAM_LIST 0x24u
64#define PV2_OP_CAL_START 0x30u
65#define PV2_OP_CAL_CAPTURE 0x31u
66#define PV2_OP_CAL_ABORT 0x32u
67#define PV2_OP_CAL_SAVE 0x33u
68#define PV2_OP_CAL_RESTORE 0x34u
69#define PV2_OP_CAL_SET_REF 0x35u
70#define PV2_OP_MOTOR_TEST 0x36u
71#define PV2_OP_MOTOR_REVERSE 0x37u
72#define PV2_OP_MOTOR_REMAP 0x38u
73#define PV2_OP_STREAM_RATES 0x40u
74#define PV2_OP_REQUEST 0x41u
75#define PV2_OP_SET_NAME 0x42u
76#define PV2_OP_SET_TIME 0x43u
77#define PV2_OP_LOG_LIST 0x50u
78#define PV2_OP_LOG_READ 0x51u
79#define PV2_OP_LOG_ERASE 0x52u
81#define PV2_ARM_MAGIC0 0xA5u
82#define PV2_ARM_MAGIC1 0x5Au
83#define PV2_PROPS_OFF_MAGIC 0x50u
107#define PV2_FS_APP_LINK (1u << 0)
108#define PV2_FS_RADIO (1u << 1)
109#define PV2_FS_BATTERY (1u << 2)
110#define PV2_FS_GEOFENCE (1u << 3)
111#define PV2_FS_GPS (1u << 4)
112#define PV2_FS_FLOW (1u << 5)
114#define PV2_FF_IN_AIR (1u << 0)
115#define PV2_FF_LANDED (1u << 1)
116#define PV2_FF_HOME_SET (1u << 2)
117#define PV2_FF_GEOFENCE_ON (1u << 3)
118#define PV2_FF_BEGINNER (1u << 4)
119#define PV2_FF_ARM_BLOCKED (1u << 5)
121#define PV2_S_IMU (1u << 0)
122#define PV2_S_BARO (1u << 1)
123#define PV2_S_MAG_FC (1u << 2)
124#define PV2_S_MAG_GPS (1u << 3)
125#define PV2_S_GNSS (1u << 4)
126#define PV2_S_FLOW (1u << 5)
127#define PV2_S_TOF (1u << 6)
128#define PV2_S_ESC_TLM (1u << 7)
129#define PV2_S_CURRENT (1u << 8)
130#define PV2_S_ELRS (1u << 9)
131#define PV2_S_LEDS (1u << 10)
132#define PV2_S_FLASH_LOG (1u << 11)
180 uint8_t
arm, mode, autom, failsafe;
210 int16_t vel_ned_cms[3];
265#define PV2_LOG_DATA_MAX 240u
268 uint8_t type, state, step,
progress, quality, reason;
273typedef struct { uint16_t remaining_ms; int16_t bias_mdps[3]; uint16_t noise_mdps; int16_t temp_cc; }
pv2_cal_gyro_t;
274typedef struct { uint8_t coverage[5]; uint8_t interf_fc, interf_gps, quality_fc, quality_gps; }
pv2_cal_compass_t;
275typedef struct { uint16_t tof_mm, height_mm; uint8_t flow_q, match_pct,
axes_done; uint16_t scale_x_e4, scale_y_e4; int16_t tof_offset_mm; }
pv2_cal_flow_t;
278typedef struct { uint16_t centre[4], min[4], max[4]; uint8_t aux_pos[4]; }
pv2_cal_sticks_t;
290#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
291_Static_assert(
sizeof(
pv2_caps_t) == 39,
"CAPS layout");
292_Static_assert(
sizeof(
pv2_flight_t) == 25,
"FLIGHT layout");
293_Static_assert(
sizeof(
pv2_power_t) == 13,
"POWER layout");
294_Static_assert(
sizeof(
pv2_nav_t) == 31,
"NAV layout");
295_Static_assert(
sizeof(
pv2_motor_t) == 4,
"MOTORS entry layout");
296_Static_assert(
sizeof(
pv2_system_t) == 23,
"SYSTEM layout");
298_Static_assert(
sizeof(
pv2_param_t) == 11,
"PARAM layout");
308_Static_assert(
sizeof(
pv2_ack_t) == 4,
"ACK layout");
309_Static_assert(
sizeof(
pv2_check_t) == 4,
"CHECKS item layout");
314#define PV2_EVENT_TEXT_MAX 40u
315#define PV2_CHECKS_MAX 12u
316#define PV2_MOTORS_MAX 8u
317#define PV2_PAYLOAD_MAX (2u + 4u * PV2_CHECKS_MAX)
320size_t pv2_frame(uint8_t type,
const void *payload, uint8_t len, uint8_t *out,
size_t cap);
321size_t pv2_event(uint8_t level, uint16_t code, int32_t arg,
const char *text, uint8_t *out,
size_t cap);
322size_t pv2_ack(uint8_t op, uint8_t
seq, uint8_t
result, uint8_t reason, uint8_t *out,
size_t cap);
323size_t pv2_param(uint16_t
id,
float value, uint8_t flags, uint16_t index, uint16_t count, uint8_t *out,
size_t cap);
329static inline uint16_t
pv2_rd_u16(
const uint8_t *p) {
return (uint16_t)(p[0] | ((uint16_t)p[1] << 8)); }
static void result(const fc_cmd_t *c, uint8_t res, uint8_t why)
static uint16_t pv2_rd_u16(const uint8_t *p)
little-endian readers for command payloads (unaligned-safe)
size_t pv2_calib(const pv2_calib_hdr_t *h, const void *data, uint8_t data_len, uint8_t *out, size_t cap)
size_t pv2_event(uint8_t level, uint16_t code, int32_t arg, const char *text, uint8_t *out, size_t cap)
@ PV2_R_NOT_OVER_USB
flight command received over the USB link: ground link only
@ PV2_R_USB_CONNECTED
ARM / TAKEOFF / MOTOR_TEST while a USB host is connected (ADR 0009)
@ PV2_R_OTHER_LINK
configuration change from the link that does not have control
@ PV2_R_PROPS_CONFIRM_MISSING
size_t pv2_ack(uint8_t op, uint8_t seq, uint8_t result, uint8_t reason, uint8_t *out, size_t cap)
@ PV2_E_BATTERY_EMERGENCY
@ PV2_E_TAKEOFF_ABORTED
firmware extension (WARN): no lift-off; the app shows the text
@ PV2_E_FAILSAFE_APP_LINK
@ PV2_E_BATTERY_MONITOR_LOST
firmware extension (ERROR): BattTask silent, battery unknown
float pv2_rd_f32(const uint8_t *p)
size_t pv2_param(uint16_t id, float value, uint8_t flags, uint16_t index, uint16_t count, uint8_t *out, size_t cap)
size_t pv2_motors(const pv2_motor_t *m, uint8_t n, uint8_t *out, size_t cap)
static int16_t pv2_rd_i16(const uint8_t *p)
size_t pv2_frame(uint8_t type, const void *payload, uint8_t len, uint8_t *out, size_t cap)
size_t pv2_checks(uint8_t ready, const pv2_check_t *items, uint8_t n, uint8_t *out, size_t cap)
@ PV2_CHK_USB
FAIL while a USB host is connected: no ARM.
uint8_t hw_rev
ASCII letter.
uint8_t id
< 0x0F CHECKS item (after ready u8, n u8)
uint8_t level
< 0x0B EVENT header, then text[len]
uint16_t ground_speed_cms
uint16_t home_bearing_cdeg
uint16_t home_dist_m
0xFFFF n/a
uint16_t rth_eta_s
0xFFFF n/a
uint16_t id
< 0x11 LOG_DATA header (USB), then data
uint32_t bytes
sectors × 4096
uint8_t flags
bit0 truncated (oldest, beginning overwritten), bit1 being written
uint32_t t0_ms
uptime when the log started
uint16_t id
< 0x10 LOG_ENTRY (USB)
uint8_t count
position in the list, list size
uint16_t rpm
< 0x09 MOTORS, one entry (after n u8)
uint16_t wind_cms
0xFFFF n/a
uint16_t tof_mm
0xFFFF n/a
uint8_t flags
bit0 dirty (RAM != flash), bit1 read-only
uint16_t vbat_mv
< 0x07 POWER
uint16_t remain_s
0xFFFF n/a
uint8_t est_flags
bit0 EKF ok, bit1 acc gated, bit2 mag gated, bit3 mag interference