| 222 | |
| 223 | |
| 224 | void |
| 225 | aliveIDsCallback(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 | |
| 277 | typedef unsigned long uint32; |
| 278 | // convert a string represenation of an IP address into its numeric equivalent |
nothing calls this directly
no test coverage detected