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 =
6161
6262const std::string MqttClient::kLatencyRosTopicPrefix = " ~/latencies/" ;
6363
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+
6476template <typename T>
6577T mqtt2int (mqtt::const_message_ptr mqtt_msg) {
6678 auto str_msg = mqtt_msg->to_string ();
@@ -155,9 +167,17 @@ bool fixedMqtt2PrimitiveRos(mqtt::const_message_ptr mqtt_msg,
155167 serializeRosMessage (msg, serialized_msg);
156168 return true ;
157169 } 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 ;
159175 } 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 ;
161181 }
162182 } catch (const std::exception &) {
163183 }
You can’t perform that action at this time.
0 commit comments