MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / aliveIDsCallback

Function aliveIDsCallback

opt_utils/apps/ros2udp_converter.cpp:224–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223
224void
225aliveIDsCallback(const opt_msgs::IDArray::ConstPtr& alive_ids_msg)
226{
227 ros::Time msg_time = ros::Time(alive_ids_msg->header.stamp.sec, alive_ids_msg->header.stamp.nsec);
228 if ((msg_time - last_heartbeat_time).toSec() > heartbeat_interval)
229 {
230 /// Create JSON-formatted message:
231 Jzon::Object root, header, stamp;
232
233 /// Add header:
234 header.Add("seq", int(alive_ids_msg->header.seq));
235 stamp.Add("sec", int(alive_ids_msg->header.stamp.sec));
236 stamp.Add("nsec", int(alive_ids_msg->header.stamp.nsec));
237 header.Add("stamp", stamp);
238 header.Add("frame_id", "heartbeat");
239 root.Add("header", header);
240
241 Jzon::Array alive_IDs;
242 for (unsigned int i = 0; i < alive_ids_msg->ids.size(); i++)
243 {
244 alive_IDs.Add(alive_ids_msg->ids[i]);
245 }
246 root.Add("alive_IDs", alive_IDs);
247 root.Add("max_ID", alive_ids_msg->max_ID);
248
249 /// Convert JSON object to string:
250 Jzon::Format message_format = Jzon::StandardFormat;
251 message_format.indentSize = json_indent_size;
252 message_format.newline = json_newline;
253 message_format.spacing = json_spacing;
254 message_format.useTabs = json_use_tabs;
255 Jzon::Writer writer(root, message_format);
256 writer.Write();
257 std::string json_string = writer.GetResult();
258 // std::cout << "String sent: " << json_string << std::endl;
259
260 /// Copy string to message buffer:
261 udp_data.si_num_byte_ = json_string.length()+1;
262 char buf[udp_data.si_num_byte_];
263 for (unsigned int i = 0; i < udp_data.si_num_byte_; i++)
264 {
265 buf[i] = 0;
266 }
267 sprintf(buf, "%s", json_string.c_str());
268 udp_data.pc_pck_ = buf; // buffer where the message is written
269
270 /// Send message:
271 udp_messaging.sendFromSocketUDP(&udp_data);
272
273 last_heartbeat_time = msg_time;
274 }
275}
276
277typedef unsigned long uint32;
278// convert a string represenation of an IP address into its numeric equivalent

Callers

nothing calls this directly

Calls 4

AddMethod · 0.80
WriteMethod · 0.80
sendFromSocketUDPMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected