df3d399610
Switch CRC from CCITT (0x07) to DVB-S2 (0xD5) to match ELRS. Adopt ELRS USB frame format: [addr][length][type][payload][crc]. Update frame type constants to match current ELRS protocol values. New skeleton modules (stub implementations with TODO comments): - crsf_telemetry.h/.c: telemetry decoders (GPS, battery, link..) - crsf_stream.h/.c: incremental streaming frame reader - crsf_param.h/.c: parameter protocol (read/write/set_power) Retained old frame format as *_legacy functions for backward compatibility with existing telemetry tool and tests. Add cel_serial_find_elrs_port() and cel_serial_open_probe() stubs to serial module for port auto-detection and baud probing.
146 lines
3.3 KiB
C
146 lines
3.3 KiB
C
#pragma once
|
|
#include <stdint.h>
|
|
#include "celrs/crsf.h"
|
|
|
|
/* Telemetry frame types */
|
|
typedef enum {
|
|
CEL_TELEM_GPS = 0,
|
|
CEL_TELEM_VARIO = 1,
|
|
CEL_TELEM_BATTERY = 2,
|
|
CEL_TELEM_BARO = 3,
|
|
CEL_TELEM_AIRSPEED = 4,
|
|
CEL_TELEM_HEARTBEAT = 5,
|
|
CEL_TELEM_RPM = 6,
|
|
CEL_TELEM_TEMP = 7,
|
|
CEL_TELEM_VOLTAGES = 8,
|
|
CEL_TELEM_ESC = 9,
|
|
CEL_TELEM_LINK = 10,
|
|
CEL_TELEM_ATTITUDE = 11,
|
|
CEL_TELEM_FLIGHT_MODE = 12,
|
|
CEL_TELEM_PARAM = 13,
|
|
CEL_TELEM_UNKNOWN = 14,
|
|
} cel_telem_type;
|
|
|
|
/* GPS telemetry */
|
|
typedef struct {
|
|
float latitude_deg;
|
|
float longitude_deg;
|
|
float groundspeed_kmh;
|
|
float heading_deg;
|
|
float altitude_m;
|
|
uint8_t satellites;
|
|
} cel_telem_gps;
|
|
|
|
/* Vario (vertical speed) */
|
|
typedef struct {
|
|
int16_t vertical_speed_cms;
|
|
} cel_telem_vario;
|
|
|
|
/* Battery sensor */
|
|
typedef struct {
|
|
float voltage_v;
|
|
float current_a;
|
|
uint32_t capacity_mah;
|
|
uint8_t remaining_pct;
|
|
} cel_telem_battery;
|
|
|
|
/* Barometric altitude */
|
|
typedef struct {
|
|
float altitude_m;
|
|
int16_t vertical_speed_cms;
|
|
} cel_telem_baro;
|
|
|
|
/* Airspeed */
|
|
typedef struct {
|
|
float speed_kmh;
|
|
} cel_telem_airspeed;
|
|
|
|
/* Heartbeat */
|
|
typedef struct {
|
|
uint16_t origin_addr;
|
|
} cel_telem_heartbeat;
|
|
|
|
/* RPM sensor (up to 8 values) */
|
|
typedef struct {
|
|
uint8_t source;
|
|
int32_t values[8];
|
|
uint8_t count;
|
|
} cel_telem_rpm;
|
|
|
|
/* Temperature sensor (up to 8 values, deg C) */
|
|
typedef struct {
|
|
uint8_t source;
|
|
float values[8];
|
|
uint8_t count;
|
|
} cel_telem_temp;
|
|
|
|
/* Voltage cells (up to 8 values, volts) */
|
|
typedef struct {
|
|
uint8_t source;
|
|
float values[8];
|
|
uint8_t count;
|
|
} cel_telem_voltages;
|
|
|
|
/* ESC telemetry (BLHeli/KISS passthrough) */
|
|
typedef struct {
|
|
float voltage_v;
|
|
float current_a;
|
|
uint16_t consumed_mah;
|
|
uint32_t rpm;
|
|
uint8_t temp_c;
|
|
} cel_telem_esc;
|
|
|
|
/* Link statistics */
|
|
typedef struct {
|
|
uint8_t uplink_rssi1;
|
|
uint8_t uplink_rssi2;
|
|
uint8_t uplink_quality;
|
|
int8_t uplink_snr;
|
|
uint8_t active_antenna;
|
|
uint8_t rf_mode;
|
|
uint8_t uplink_power;
|
|
uint8_t downlink_rssi;
|
|
uint8_t downlink_qual;
|
|
int8_t downlink_snr;
|
|
} cel_telem_link;
|
|
|
|
/* Attitude (pitch/roll/yaw in radians) */
|
|
typedef struct {
|
|
float pitch_rad;
|
|
float roll_rad;
|
|
float yaw_rad;
|
|
} cel_telem_attitude;
|
|
|
|
/* Flight mode string */
|
|
typedef struct {
|
|
char name[32];
|
|
} cel_telem_flight_mode;
|
|
|
|
/* Union of all telemetry data types */
|
|
typedef union {
|
|
cel_telem_gps gps;
|
|
cel_telem_vario vario;
|
|
cel_telem_battery battery;
|
|
cel_telem_baro baro;
|
|
cel_telem_airspeed airspeed;
|
|
cel_telem_heartbeat heartbeat;
|
|
cel_telem_rpm rpm;
|
|
cel_telem_temp temp;
|
|
cel_telem_voltages voltages;
|
|
cel_telem_esc esc;
|
|
cel_telem_link link;
|
|
cel_telem_attitude attitude;
|
|
cel_telem_flight_mode flight_mode;
|
|
} cel_telem_data;
|
|
|
|
/* Parsed telemetry frame */
|
|
typedef struct {
|
|
cel_telem_type type;
|
|
cel_telem_data data;
|
|
} cel_telemetry;
|
|
|
|
/* Parse a CRSF frame's payload into a telemetry struct.
|
|
Returns 0 on success, -1 on unsupported type or bad payload length. */
|
|
int cel_crsf_telemetry_parse(cel_crsf_frame const* frame,
|
|
cel_telemetry* out);
|