File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,18 @@ const std::string MqttClient::kRosMsgTypeMqttTopicPrefix =
61
61
62
62
const std::string MqttClient::kLatencyRosTopicPrefix = " ~/latencies/" ;
63
63
64
+ template <typename T>
65
+ T mqtt2float (mqtt::const_message_ptr mqtt_msg) {
66
+ auto str_msg = mqtt_msg->to_string ();
67
+ std::size_t pos;
68
+ const T v = std::stold (str_msg, &pos);
69
+
70
+ if (pos != str_msg.size ())
71
+ throw std::invalid_argument (" not all charaters processed" );
72
+
73
+ return v;
74
+ }
75
+
64
76
template <typename T>
65
77
T mqtt2int (mqtt::const_message_ptr mqtt_msg) {
66
78
auto str_msg = mqtt_msg->to_string ();
@@ -155,9 +167,17 @@ bool fixedMqtt2PrimitiveRos(mqtt::const_message_ptr mqtt_msg,
155
167
serializeRosMessage (msg, serialized_msg);
156
168
return true ;
157
169
} else if (msg_type == " std_msgs/msg/Float32" ) {
158
- // / TODO
170
+ std_msgs::msg::Float32 msg;
171
+ msg.data = mqtt2float<float >(mqtt_msg);
172
+
173
+ serializeRosMessage (msg, serialized_msg);
174
+ return true ;
159
175
} else if (msg_type == " std_msgs/msg/Float64" ) {
160
- // / TODO
176
+ std_msgs::msg::Float64 msg;
177
+ msg.data = mqtt2float<double >(mqtt_msg);
178
+
179
+ serializeRosMessage (msg, serialized_msg);
180
+ return true ;
161
181
}
162
182
} catch (const std::exception &) {
163
183
}
You can’t perform that action at this time.
0 commit comments