Class BroadcastServer

Class Documentation

class BroadcastServer

This BroadcastServer is a wrapper of a websocket server. User need to specify the api_msg_type, and provide a callback function. The provided callback will be called when the specified msg_type is received. Note that this will spawn a seperate thread to host the web socket server

Public Types

enum class ApiMsgType

Values:

enumerator TaskStateUpdate
enumerator TaskLogUpdate
enumerator FleetStateUpdate
enumerator FleetLogUpdate
using ApiMessageCallback = std::function<void(const nlohmann::json&)>

Public Functions

void start()

Start Server.

void stop()

Stop Server.

Public Static Functions

static std::shared_ptr<BroadcastServer> make(const int port, ApiMessageCallback callback, std::optional<ApiMsgType> msg_selection = std::nullopt)

Create a wrapper around a websocket server for receiving states and logs for fleets, robots and tasks

Parameters:
  • port[in] server url port number

  • callback[in] callback function when the message is received

  • msg_selection[in] selected msg type to listen. Will listen to all msg if nullopt

static std::shared_ptr<BroadcastServer> make_with_logger(const int port, ApiMessageCallback callback, const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_interface, std::optional<ApiMsgType> msg_selection = std::nullopt)

Create a wrapper around a websocket server for receiving states and logs for fleets, robots and tasks

Parameters:
  • port[in] server url port number

  • callback[in] callback function when the message is received

  • node_logging_interface[in] node interface for logging. Default as nullptr which will result in errors and additional debug information not being logged

  • msg_selection[in] selected msg type to listen. Will listen to all msg if nullopt

static const std::string to_string(const ApiMsgType &type)

Get the string name of the ApiMsgType.