openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
aliro_uwb_msg_builder.c File Reference

— big-endian TLV message builder. More...

#include "aliro_uwb_msg_builder.h"
#include "woz_alloc.h"
#include <string.h>
Include dependency graph for aliro_uwb_msg_builder.c:

Functions

bool aliro_uwb_msg_builder_init (struct aliro_uwb_msg_builder *builder, uint16_t payload_len)
 Allocate a message with room for the given payload length plus header.
 
void aliro_uwb_msg_builder_header (struct aliro_uwb_msg_builder *builder, uint8_t protocol, uint8_t id, uint16_t payload_length)
 Append the 4-byte header (protocol, id, big-endian payload length).
 
static bool add_attribute (struct aliro_uwb_msg_builder *builder, uint8_t id, uint8_t length, const uint8_t *value)
 Append id + length + raw value bytes, refusing to overrun the allocation.
 
bool aliro_uwb_msg_builder_add_u8 (struct aliro_uwb_msg_builder *builder, uint8_t id, uint8_t value)
 Append a 1-byte-value attribute.
 
bool aliro_uwb_msg_builder_add_u16 (struct aliro_uwb_msg_builder *builder, uint8_t id, uint16_t value)
 Append a 2-byte big-endian attribute.
 
bool aliro_uwb_msg_builder_add_u32 (struct aliro_uwb_msg_builder *builder, uint8_t id, uint32_t value)
 Append a 4-byte big-endian attribute.
 
bool aliro_uwb_msg_builder_add_u64 (struct aliro_uwb_msg_builder *builder, uint8_t id, uint64_t value)
 Append a 8-byte big-endian attribute.
 
bool aliro_uwb_msg_builder_add_u16_array (struct aliro_uwb_msg_builder *builder, uint8_t id, size_t count, const uint16_t *values)
 Append an attribute whose value is count big-endian 16-bit words.
 
bool aliro_uwb_msg_builder_add_bytes (struct aliro_uwb_msg_builder *builder, uint8_t id, size_t count, const uint8_t *values)
 Append an attribute whose value is count raw bytes.
 

Detailed Description

— big-endian TLV message builder.

Function Documentation

◆ add_attribute()

static bool add_attribute ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
uint8_t  length,
const uint8_t *  value 
)
static

Append id + length + raw value bytes, refusing to overrun the allocation.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
lengthLength of the attribute value in bytes.
valuePointer to the attribute value bytes to copy, may be NULL if length is 0.
Returns
true if the attribute was appended, false if it would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_add_bytes()

bool aliro_uwb_msg_builder_add_bytes ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
size_t  count,
const uint8_t *  values 
)

Append an attribute whose value is count raw bytes.

Append an attribute whose value is count raw bytes.

◆ aliro_uwb_msg_builder_add_u16()

bool aliro_uwb_msg_builder_add_u16 ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
uint16_t  value 
)

Append a 2-byte big-endian attribute.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
value16-bit value to append, encoded big-endian.
Returns
true if the attribute was appended, false if it would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_add_u16_array()

bool aliro_uwb_msg_builder_add_u16_array ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
size_t  count,
const uint16_t *  values 
)

Append an attribute whose value is count big-endian 16-bit words.

Append an attribute whose value is count big-endian 16-bit words.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
countNumber of 16-bit words in the values array.
valuesPointer to the array of 16-bit values to append.
Returns
true if the attribute was appended, false if count is 0, values is NULL, or the attribute would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_add_u32()

bool aliro_uwb_msg_builder_add_u32 ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
uint32_t  value 
)

Append a 4-byte big-endian attribute.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
value32-bit value to append, encoded big-endian.
Returns
true if the attribute was appended, false if it would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_add_u64()

bool aliro_uwb_msg_builder_add_u64 ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
uint64_t  value 
)

Append a 8-byte big-endian attribute.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
value64-bit value to append, encoded big-endian.
Returns
true if the attribute was appended, false if it would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_add_u8()

bool aliro_uwb_msg_builder_add_u8 ( struct aliro_uwb_msg_builder builder,
uint8_t  id,
uint8_t  value 
)

Append a 1-byte-value attribute.

Parameters
builderMessage builder to append the attribute to.
idAttribute identifier byte.
value1-byte value to append.
Returns
true if the attribute was appended, false if it would overrun the builder's capacity.

◆ aliro_uwb_msg_builder_header()

void aliro_uwb_msg_builder_header ( struct aliro_uwb_msg_builder builder,
uint8_t  protocol,
uint8_t  id,
uint16_t  payload_length 
)

Append the 4-byte header (protocol, id, big-endian payload length).

Parameters
builderMessage builder to append the header to.
protocolProtocol identifier byte.
idMessage identifier byte.
payload_lengthPayload length, written big-endian.

◆ aliro_uwb_msg_builder_init()

bool aliro_uwb_msg_builder_init ( struct aliro_uwb_msg_builder builder,
uint16_t  payload_len 
)

Allocate a message with room for the given payload length plus header.

Allocate a message with room for payload_len payload bytes plus header.

Parameters
builderMessage builder to initialize.
payload_lenNumber of payload bytes to reserve, in addition to the header.
Returns
true on successful allocation, false if allocation failed.