Inital commit
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* CRSF frame header byte */
|
||||
#define CEL_CRSF_FRAME_HEADER 0xC8
|
||||
|
||||
/* CRSF device addresses */
|
||||
#define CEL_CRSF_ADDRESS_FC_BROADCAST 0x00
|
||||
#define CEL_CRSF_ADDRESS_FC 0x10
|
||||
#define CEL_CRSF_ADDRESS_TBS_GROUND_STATION 0x80
|
||||
#define CEL_CRSF_ADDRESS_CUSTOM_MODULE 0xEA
|
||||
#define CEL_CRSF_ADDRESS_RC_DEVICE 0xDD
|
||||
#define CEL_CRSF_ADDRESS_GPS 0xEC
|
||||
#define CEL_CRSF_ADDRESS_FLIGHT_CONTROLLER 0xED
|
||||
|
||||
/* CRSF frame types */
|
||||
typedef enum {
|
||||
CEL_CRSF_FRAMETYPE_PACKET_LINK_TELEMETRY = 0x02,
|
||||
CEL_CRSF_FRAMETYPE_RC_CHANNELS_PACKED = 0x01,
|
||||
CEL_CRSF_FRAMETYPE_GPS = 0x02,
|
||||
CEL_CRSF_FRAMETYPE_HEARTBEAT = 0x03,
|
||||
CEL_CRSF_FRAMETYPE_VERSION = 0x04,
|
||||
CEL_CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY = 0x05,
|
||||
CEL_CRSF_FRAMETYPE_PARAMETER_READ = 0x06,
|
||||
CEL_CRSF_FRAMETYPE_PARAMETER_WRITE = 0x07,
|
||||
CEL_CRSF_FRAMETYPE_DEVICE_INFO = 0x08,
|
||||
CEL_CRSF_FRAMETYPE_PARAMETER_LIST = 0x09,
|
||||
CEL_CRSF_FRAMETYPE_RC_CHANNELS_RAW = 0x16,
|
||||
CEL_CRSF_FRAMETYPE_MSP_READ = 0x17,
|
||||
CEL_CRSF_FRAMETYPE_MSP_WRITE = 0x18,
|
||||
CEL_CRSF_FRAMETYPE_CURR_VOLTAGE_TEMP = 0x1E,
|
||||
CEL_CRSF_FRAMETYPE_BATTERY_SENSOR = 0x1F,
|
||||
CEL_CRSF_FRAMETYPE_COMPRESSED_SENSORS = 0x28,
|
||||
CEL_CRSF_FRAMETYPE_ARM = 0x0D,
|
||||
CEL_CRSF_FRAMETYPE_SETTING = 0x9E,
|
||||
CEL_CRSF_FRAMETYPE_SUPERBOX = 0xA0,
|
||||
CEL_CRSF_FRAMETYPE_DEVICE_SUPERBOX = 0xA1,
|
||||
} cel_crsf_frame_type;
|
||||
|
||||
/* Parsed CRSF frame */
|
||||
typedef struct {
|
||||
uint8_t destination;
|
||||
uint8_t source;
|
||||
uint8_t type;
|
||||
uint8_t size;
|
||||
uint8_t payload[255];
|
||||
uint8_t crc;
|
||||
} cel_crsf_frame;
|
||||
|
||||
/* CRC8 calculation over CRSF frame data (CCITT poly 0x07) */
|
||||
uint8_t cel_crsf_crc(uint8_t const* data, size_t len);
|
||||
|
||||
/* Validate CRC of a CRSF frame (header already stripped, starts at dest addr) */
|
||||
int cel_crsf_frame_validate(cel_crsf_frame const* frame);
|
||||
|
||||
/* Parse a raw buffer into a cel_crsf_frame. Returns 0 on success, -1 on error.
|
||||
buf should start with 0xC8 header. */
|
||||
int cel_crsf_frame_parse(cel_crsf_frame* frame, uint8_t const* buf, size_t len);
|
||||
|
||||
/* Build a CRSF frame into dst buffer. Returns total bytes written.
|
||||
dst must have space for at least 5 + size bytes (header, addr, src, type,
|
||||
size byte, payload, crc). */
|
||||
size_t cel_crsf_frame_build(uint8_t* dst, uint8_t destination, uint8_t source,
|
||||
uint8_t type, uint8_t const* payload, uint8_t size);
|
||||
Reference in New Issue
Block a user