|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
SPDX-License-Identifier: MIT. More...
Enumerations | |
| enum | parse_result_t { PARSE_INVALID = -1 , PARSE_INCOMPLETE = 0 , PARSE_OK = 1 } |
| Outcome of examining one sync candidate. More... | |
Functions | |
| static uint16_t | rd16 (const uint8_t *p) |
| Little-endian, assembled byte by byte rather than cast; see the header. | |
| static void | wr16 (uint8_t *p, uint16_t v) |
| Write a little-endian 16-bit field. | |
| static bool | type_is_known (uint8_t t) |
| Whether a type byte is one of the frame types this speaks. | |
| static bool | type_carries_telemetry (uint8_t t) |
| A frame from the ESC (electronic speed controller) carries telemetry; one from the master carries the 4-byte control payload. | |
| static uint8_t | header_bytes (uint8_t version) |
| Header length for a protocol version. | |
| 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. | |
| void | openyge_decoder_reset (openyge_decoder_t *d) |
| Clear a decoder, buffer and counters. | |
| static parse_result_t | parse_at (const openyge_decoder_t *d, size_t at, openyge_frame_t *out, size_t *total_out, bool *crc_failed, bool *rejected) |
Examine the candidate frame starting at at without modifying the decoder, so several candidates can be weighed before one is committed to. | |
| static void | drop (openyge_decoder_t *d, size_t n) |
Discard the first n bytes of the decoder buffer. | |
| 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. | |
| bool | openyge_frame_has_telemetry (const openyge_frame_t *f) |
| True if this frame is one an ESC sends, i.e. one carrying telemetry. | |
| bool | openyge_telemetry_parse (const openyge_frame_t *f, openyge_telemetry_t *out) |
| Parse the telemetry payload. | |
| bool | openyge_control_parse (const openyge_frame_t *f, uint16_t *index, uint16_t *param) |
| Parse the 4-byte control payload of a request. | |
| 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. | |
| 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. | |
| 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. | |
SPDX-License-Identifier: MIT.
| enum parse_result_t |
|
static |
Discard the first n bytes of the decoder buffer.
| d | Decoder holding the buffer. |
| n | Bytes to discard; more than the buffer holds empties it. |
|
static |
Header length for a protocol version.
| version | Version byte from the header. |
| 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.
One parameter per frame; there is no page write.
| out | Buffer to write the frame into. |
| cap | Size of out in bytes. |
| device | Device address, without the master bit. |
| seq | Sequence number. |
| index | Parameter index. |
| value | Value to write. |
| 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.
| out | Buffer to write the frame into. |
| cap | Size of out in bytes. |
| device | Device address, without the master bit. |
| seq | Sequence number. |
| bool openyge_control_parse | ( | const openyge_frame_t * | f, |
| uint16_t * | index, | ||
| uint16_t * | param ) |
Parse the 4-byte control payload of a request.
| f | Decoded frame. |
| index | Receives the parameter index; NULL to skip. |
| param | Receives the parameter value; NULL to skip. |
| 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.
A frame's CRC is openyge_crc(OPENYGE_CRC_INIT, frame, total - 2), stored little-endian in the frame's last 2 bytes. Incremental: folding a buffer in pieces gives what folding it whole gives. A len of 0 returns crc and reads nothing.
| crc | Accumulator from an earlier call, or OPENYGE_CRC_INIT. |
| data | Bytes to fold. |
| len | Number of bytes in data. |
| 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.
Resynchronising: noise carrying a plausible sync byte in front of a real frame must not swallow the real one. Every sync byte in the buffer is a candidate and the earliest complete candidate wins.
| d | Decoder state. |
| byte | Received byte. |
| out | Receives the frame when true is returned. |
| void openyge_decoder_reset | ( | openyge_decoder_t * | d | ) |
Clear a decoder, buffer and counters.
| d | Decoder to clear; NULL does nothing. |
| 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.
Returns its length, or 0 if it would not fit or the type is not one this speaks.
The length byte is written from what was assembled, after the bounds check, so a frame that does not fit leaves the buffer untouched.
| out | Buffer to write the frame into. |
| cap | Size of out in bytes. |
| type | One of openyge_frame_type_t. |
| device | Device address, without the master bit. |
| seq | Sequence number. |
| payload | Payload bytes. |
| payload_len | Payload length; must match the type's payload size. |
| bool openyge_frame_has_telemetry | ( | const openyge_frame_t * | f | ) |
True if this frame is one an ESC sends, i.e. one carrying telemetry.
| f | Decoded frame. |
| bool openyge_telemetry_parse | ( | const openyge_frame_t * | f, |
| openyge_telemetry_t * | out ) |
Parse the telemetry payload.
False if the frame does not carry one.
| f | Decoded frame. |
| out | Receives the telemetry. |
out is NULL.
|
static |
Examine the candidate frame starting at at without modifying the decoder, so several candidates can be weighed before one is committed to.
| d | Decoder holding the buffer. |
| at | Index of the sync byte of the candidate. |
| out | Receives the frame when PARSE_OK; NULL to skip. |
| total_out | Receives the frame length when PARSE_OK. |
| crc_failed | Set to true when the CRC does not match. |
| rejected | Set to true when the CRC holds but the payload length does not fit the frame type. |
|
inlinestatic |
Little-endian, assembled byte by byte rather than cast; see the header.
| p | Two bytes, least significant first. |
|
static |
A frame from the ESC (electronic speed controller) carries telemetry; one from the master carries the 4-byte control payload.
The parameter-write acknowledgement is an ESC frame and carries telemetry too.
| t | Type byte from the header. |
|
static |
Whether a type byte is one of the frame types this speaks.
| t | Type byte from the header. |
|
inlinestatic |
Write a little-endian 16-bit field.
| p | Two bytes to write, least significant first. |
| v | The 16-bit value. |