31#ifndef RCBENCH_OPENYGE_H
32#define RCBENCH_OPENYGE_H
44#define OPENYGE_SYNC 0xA5u
45#define OPENYGE_VERSION 3u
49#define OPENYGE_HDR_V3 6u
50#define OPENYGE_HDR_LEGACY 4u
51#define OPENYGE_CRC_BYTES 2u
53#define OPENYGE_TELEMETRY_BYTES 26u
54#define OPENYGE_CONTROL_BYTES 4u
60#define OPENYGE_MIN_FRAME (OPENYGE_HDR_LEGACY + OPENYGE_CRC_BYTES)
61#define OPENYGE_MAX_FRAME 140u
70#define OPENYGE_CRC_INIT 0x0000u
71#define OPENYGE_CRC_CHECK 0x31C3u
87uint16_t
openyge_crc(uint16_t crc,
const void *data,
size_t len);
90#define OPENYGE_DEV_MASTER 0x80u
91#define OPENYGE_DEV_ADDR_MASK 0x7Fu
92#define OPENYGE_DEV_BROADCAST 0x00u
97#define OPENYGE_TEMP_OFFSET 40
237size_t openyge_encode(uint8_t *out,
size_t cap, uint8_t type, uint8_t device,
238 uint8_t seq,
const void *payload,
size_t payload_len);
250 uint8_t device, uint8_t seq);
266 uint8_t seq, uint16_t index, uint16_t value);
272 OPENYGE_SUBJECT_ESC = 0,
283 OPENYGE_ST_DISARMED = 0x0,
284 OPENYGE_ST_POWER_CUT = 0x1,
285 OPENYGE_ST_FAST_START = 0x2,
286 OPENYGE_ST_ALIGN_FOR_POS = 0x4,
287 OPENYGE_ST_BRAKING_NORM_FINI = 0x6,
288 OPENYGE_ST_BRAKING_SYNC_FINI = 0x7,
289 OPENYGE_ST_STARTING = 0x8,
290 OPENYGE_ST_BRAKING_NORM = 0x9,
291 OPENYGE_ST_BRAKING_SYNC = 0xA,
292 OPENYGE_ST_WINDMILLING = 0xC,
293 OPENYGE_ST_RUNNING_NORM = 0xE,
310 bool warn_undervoltage;
312 bool warn_overcurrent;
320 bool fault_overvoltage;
321 bool fault_undervoltage;
323 bool fault_overcurrent;
348#define OPENYGE_MAX_PARAMS 64
356#define OPENYGE_P_COUNT 0
357#define OPENYGE_P_MOTOR_POLES 20
358#define OPENYGE_P_PINION_TEETH 21
359#define OPENYGE_P_MAIN_TEETH 22
bool openyge_telemetry_parse(const openyge_frame_t *f, openyge_telemetry_t *out)
Parse the telemetry payload.
Definition openyge_frame.c:301
void openyge_params_observe(openyge_params_t *p, uint16_t index, uint16_t value)
Record one (index, value) pair from a telemetry frame.
Definition openyge_params.c:17
size_t openyge_build_param_write(uint8_t *out, size_t cap, uint8_t device, uint8_t seq, uint16_t index, uint16_t value)
A single parameter write.
Definition openyge_frame.c:395
float openyge_params_progress(const openyge_params_t *p)
0..1, for a progress bar.
Definition openyge_params.c:92
bool openyge_params_complete(const openyge_params_t *p)
True once every index 0..count-1 has been seen and no write is pending.
Definition openyge_params.c:59
bool openyge_motor_rpm(const openyge_params_t *p, uint32_t erpm, float *motor_rpm)
Mechanical and head RPM (revolutions per minute) from eRPM (electrical RPM) and the gear train.
Definition openyge_params.c:107
bool openyge_params_get(const openyge_params_t *p, uint16_t index, uint16_t *out)
Read one.
Definition openyge_params.c:80
size_t openyge_build_telemetry_request(uint8_t *out, size_t cap, uint8_t device, uint8_t seq)
A telemetry request: the control payload, both words zero.
Definition openyge_frame.c:387
size_t openyge_encode(uint8_t *out, size_t cap, uint8_t type, uint8_t device, uint8_t seq, const void *payload, size_t payload_len)
Build a frame.
Definition openyge_frame.c:355
void openyge_params_reset(openyge_params_t *p)
Clear the parameter cache.
Definition openyge_params.c:10
const char * openyge_state_name(uint8_t state)
A short name for a motor state, or "?" for a reserved value.
Definition openyge_status.c:21
uint16_t openyge_crc(uint16_t crc, const void *data, size_t len)
Fold len bytes at data into crc and return the new accumulator.
Definition openyge_frame.c:88
openyge_state_t
The motor states.
Definition openyge.h:282
void openyge_decoder_reset(openyge_decoder_t *d)
Clear a decoder, buffer and counters.
Definition openyge_frame.c:104
bool openyge_decode_byte(openyge_decoder_t *d, uint8_t byte, openyge_frame_t *out)
Feed one received byte; returns true when out holds a whole good frame.
Definition openyge_frame.c:219
void openyge_status_decode(uint8_t status1, openyge_status_t *out)
Decode the status byte of a telemetry frame.
Definition openyge_status.c:39
openyge_subject_t
Which device the warning bits are talking about.
Definition openyge.h:271
void openyge_params_begin_writes(openyge_params_t *p)
Mark writes outstanding, which withdraws the table until it is re-read.
Definition openyge_params.c:37
bool openyge_head_rpm(const openyge_params_t *p, uint32_t erpm, float *head_rpm)
Head rpm from eRPM and the gear train.
Definition openyge_params.c:120
bool openyge_frame_has_telemetry(const openyge_frame_t *f)
True if this frame is one an ESC sends, i.e. one carrying telemetry.
Definition openyge_frame.c:295
openyge_frame_type_t
Frame type codes, the type byte of the header.
Definition openyge.h:100
@ OPENYGE_FT_TELE_REQ
Definition openyge.h:103
@ OPENYGE_FT_TELE_RESP
Definition openyge.h:102
@ OPENYGE_FT_TELE_AUTO
Definition openyge.h:101
@ OPENYGE_FT_WRITE_PARAM_REQ
Definition openyge.h:105
@ OPENYGE_FT_WRITE_PARAM_RESP
Definition openyge.h:104
void openyge_params_end_writes(openyge_params_t *p)
Clear the outstanding-writes mark.
Definition openyge_params.c:52
#define OPENYGE_MAX_FRAME
Definition openyge.h:61
#define OPENYGE_MAX_PARAMS
The bitmap that tracks which indices have been seen is 64 bits wide.
Definition openyge.h:348
bool openyge_control_parse(const openyge_frame_t *f, uint16_t *index, uint16_t *param)
Parse the 4-byte control payload of a request.
Definition openyge_frame.c:337
Byte buffer and counters of the resynchronising decoder.
Definition openyge.h:126
uint32_t rejected
Definition openyge.h:136
One decoded frame: header and payload.
Definition openyge.h:119
uint8_t payload[OPENYGE_MAX_FRAME]
Definition openyge.h:121
uint8_t payload_len
Definition openyge.h:122
uint16_t value[OPENYGE_MAX_PARAMS]
Definition openyge.h:362
uint64_t seen
Definition openyge.h:363
bool writes_pending
Definition openyge.h:367
Decoded status byte.
Definition openyge.h:297
bool state_known
Definition openyge.h:299
openyge_subject_t subject
Definition openyge.h:309
uint8_t state
Definition openyge.h:298
uint8_t status1
Definition openyge.h:177
uint8_t status2
Definition openyge.h:178
float amps
Definition openyge.h:166
float bec_volts
Definition openyge.h:171
uint16_t pidx
Definition openyge.h:179
uint16_t pdata
Definition openyge.h:180
int16_t temp_c
Definition openyge.h:173
int8_t throttle_pct
Definition openyge.h:170
int16_t cap_temp_c
Definition openyge.h:175
uint16_t consumption_mah
Definition openyge.h:167
int16_t bec_temp_c
Definition openyge.h:174
float volts
Definition openyge.h:165
int8_t pwm_pct
Definition openyge.h:169
float bec_amps
Definition openyge.h:172
uint32_t erpm
Definition openyge.h:168
int16_t aux_temp_c
Definition openyge.h:176