Skip to content

File syn_xrce_dds.c

FileList > proto > syn_xrce_dds.c

Go to the source code of this file

Micro-ROS & eProsima Micro XRCE-DDS v1.2 Protocol Client Engine Implementation.

  • #include "../port/syn_port_system.h"
  • #include "syn_xrce_dds.h"
  • #include <string.h>

Public Functions

Type Name
bool syn_cdr_read_bool (SYN_CDR_Reader * r, bool * out)
Read boolean.
bool syn_cdr_read_bytes (SYN_CDR_Reader * r, uint8_t * out_buf, size_t len)
Read raw byte buffer without alignment padding.
bool syn_cdr_read_double (SYN_CDR_Reader * r, double * out)
Read 64-bit double (8-byte aligned).
bool syn_cdr_read_float (SYN_CDR_Reader * r, float * out)
Read 32-bit float (4-byte aligned).
bool syn_cdr_read_i16 (SYN_CDR_Reader * r, int16_t * out)
Read signed 16-bit integer (2-byte aligned).
bool syn_cdr_read_i32 (SYN_CDR_Reader * r, int32_t * out)
Read signed 32-bit integer (4-byte aligned).
bool syn_cdr_read_i64 (SYN_CDR_Reader * r, int64_t * out)
Read signed 64-bit integer (8-byte aligned).
bool syn_cdr_read_i8 (SYN_CDR_Reader * r, int8_t * out)
Read signed 8-bit integer.
bool syn_cdr_read_string (SYN_CDR_Reader * r, char * out_buf, size_t max_len)
Read null-terminated string with length prefix.
bool syn_cdr_read_u16 (SYN_CDR_Reader * r, uint16_t * out)
Read unsigned 16-bit integer (2-byte aligned).
bool syn_cdr_read_u32 (SYN_CDR_Reader * r, uint32_t * out)
Read unsigned 32-bit integer (4-byte aligned).
bool syn_cdr_read_u64 (SYN_CDR_Reader * r, uint64_t * out)
Read unsigned 64-bit integer (8-byte aligned).
bool syn_cdr_read_u8 (SYN_CDR_Reader * r, uint8_t * out)
Read unsigned 8-bit integer.
void syn_cdr_reader_init (SYN_CDR_Reader * r, const uint8_t * buf, size_t size)
Initialize CDR reader.
bool syn_cdr_write_bool (SYN_CDR_Writer * w, bool v)
Write boolean.
bool syn_cdr_write_bytes (SYN_CDR_Writer * w, const uint8_t * bytes, size_t len)
Write raw byte buffer without alignment padding.
bool syn_cdr_write_double (SYN_CDR_Writer * w, double v)
Write 64-bit double (8-byte aligned).
bool syn_cdr_write_float (SYN_CDR_Writer * w, float v)
Write 32-bit float (4-byte aligned).
bool syn_cdr_write_i16 (SYN_CDR_Writer * w, int16_t v)
Write signed 16-bit integer (2-byte aligned).
bool syn_cdr_write_i32 (SYN_CDR_Writer * w, int32_t v)
Write signed 32-bit integer (4-byte aligned).
bool syn_cdr_write_i64 (SYN_CDR_Writer * w, int64_t v)
Write signed 64-bit integer (8-byte aligned).
bool syn_cdr_write_i8 (SYN_CDR_Writer * w, int8_t v)
Write signed 8-bit integer.
bool syn_cdr_write_string (SYN_CDR_Writer * w, const char * str)
Write null-terminated string with 32-bit length prefix and null terminator.
bool syn_cdr_write_u16 (SYN_CDR_Writer * w, uint16_t v)
Write unsigned 16-bit integer (2-byte aligned).
bool syn_cdr_write_u32 (SYN_CDR_Writer * w, uint32_t v)
Write unsigned 32-bit integer (4-byte aligned).
bool syn_cdr_write_u64 (SYN_CDR_Writer * w, uint64_t v)
Write unsigned 64-bit integer (8-byte aligned).
bool syn_cdr_write_u8 (SYN_CDR_Writer * w, uint8_t v)
Write unsigned 8-bit integer.
void syn_cdr_writer_init (SYN_CDR_Writer * w, uint8_t * buf, size_t size)
Initialize CDR writer.
SYN_Status syn_xrce_client_create_datareader (SYN_XRCE_Client * client, uint16_t reader_id, uint16_t subscriber_id, uint16_t topic_id)
Create a DDS DataReader entity.
SYN_Status syn_xrce_client_create_datawriter (SYN_XRCE_Client * client, uint16_t writer_id, uint16_t publisher_id, uint16_t topic_id)
Create a DDS DataWriter entity.
SYN_Status syn_xrce_client_create_participant (SYN_XRCE_Client * client, uint16_t participant_id)
Create a DDS DomainParticipant entity.
SYN_Status syn_xrce_client_create_publisher (SYN_XRCE_Client * client, uint16_t publisher_id, uint16_t participant_id)
Create a DDS Publisher entity.
SYN_Status syn_xrce_client_create_session (SYN_XRCE_Client * client)
Connect and establish session with Micro-ROS Agent.
SYN_Status syn_xrce_client_create_subscriber (SYN_XRCE_Client * client, uint16_t subscriber_id, uint16_t participant_id)
Create a DDS Subscriber entity.
SYN_Status syn_xrce_client_create_topic (SYN_XRCE_Client * client, uint16_t topic_id, uint16_t participant_id, const char * topic_name, const char * type_name)
Create a DDS Topic entity.
SYN_Status syn_xrce_client_init (SYN_XRCE_Client * client, const SYN_XRCE_Config * cfg)
Initialize Micro XRCE-DDS Client.
SYN_PT_Status syn_xrce_client_pt (SYN_PT * pt, SYN_Task * task)
Protothread continuation function for syn_sched .
SYN_Status syn_xrce_client_read_data (SYN_XRCE_Client * client, uint16_t reader_id)
Request incoming topic samples from an active DataReader.
SYN_Status syn_xrce_client_step (SYN_XRCE_Client * client, uint32_t now_ms)
Advance the XRCE-DDS client state machine by one step / tick.
SYN_Status syn_xrce_client_write_data (SYN_XRCE_Client * client, uint16_t writer_id, const uint8_t * data, size_t len)
Publish CDR serialized data payload to a DataWriter.

Public Static Functions

Type Name
size_t cdr_pad_reader (SYN_CDR_Reader * r, size_t align)
Align CDR reader position to specified byte boundary.
size_t cdr_pad_writer (SYN_CDR_Writer * w, size_t align)
Align CDR writer position to specified byte boundary with zero padding.
void xrce_finish_submessage (SYN_CDR_Writer * w, size_t len_pos)
Finish XRCE submessage and patch calculated payload length.
SYN_Status xrce_register_local_object (SYN_XRCE_Client * client, uint16_t id, uint8_t kind, uint16_t parent)
Register local XRCE object in client's internal entity table.
size_t xrce_start_submessage (SYN_CDR_Writer * w, uint8_t submsg_id, uint8_t flags)
Start XRCE submessage with 4-byte header and return length patch offset.
void xrce_write_header (SYN_CDR_Writer * w, uint8_t session_id, uint8_t stream_id, uint16_t seq_num, uint32_t client_key)
Write XRCE message header to CDR stream.

Macros

Type Name
define SYN_XRCE_DATA_FORMAT_DATA 0x00U
XRCE data submessage format: Raw Data payload.
define SYN_XRCE_DEFAULT_HEARTBEAT_MS 5000U
Default client heartbeat period in milliseconds.
define SYN_XRCE_FLAG_LITTLE_ENDIAN 0x01U
XRCE submessage little-endian endianness flag.
define SYN_XRCE_REPRESENTATION_AS_STRING 0x02U
XRCE object representation as string / XML.
define SYN_XRCE_REPRESENTATION_BY_REF 0x01U
XRCE object representation by reference.

Public Functions Documentation

function syn_cdr_read_bool

Read boolean.

bool syn_cdr_read_bool (
    SYN_CDR_Reader * r,
    bool * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_bytes

Read raw byte buffer without alignment padding.

bool syn_cdr_read_bytes (
    SYN_CDR_Reader * r,
    uint8_t * out_buf,
    size_t len
) 

Parameters:

  • r Reader context.
  • out_buf Output buffer.
  • len Number of bytes to read.

Returns:

true on success, false on underflow.


function syn_cdr_read_double

Read 64-bit double (8-byte aligned).

bool syn_cdr_read_double (
    SYN_CDR_Reader * r,
    double * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_float

Read 32-bit float (4-byte aligned).

bool syn_cdr_read_float (
    SYN_CDR_Reader * r,
    float * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_i16

Read signed 16-bit integer (2-byte aligned).

bool syn_cdr_read_i16 (
    SYN_CDR_Reader * r,
    int16_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_i32

Read signed 32-bit integer (4-byte aligned).

bool syn_cdr_read_i32 (
    SYN_CDR_Reader * r,
    int32_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_i64

Read signed 64-bit integer (8-byte aligned).

bool syn_cdr_read_i64 (
    SYN_CDR_Reader * r,
    int64_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_i8

Read signed 8-bit integer.

bool syn_cdr_read_i8 (
    SYN_CDR_Reader * r,
    int8_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_string

Read null-terminated string with length prefix.

bool syn_cdr_read_string (
    SYN_CDR_Reader * r,
    char * out_buf,
    size_t max_len
) 

Parameters:

  • r Reader context.
  • out_buf Output string buffer.
  • max_len Capacity of output string buffer.

Returns:

true on success, false on underflow/truncation.


function syn_cdr_read_u16

Read unsigned 16-bit integer (2-byte aligned).

bool syn_cdr_read_u16 (
    SYN_CDR_Reader * r,
    uint16_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_u32

Read unsigned 32-bit integer (4-byte aligned).

bool syn_cdr_read_u32 (
    SYN_CDR_Reader * r,
    uint32_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_u64

Read unsigned 64-bit integer (8-byte aligned).

bool syn_cdr_read_u64 (
    SYN_CDR_Reader * r,
    uint64_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_read_u8

Read unsigned 8-bit integer.

bool syn_cdr_read_u8 (
    SYN_CDR_Reader * r,
    uint8_t * out
) 

Parameters:

  • r Reader context.
  • out Output pointer.

Returns:

true on success, false on underflow.


function syn_cdr_reader_init

Initialize CDR reader.

void syn_cdr_reader_init (
    SYN_CDR_Reader * r,
    const uint8_t * buf,
    size_t size
) 

Parameters:

  • r Reader context.
  • buf Input buffer.
  • size Buffer size.

function syn_cdr_write_bool

Write boolean.

bool syn_cdr_write_bool (
    SYN_CDR_Writer * w,
    bool v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_bytes

Write raw byte buffer without alignment padding.

bool syn_cdr_write_bytes (
    SYN_CDR_Writer * w,
    const uint8_t * bytes,
    size_t len
) 

Parameters:

  • w Writer context.
  • bytes Data buffer.
  • len Number of bytes.

Returns:

true on success, false on overflow.


function syn_cdr_write_double

Write 64-bit double (8-byte aligned).

bool syn_cdr_write_double (
    SYN_CDR_Writer * w,
    double v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_float

Write 32-bit float (4-byte aligned).

bool syn_cdr_write_float (
    SYN_CDR_Writer * w,
    float v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_i16

Write signed 16-bit integer (2-byte aligned).

bool syn_cdr_write_i16 (
    SYN_CDR_Writer * w,
    int16_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_i32

Write signed 32-bit integer (4-byte aligned).

bool syn_cdr_write_i32 (
    SYN_CDR_Writer * w,
    int32_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_i64

Write signed 64-bit integer (8-byte aligned).

bool syn_cdr_write_i64 (
    SYN_CDR_Writer * w,
    int64_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_i8

Write signed 8-bit integer.

bool syn_cdr_write_i8 (
    SYN_CDR_Writer * w,
    int8_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_string

Write null-terminated string with 32-bit length prefix and null terminator.

bool syn_cdr_write_string (
    SYN_CDR_Writer * w,
    const char * str
) 

Parameters:

  • w Writer context.
  • str String pointer.

Returns:

true on success, false on overflow.


function syn_cdr_write_u16

Write unsigned 16-bit integer (2-byte aligned).

bool syn_cdr_write_u16 (
    SYN_CDR_Writer * w,
    uint16_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_u32

Write unsigned 32-bit integer (4-byte aligned).

bool syn_cdr_write_u32 (
    SYN_CDR_Writer * w,
    uint32_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_u64

Write unsigned 64-bit integer (8-byte aligned).

bool syn_cdr_write_u64 (
    SYN_CDR_Writer * w,
    uint64_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_write_u8

Write unsigned 8-bit integer.

bool syn_cdr_write_u8 (
    SYN_CDR_Writer * w,
    uint8_t v
) 

Parameters:

  • w Writer context.
  • v Value.

Returns:

true on success, false on overflow.


function syn_cdr_writer_init

Initialize CDR writer.

void syn_cdr_writer_init (
    SYN_CDR_Writer * w,
    uint8_t * buf,
    size_t size
) 

Parameters:

  • w Writer context.
  • buf Target buffer.
  • size Buffer size.

function syn_xrce_client_create_datareader

Create a DDS DataReader entity.

SYN_Status syn_xrce_client_create_datareader (
    SYN_XRCE_Client * client,
    uint16_t reader_id,
    uint16_t subscriber_id,
    uint16_t topic_id
) 

Parameters:

  • client Client instance.
  • reader_id Object ID for the reader.
  • subscriber_id Parent subscriber ID.
  • topic_id Associated topic ID.

Returns:

SYN_OK on success.


function syn_xrce_client_create_datawriter

Create a DDS DataWriter entity.

SYN_Status syn_xrce_client_create_datawriter (
    SYN_XRCE_Client * client,
    uint16_t writer_id,
    uint16_t publisher_id,
    uint16_t topic_id
) 

Parameters:

  • client Client instance.
  • writer_id Object ID for the writer.
  • publisher_id Parent publisher ID.
  • topic_id Associated topic ID.

Returns:

SYN_OK on success.


function syn_xrce_client_create_participant

Create a DDS DomainParticipant entity.

SYN_Status syn_xrce_client_create_participant (
    SYN_XRCE_Client * client,
    uint16_t participant_id
) 

Parameters:

  • client Client instance.
  • participant_id Object ID for the participant.

Returns:

SYN_OK on success.


function syn_xrce_client_create_publisher

Create a DDS Publisher entity.

SYN_Status syn_xrce_client_create_publisher (
    SYN_XRCE_Client * client,
    uint16_t publisher_id,
    uint16_t participant_id
) 

Parameters:

  • client Client instance.
  • publisher_id Object ID for the publisher.
  • participant_id Parent participant ID.

Returns:

SYN_OK on success.


function syn_xrce_client_create_session

Connect and establish session with Micro-ROS Agent.

SYN_Status syn_xrce_client_create_session (
    SYN_XRCE_Client * client
) 

Parameters:

  • client Client instance.

Returns:

SYN_OK on success, SYN_ERROR on transport failure.


function syn_xrce_client_create_subscriber

Create a DDS Subscriber entity.

SYN_Status syn_xrce_client_create_subscriber (
    SYN_XRCE_Client * client,
    uint16_t subscriber_id,
    uint16_t participant_id
) 

Parameters:

  • client Client instance.
  • subscriber_id Object ID for the subscriber.
  • participant_id Parent participant ID.

Returns:

SYN_OK on success.


function syn_xrce_client_create_topic

Create a DDS Topic entity.

SYN_Status syn_xrce_client_create_topic (
    SYN_XRCE_Client * client,
    uint16_t topic_id,
    uint16_t participant_id,
    const char * topic_name,
    const char * type_name
) 

Parameters:

  • client Client instance.
  • topic_id Object ID for the topic.
  • participant_id Parent participant ID.
  • topic_name ROS 2 topic name (e.g. "sensors/imu").
  • type_name ROS 2 type identifier (e.g. "sensor_msgs::msg::dds_::Imu_").

Returns:

SYN_OK on success.


function syn_xrce_client_init

Initialize Micro XRCE-DDS Client.

SYN_Status syn_xrce_client_init (
    SYN_XRCE_Client * client,
    const SYN_XRCE_Config * cfg
) 

Parameters:

  • client Client context to initialize.
  • cfg Configuration options and buffers.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid argument.


function syn_xrce_client_pt

Protothread continuation function for syn_sched .

SYN_PT_Status syn_xrce_client_pt (
    SYN_PT * pt,
    SYN_Task * task
) 

Parameters:

  • pt Protothread continuation structure.
  • task Task handle containing SYN_XRCE_Client in user_data.

Returns:

SYN_PT_Status continuation status.


function syn_xrce_client_read_data

Request incoming topic samples from an active DataReader.

SYN_Status syn_xrce_client_read_data (
    SYN_XRCE_Client * client,
    uint16_t reader_id
) 

Parameters:

  • client Client instance.
  • reader_id DataReader entity ID.

Returns:

SYN_OK on success.


function syn_xrce_client_step

Advance the XRCE-DDS client state machine by one step / tick.

SYN_Status syn_xrce_client_step (
    SYN_XRCE_Client * client,
    uint32_t now_ms
) 

Parameters:

  • client Client instance.
  • now_ms Current timestamp in milliseconds.

Returns:

SYN_OK on success.


function syn_xrce_client_write_data

Publish CDR serialized data payload to a DataWriter.

SYN_Status syn_xrce_client_write_data (
    SYN_XRCE_Client * client,
    uint16_t writer_id,
    const uint8_t * data,
    size_t len
) 

Parameters:

  • client Client instance.
  • writer_id DataWriter entity ID.
  • data CDR payload buffer.
  • len Payload length.

Returns:

SYN_OK on success.


Public Static Functions Documentation

function cdr_pad_reader

Align CDR reader position to specified byte boundary.

static size_t cdr_pad_reader (
    SYN_CDR_Reader * r,
    size_t align
) 

Parameters:

  • r Reader context.
  • align Alignment boundary in bytes (2, 4, 8).

Returns:

Updated buffer position.


function cdr_pad_writer

Align CDR writer position to specified byte boundary with zero padding.

static size_t cdr_pad_writer (
    SYN_CDR_Writer * w,
    size_t align
) 

Parameters:

  • w Writer context.
  • align Alignment boundary in bytes (2, 4, 8).

Returns:

Updated buffer position.


function xrce_finish_submessage

Finish XRCE submessage and patch calculated payload length.

static void xrce_finish_submessage (
    SYN_CDR_Writer * w,
    size_t len_pos
) 

Parameters:

  • w Writer context.
  • len_pos Byte offset of submessage length field.

function xrce_register_local_object

Register local XRCE object in client's internal entity table.

static SYN_Status xrce_register_local_object (
    SYN_XRCE_Client * client,
    uint16_t id,
    uint8_t kind,
    uint16_t parent
) 

Parameters:

  • client Client instance pointer.
  • id Object identifier.
  • kind Object kind (participant, topic, publisher, etc.).
  • parent Parent object identifier.

Returns:

SYN_OK on success, SYN_ERROR on table overflow.


function xrce_start_submessage

Start XRCE submessage with 4-byte header and return length patch offset.

static size_t xrce_start_submessage (
    SYN_CDR_Writer * w,
    uint8_t submsg_id,
    uint8_t flags
) 

Parameters:

  • w Writer context.
  • submsg_id Submessage identifier.
  • flags Submessage flags.

Returns:

Byte offset of submessage length field for later patching.


function xrce_write_header

Write XRCE message header to CDR stream.

static void xrce_write_header (
    SYN_CDR_Writer * w,
    uint8_t session_id,
    uint8_t stream_id,
    uint16_t seq_num,
    uint32_t client_key
) 

Parameters:

  • w Writer context.
  • session_id XRCE session identifier.
  • stream_id XRCE stream identifier.
  • seq_num Stream sequence number.
  • client_key 32-bit client key.

Macro Definition Documentation

define SYN_XRCE_DATA_FORMAT_DATA

XRCE data submessage format: Raw Data payload.

#define SYN_XRCE_DATA_FORMAT_DATA `0x00U`


define SYN_XRCE_DEFAULT_HEARTBEAT_MS

Default client heartbeat period in milliseconds.

#define SYN_XRCE_DEFAULT_HEARTBEAT_MS `5000U`


define SYN_XRCE_FLAG_LITTLE_ENDIAN

XRCE submessage little-endian endianness flag.

#define SYN_XRCE_FLAG_LITTLE_ENDIAN `0x01U`


define SYN_XRCE_REPRESENTATION_AS_STRING

XRCE object representation as string / XML.

#define SYN_XRCE_REPRESENTATION_AS_STRING `0x02U`


define SYN_XRCE_REPRESENTATION_BY_REF

XRCE object representation by reference.

#define SYN_XRCE_REPRESENTATION_BY_REF `0x01U`



The documentation for this class was generated from the following file src/syntropic/proto/syn_xrce_dds.c