Inter Process Communication (IPC)

Redis

class RedisPublisher

RedisPublisher class. This class is a simple wrapper around the redis++ publisher, but it applies default settings for flyMS. It can be subscribed to using the RedisSubscriber class.

Exampe Usage:

RedisPublisher pub;
std::string channel = "test_channel";
std::string message = "test_message";
pub.publish(channel, message);

Subclassed by flyMS::MavlinkRedisPub

Public Functions

inline RedisPublisher()

Construct a new Redis Publisher object.

inline void publish(std::string_view channel, std::string_view msg)

Publish a message to a redis channel.

Parameters:
  • channel – The channel to publish to

  • msg – The contents of the message

inline void publish(std::string_view channel, const YAML::Node &msg)

Publish a YAML node to the redis channel. The yaml node is converted to a string using it’s << operator.

Parameters:
  • channel – The channel to publish to

  • msg – The yaml node to stringify then publish

class RedisSubscriber

RedisSubscriber class. This class is a simple wrapper around the redis++ subscriber, but it applies default settings for flyMS. It receives messages from the RedisPublisher class.

Example Usage:

std::mutex mutex;
std::string my_received_message;
auto callback = [&](auto channel, auto message) {
  std::unique_lock<std::mutex> lock(mutex);
  my_received_message = message;
};
RedisSubscriber sub(callback, {"test_channel"});

while (true) {
  // Lock mutex and do stuff with my_received_message
}

Subclassed by flyMS::MavlinkRedisSub

Public Functions

RedisSubscriber(std::function<void(std::string, std::string)> callback, const std::vector<std::string> &channels, std::function<void(const sw::redis::Error&)> error_callback = RedisSubscriber::default_timeout_callback)

Construct a new Redis Interface object.

Parameters:
  • callback – The callback function to invoke when a message is received on one of the subscribed channels

  • channels – The channels to subscribe to

  • error_callback – The callback function to invoke when an error occurs, this includes timeouts when messages are not received within the expected period

~RedisSubscriber()

Destroy the RedisSubscriber object.

void set_error_callback(std::function<void(const sw::redis::Error)> callback)

Set the error callback function. This function will be called if the internal redis++ subscriber throws an exeption.

Parameters:

callback – The callback function to invoke when an error occurs

UART

class Uart

Send and receive data over a UART port. Baudrate is set to B115200.

Example Usage:

auto callback = [](const std::array<uint8_t, kBUF_SIZE>& bytes, size_t size) {
  // do something with the received bytes
};
Uart uart("/dev/ttyUSB0", callback);
uart.send({0x01, 0x02, 0x03});

Subclassed by flyMS::MavlinkUart

Public Functions

Uart(const std::filesystem::path &serial_dev, std::function<void(const std::array<uint8_t, kBUF_SIZE>&, size_t)> callback)

Construct a new Uart object.

Parameters:
  • serial_dev – The path to the serial device

  • callback – The callback function that is called when new data is received

bool send(const std::vector<uint8_t> &bytes)

Send data over the UART port.

Parameters:

bytes – The data to send

Returns:

true Data was sent successfully

Returns:

false There was an error sending data