Skip to content

Commit e9a02fb

Browse files
authored
Merge pull request #89 from zouri/main
2 parents fb83478 + de01b27 commit e9a02fb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ bridge:
267267
268268
As seen in the [Quick Start](#quick-start), the *mqtt_client* can not only exchange arbitrary ROS messages with other *mqtt_clients*, but it can also exchange primitive message data with other non-*mqtt_client* MQTT clients. This allows ROS-based devices to exchange primitive messages with devices not based on ROS. The `primitive` parameter can be set for both ROS-to-MQTT (`bridge/ros2mqtt`) and for MQTT-to-ROS (`bridge/mqtt2ros`) transmissions.
269269

270-
If a ROS-to-MQTT transmission is configured as `primitive` and the ROS message type is one of the supported primitive ROS message types, the raw data is published as a string. The supported primitive ROS message types are [`std_msgs/String`](http://docs.ros.org/en/api/std_msgs/html/msg/String.html), [`std_msgs/Bool`](http://docs.ros.org/en/api/std_msgs/html/msg/Bool.html), [`std_msgs/Char`](http://docs.ros.org/en/api/std_msgs/html/msg/Char.html), [`std_msgs/UInt8`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt8.html), [`std_msgs/UInt16`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt16.html), [`std_msgs/UInt32`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt32.html), [`std_msgs/UInt64`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt64.html), [`std_msgs/Int8`](http://docs.ros.org/en/api/std_msgs/html/msg/Int8.html), [`std_msgs/Int16`](http://docs.ros.org/en/api/std_msgs/html/msg/Int16.html), [`std_msgs/Int32`](http://docs.ros.org/en/api/std_msgs/html/msg/Int32.html), [`std_msgs/Int64`](http://docs.ros.org/en/api/std_msgs/html/msg/Int64.html), [`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float32.html), [`std_msgs/Float64`](http://docs.ros.org/en/api/std_msgs/html/msg/Float64.html).
270+
If a ROS-to-MQTT transmission is configured as `primitive` and the ROS message type is one of the supported primitive ROS message types, the raw data is published as a string. The supported primitive ROS message types are [`std_msgs/String`](http://docs.ros.org/en/api/std_msgs/html/msg/String.html), [`std_msgs/Bool`](http://docs.ros.org/en/api/std_msgs/html/msg/Bool.html), [`std_msgs/Char`](http://docs.ros.org/en/api/std_msgs/html/msg/Char.html), [`std_msgs/UInt8`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt8.html), [`std_msgs/UInt16`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt16.html), [`std_msgs/UInt32`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt32.html), [`std_msgs/UInt64`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt64.html), [`std_msgs/Int8`](http://docs.ros.org/en/api/std_msgs/html/msg/Int8.html), [`std_msgs/Int16`](http://docs.ros.org/en/api/std_msgs/html/msg/Int16.html), [`std_msgs/Int32`](http://docs.ros.org/en/api/std_msgs/html/msg/Int32.html), [`std_msgs/Int64`](http://docs.ros.org/en/api/std_msgs/html/msg/Int64.html), [`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float32.html), [`std_msgs/Float64`](http://docs.ros.org/en/api/std_msgs/html/msg/Float64.html), [`std_msgs/UInt8MultiArray`](http://docs.ros.org/en/api/std_msgs/html/msg/UInt8MultiArray.html).
271271

272272
If an MQTT-to-ROS transmission is configured as `primitive`, the MQTT message is interpreted and published as a primitive data type, if possible. The message is probed in the following order: `bool` ([`std_msgs/Bool`](http://docs.ros.org/en/api/std_msgs/html/msg/Bool.html)), `int` ([`std_msgs/Int32`](http://docs.ros.org/en/api/std_msgs/html/msg/Int32.html)), `float` ([`std_msgs/Float32`](http://docs.ros.org/en/api/std_msgs/html/msg/Float32.html)), `string` ([`std_msgs/String`](http://docs.ros.org/en/api/std_msgs/html/msg/String.html)).
273273

mqtt_client/src/MqttClient.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SOFTWARE.
4848
#include <std_msgs/msg/u_int32.hpp>
4949
#include <std_msgs/msg/u_int64.hpp>
5050
#include <std_msgs/msg/u_int8.hpp>
51+
#include <std_msgs/msg/u_int8_multi_array.hpp>
5152

5253
#include <rclcpp_components/register_node_macro.hpp>
5354
RCLCPP_COMPONENTS_REGISTER_NODE(mqtt_client::MqttClient)
@@ -164,6 +165,12 @@ bool fixedMqtt2PrimitiveRos(mqtt::const_message_ptr mqtt_msg,
164165
std_msgs::msg::Float64 msg;
165166
msg.data = mqtt2float<double>(mqtt_msg);
166167

168+
serializeRosMessage(msg, serialized_msg);
169+
} else if (msg_type == "std_msgs/msg/UInt8MultiArray") {
170+
std_msgs::msg::UInt8MultiArray msg;
171+
const std::string& str_msg = mqtt_msg->to_string();
172+
msg.data = std::vector<uint8_t>(str_msg.begin(), str_msg.end());
173+
167174
serializeRosMessage(msg, serialized_msg);
168175
} else {
169176
throw std::domain_error("Unhandled message type (" + msg_type + ")");
@@ -251,6 +258,10 @@ bool primitiveRosMessageToString(
251258
std_msgs::msg::Float64 msg;
252259
deserializeRosMessage(*serialized_msg, msg);
253260
primitive = std::to_string(msg.data);
261+
} else if (msg_type == "std_msgs/msg/UInt8MultiArray") {
262+
std_msgs::msg::UInt8MultiArray msg;
263+
deserializeRosMessage(*serialized_msg, msg);
264+
primitive = std::string(msg.data.begin(), msg.data.end());
254265
} else {
255266
found_primitive = false;
256267
}

0 commit comments

Comments
 (0)