CommRaT 2.0.0
C++20 Real-Time Messaging Framework
Loading...
Searching...
No Matches
commrat::CommRaT< MessageDefs > Class Template Reference

CommRaT Application Template - Main User-Facing Interface. More...

#include <commrat/commrat.hpp>

Inheritance diagram for commrat::CommRaT< MessageDefs >:
commrat::MessageRegistry< MessageDefs... >

Public Types

using payload_types = typename Registry::PayloadTypes
 
template<typename OutputSpec_ , typename InputSpec_ , typename... CommandTypes>
using Module = commrat::Module< Registry, OutputSpec_, InputSpec_, CommandTypes... >
 Module template - create modules for this application.
 
template<typename PayloadT >
using Mailbox = RegistryMailbox< Registry >
 Mailbox template - create mailboxes for this application.
 
template<std::size_t HistorySize>
using HistoricalMailbox = commrat::HistoricalMailbox< Registry, HistorySize >
 HistoricalMailbox template - mailbox with time-synchronized getData()
 
using Introspection = IntrospectionHelper< CommRaT >
 Introspection helper - export message schemas to any format.
 
- Public Types inherited from commrat::MessageRegistry< MessageDefs... >
using PayloadTypes = typename ExtractPayloads< ProcessedDefs >::PayloadTypes
 
using PayloadTypeFor = typename TypeByID< ID, 0 >::type
 Get the payload type by message ID (compile-time)
 
using type_at = std::tuple_element_t< I, PayloadTypes >
 Get payload type at index I.
 

Additional Inherited Members

- Static Public Member Functions inherited from commrat::MessageRegistry< MessageDefs... >
static constexpr size_t calc_max_size (std::tuple< Payloads... > *)
 
static constexpr size_t max_size_for_types ()
 Calculate maximum message size for specific payload types.
 
static constexpr uint32_t get_message_id ()
 Get the message ID for a given payload type.
 
static auto serialize (T &message)
 Serialize a message with automatic type registration check.
 
static auto serialize (TimsMessage< PayloadT > &message)
 Serialize a TimsMessage<PayloadT> wrapper.
 
static auto deserialize (std::span< const std::byte > data)
 Deserialize a message with known type at compile time.
 
static auto deserialize (std::span< const std::byte > data)
 Deserialize a TimsMessage<PayloadT> wrapper.
 
static bool visit (uint32_t msg_id, std::span< const std::byte > data, Visitor &&visitor)
 Visit a message by its message ID using a visitor.
 
static bool dispatch (uint32_t msg_id, std::span< const std::byte > data, Callback &&callback)
 Deserialize message by ID and dispatch to callback.
 
static constexpr size_t max_buffer_size ()
 Get maximum buffer size needed for any message in the registry.
 
static constexpr size_t size ()
 Get number of registered message types.
 
static constexpr auto get_all_ids_impl (std::tuple< Defs... > *)
 Get list of all message IDs in the registry.
 
static constexpr auto message_ids ()
 
static constexpr std::size_t get_type_index ()
 Get type index for payload type T.
 
- Static Public Attributes inherited from commrat::MessageRegistry< MessageDefs... >
static constexpr bool is_registered_v
 
static constexpr size_t num_types
 
static constexpr size_t max_message_size
 
static constexpr bool is_registered
 Check if a payload type is registered.
 
static constexpr bool has_message_id
 Check if a message ID is registered.
 

Detailed Description

template<typename... MessageDefs>
class commrat::CommRaT< MessageDefs >

CommRaT Application Template - Main User-Facing Interface.

This is the primary entry point for defining a CommRaT application. Combines MessageRegistry with Module/Mailbox factories for clean, type-safe messaging.

Template Parameters
MessageDefsMessage definitions using MessageDefinition<PayloadType, ...>

Key Features:

  • Compile-time message type registration with automatic ID generation
  • Zero-overhead type dispatch (all lookups resolved at compile time)
  • Type-safe Module and Mailbox templates bound to this application
  • Automatic collision detection for message IDs

Usage Example:

// 1. Define your message types (plain POD structs)
struct SensorData {
float temperature;
uint32_t sensor_id;
};
struct FilteredData {
float filtered_value;
float confidence;
};
// 2. Define your application
using MyApp = CommRaT<
MessageDefinition<SensorData>,
MessageDefinition<FilteredData>
>;
// 3. Create modules using MyApp::Module
class SensorModule : public MyApp::Module<Output<SensorData>, PeriodicInput> {
protected:
void process(SensorData& output) override {
output.temperature = read_sensor();
output.sensor_id = config_.instance_id;
}
};
class FilterModule : public MyApp::Module<Output<FilteredData>, Input<SensorData>> {
protected:
void process(const SensorData& input, FilteredData& output) override {
output.filtered_value = apply_filter(input.temperature);
output.confidence = 0.95f;
}
};

Advantages over raw MessageRegistry:

  • Module template alias included (Registry::Module wasn't clear to users)
  • Mailbox types available via MyApp::Mailbox<T>
  • All application components in one namespace
  • Clearer intent: "This is my CommRaT application definition"
  • Automatic system message inclusion (subscription protocol, etc.)
See also
Module for module creation
MessageDefinition for defining message types
Output, Input, PeriodicInput for I/O specifications

Definition at line 111 of file commrat.hpp.

Member Typedef Documentation

◆ HistoricalMailbox

template<typename... MessageDefs>
template<std::size_t HistorySize>
using commrat::CommRaT< MessageDefs >::HistoricalMailbox = commrat::HistoricalMailbox<Registry, HistorySize>

HistoricalMailbox template - mailbox with time-synchronized getData()

Provides RACK-style timestamp-based message retrieval for multi-rate sensor fusion. Buffers recent messages and returns the closest match to a requested timestamp.

Template Parameters
HistorySizeNumber of messages to buffer per type (circular buffer)

Use Case: Synchronizing sensors with different rates

// IMU at 100Hz, GPS at 10Hz - need to fuse
MyApp::HistoricalMailbox<100> gps_history{gps_address, 50'000'000}; // 50ms tolerance
// In fusion module (driven by IMU)
void process(const IMUData& imu, FusedData& output) {
// Get GPS data closest to IMU timestamp
auto gps = gps_history.getData<GPSData>(imu.header.timestamp);
if (gps) {
output = fuse(imu, *gps);
}
}

Algorithm:

  1. Maintains circular buffer of recent messages with timestamps
  2. getData(target_timestamp, tolerance) finds closest message
  3. Returns std::nullopt if no message within tolerance
Note
Memory: sizeof(TimsMessage<T>) * HistorySize per type
Thread-safe: Uses internal mutex for concurrent access
See also
Inputs for automatic multi-input synchronization

Definition at line 224 of file commrat.hpp.

◆ Introspection

template<typename... MessageDefs>
using commrat::CommRaT< MessageDefs >::Introspection = IntrospectionHelper<CommRaT>

Introspection helper - export message schemas to any format.

Provides registry-wide schema export combining:

  • CommRaT metadata (message IDs, type names, size bounds)
  • SeRTial layout (fields, types, offsets, sizes, variable flags)

Supports any rfl format: JSON, YAML, TOML, XML, etc.

Usage:

// Export single message schema to JSON
auto json = MyApp::Introspection::export_as<TempData, rfl::json>();
// Export all message schemas to YAML
auto yaml = MyApp::Introspection::export_all<rfl::yaml>();
// Write all schemas to file
MyApp::Introspection::write_to_file<rfl::json>("schemas.json");

What's exported:

  • message_id - Unique ID for routing/filtering
  • payload_type - Human-readable type name
  • full_type - Complete TimsMessage<T> type
  • max_message_size - Buffer allocation hint
  • Field-level metadata (names, types, offsets, sizes)

Use cases:

  • Logger tools: Record message structure with data
  • Viewer tools: Display message fields dynamically
  • Documentation: Auto-generate API docs
  • Debugging: Understand message layout at runtime
See also
IntrospectionHelper for detailed API
MessageSchema for schema structure

Definition at line 263 of file commrat.hpp.

◆ Mailbox

template<typename... MessageDefs>
template<typename PayloadT >
using commrat::CommRaT< MessageDefs >::Mailbox = RegistryMailbox<Registry>

Mailbox template - create mailboxes for this application.

For advanced use cases that need direct mailbox access outside of Module. Most users won't need this - Module handles mailboxes automatically.

Template Parameters
PayloadTMessage payload type (must be registered in this application)

Usage (Advanced):

MyApp::Mailbox<SensorData> sensor_mailbox{address};
// Send
SensorData data{.temperature = 25.5f};
sensor_mailbox.send(data, dest_address);
// Receive
auto result = sensor_mailbox.receive<SensorData>();
if (result) {
process(result->message);
}
Note
Real-time safe if PayloadT serialization is real-time safe
See also
HistoricalMailbox for timestamp-synchronized receives

Definition at line 189 of file commrat.hpp.

◆ Module

template<typename... MessageDefs>
template<typename OutputSpec_ , typename InputSpec_ , typename... CommandTypes>
using commrat::CommRaT< MessageDefs >::Module = commrat::Module<Registry, OutputSpec_, InputSpec_, CommandTypes...>

Module template - create modules for this application.

This is the preferred user-facing API for defining modules. Automatically binds the module to this application's message registry.

Template Parameters
OutputSpec_Output specification: Output<T>, Outputs<T, U, ...>, or NoOutput
InputSpec_Input specification: Input<T>, Inputs<T, U, ...>, PeriodicInput, or LoopInput
CommandTypesOptional command types this module handles

Usage:

class MyModule : public MyApp::Module<OutputSpec, InputSpec, ...Commands> {
protected:
void process(...) override {
// Your implementation - signature depends on I/O spec
}
};

I/O Specification Examples:

See also
Output, Outputs for output specifications
Input, Inputs, PeriodicInput, LoopInput for input specifications
ModuleConfig for configuration structure

Definition at line 160 of file commrat.hpp.

◆ payload_types

template<typename... MessageDefs>
using commrat::CommRaT< MessageDefs >::payload_types = typename Registry::PayloadTypes

Definition at line 126 of file commrat.hpp.


The documentation for this class was generated from the following file: