Class PacketManager

Nested Relationships

Nested Types

Class Documentation

class PacketManager

Manages automatically sending and receiving packets on the CAN bus with timeouts and callbacks.

Public Types

typedef std::function<std::vector<uint8_t>(void)> data_generator_t

Function which generates packet data.

Public Functions

PacketManager(FilteredCanInterface &interface)

Constructs a new PacketManager using the given interface for I/O.

Parameters:
FilteredCanInterface &interface

The interface to use for I/O

inline void handle(bool should_block = false, bool should_force_transmission = false)

Handles all data reception and transmission - just calls handle_receive and handle_transmit.

Parameters:
bool should_block = false

Whether or not to block until a packet is received

bool should_force_transmission = false

Force transmission of all packets, even if they are not due

void handle_receive(bool should_block = false)

Handles all data reception and associated callbacks.

Parameters:
bool should_block = false

Whether or not to block until a packet is received

void handle_transmit(bool should_force_transmission = false)

Handles all data transmissions.

Parameters:
bool should_force_transmission = false

Force transmission of all packets, even if they are not due

void add_group(const parameters::ParameterGroup &group)

Add a parameter group to the packet manager.

Parameters:
const parameters::ParameterGroup &group

Group to add

void remove_group(const parameters::ParameterGroup &group)

Remove a parameter group from the packet manager.

Parameters:
const parameters::ParameterGroup &group

Group to remove

void set_callback(const addressing::filter_t &filter, const callback_config_t &config)

Sets a data receive callback which will be called for packets received on the interface matching the filter.

Note

The filter will be added to the interface’s receive filter list

Parameters:
const addressing::filter_t &filter

The filter to match packets against

const callback_config_t &config

The configuration for the callback

std::optional<callback_config_t> get_callback(const addressing::filter_t &filter)

Get the callback configuration for a specific filter.

Parameters:
const addressing::filter_t &filter

The filter to get the configuration for

Returns:

The callback configuration if found, otherwise std::nullopt

void remove_callback(const addressing::filter_t &filter)

Remove a callback for a specific filter.

Note

The filter will be removed from the interface’s receive filter list

Parameters:
const addressing::filter_t &filter

The filter to remove the callback for

void set_transmission_config(const addressing::flagged_address_t &address, const transmission_config_t &config)

Set a transmit configuration.

Parameters:
const transmission_config_t &config

The configuration to set

void set_transmission_generator(const addressing::flagged_address_t &address, const data_generator_t &generator)

Overwrite the transmission data generator for an address.

Note

If there is no static transmit configuration for the packet’s address, nothing will happen

Parameters:
const addressing::flagged_address_t &address

The address to set the generator for

const data_generator_t &generator

The transmission data generator

void set_transmission_interval(const addressing::flagged_address_t &address, const std::chrono::steady_clock::duration &interval)

Set the transmission interval for an address.

Note

If there is no transmit configuration for the address, nothing will happen

Parameters:
const addressing::flagged_address_t &address

The address to set the interval for

const std::chrono::steady_clock::duration &interval

New transmission interval

std::optional<transmission_config_t> get_transmission_config(const addressing::flagged_address_t &address)

Get the transmit configuration for an address.

Parameters:
const addressing::flagged_address_t &address

The address to get the configuration for

Returns:

The transmit configuration if found, otherwise std::nullopt

void remove_transmission(const addressing::flagged_address_t &address)

Remove a transmit configuration.

Parameters:
const addressing::flagged_address_t &address

The address to remove the configuration for

inline FilteredCanInterface &get_interface() const

Get the underlying interface used for I/O.

Returns:

The interface

struct callback_config_t

Configuration for a data reception callback.

Public Members

packet_callback_t data_callback = nullptr

The callback to be called when data is received.

std::function<void(void)> timeout_callback = nullptr

The callback to be called when a timeout occurs.

packet_callback_t timeout_recovery_callback = nullptr

The callback to be called when data is received after a timeout.

std::chrono::steady_clock::duration timeout = std::chrono::steady_clock::duration::zero()

The timeout duration. Zero means no timeout.

struct transmission_config_t

Configuration for scheduling a packet transmission.

Public Members

data_generator_t generator = nullptr

Function which returns the packet data to transmit.

std::chrono::steady_clock::duration interval = std::chrono::steady_clock::duration::zero()

The interval between transmissions - zero means transmit as often as possible.

bool should_transmit_immediately = false

Whether or not to transmit the packet immediately. If false, will transmit after the interval.