Adding Connections#

Adding connections allows to communicate based on newly integrated communication protocolls, and thus to talk with applications which are not based on the CCF or even ROS. To implement a new connection one has to implement the Connection-Interface, which defines the core methods of a connections. A simple example is the MQTT-Connection. Below you can see the implemented send-method of the MQTT connections, which transmits a new message, by using the Lib-Paho MQTT client library.

bool MqttConnection::send(const std::string &channel, const std::string &message) {

    if (ensureConnection()) {
        try {
            int length = message.size();
            void *data = (void *) message.c_str();

            auto pub_msg = mqtt::make_message(channel, data, length);
            pub_msg->set_qos(QOS);
            getClient().publish(pub_msg);
        }
        catch (const mqtt::exception &exc) {
            return false;
        }
    } else {
        return false;
    }
    return true;
}

After implementing a connection, one just has to add it to a controller implementing the according interface and the new protocoll is used out of the box.