Telemetry

Binary framing and high-level send / receive API.

Framing

Header: telemetry/tel_frame.h

enum tel_decode_state_t

Decoder state machine states.

Values:

enumerator TEL_DECODE_SYNC1

Waiting for first sync byte.

enumerator TEL_DECODE_SYNC2

Waiting for second sync byte.

enumerator TEL_DECODE_LEN_HI

Reading length high byte.

enumerator TEL_DECODE_LEN_LO

Reading length low byte.

enumerator TEL_DECODE_PAYLOAD

Accumulating payload bytes.

enumerator TEL_DECODE_CRC_HI

Reading CRC high byte.

enumerator TEL_DECODE_CRC_LO

Reading CRC low byte.

int tel_frame_encode(const uint8_t *payload, size_t payload_len, uint8_t *frame_buf, size_t frame_buf_len)

Encode a payload into a framed packet.

Parameters:
  • payload[in] Payload data.

  • payload_len[in] Payload length in bytes.

  • frame_buf[out] Output buffer for the complete frame.

  • frame_buf_len[in] Size of frame_buf.

Returns:

Total frame length on success, or -1 on error.

void tel_decoder_init(tel_decoder_t *dec)

Initialise the frame decoder.

Parameters:
  • dec[out] Decoder context.

int tel_decoder_feed(tel_decoder_t *dec, uint8_t byte)

Feed one byte to the decoder.

Parameters:
  • dec[inout] Decoder context.

  • byte[in] Received byte.

Returns:

1 when a complete valid frame is ready in dec->payload, 0 otherwise.

uint16_t tel_crc16(const uint8_t *data, size_t len)

Compute CRC-16/CCITT over a data buffer.

Parameters:
  • data[in] Input data.

  • len[in] Data length in bytes.

Returns:

CRC-16 value.

TEL_SYNC1

First sync byte.

TEL_SYNC2

Second sync byte.

TEL_MAX_PAYLOAD

Maximum payload bytes.

TEL_FRAME_OVERHEAD

sync(2) + len(2) + crc(2).

TEL_MAX_FRAME

Max frame size.

struct tel_decoder_t
#include <tel_frame.h>

Streaming frame decoder context.

Public Members

tel_decode_state_t state

Current decoder state.

uint8_t payload[256]

Payload accumulator.

uint16_t payload_len

Expected payload length.

uint16_t payload_idx

Bytes received so far.

uint16_t crc_received

CRC from the frame.

Send / Receive

Header: telemetry/tel_send.h

typedef int (*tel_transport_fn)(const uint8_t *data, size_t len)

Platform transport callback.

Param data:

[in] Bytes to transmit.

Param len:

[in] Number of bytes.

Return:

Number of bytes actually sent.

void tel_init(tel_ctx_t *ctx, tel_transport_fn send_fn)

Initialise telemetry context.

Parameters:
  • ctx[out] Telemetry context.

  • send_fn[in] Platform transport callback.

int tel_send_status(tel_ctx_t *ctx, const ecu_t *ecu, const ecu_outputs_t *out, const ecu_inputs_t *in)

Send a status update frame.

Parameters:
  • ctx[inout] Telemetry context.

  • ecu[in] Current ECU state.

  • out[in] Latest ECU outputs.

  • in[in] Latest ECU inputs.

Returns:

Number of bytes sent, or -1 on error.

int tel_process_byte(tel_ctx_t *ctx, uint8_t byte)

Process a received byte (from UART / socket).

Parameters:
  • ctx[inout] Telemetry context.

  • byte[in] Received byte.

Returns:

1 if a complete command was decoded, 0 otherwise.

int tel_get_throttle(const tel_ctx_t *ctx, float *throttle)

Retrieve the throttle override value, if any.

Parameters:
  • ctx[in] Telemetry context.

  • throttle[out] Receives the override value (0–100).

Returns:

1 if an override is present, 0 otherwise.

struct tel_ctx_t
#include <tel_send.h>

Telemetry context (one per link).

Public Members

tel_transport_fn send

Platform transport function.

tel_decoder_t decoder

Incoming frame decoder.

float throttle_override

Throttle value from host.

int has_throttle_override

Non-zero if override is set.