| 123 | } |
| 124 | |
| 125 | void |
| 126 | aliveIDsCallback(const opt_msgs::IDArray::ConstPtr& alive_ids_msg) |
| 127 | { |
| 128 | ros::Time msg_time = ros::Time(alive_ids_msg->header.stamp.sec, alive_ids_msg->header.stamp.nsec); |
| 129 | if ((msg_time - last_heartbeat_time).toSec() > heartbeat_interval) |
| 130 | { |
| 131 | /// Create JSON-formatted message: |
| 132 | Jzon::Object root, header, stamp; |
| 133 | |
| 134 | /// Add header: |
| 135 | header.Add("seq", int(alive_ids_msg->header.seq)); |
| 136 | stamp.Add("sec", int(alive_ids_msg->header.stamp.sec)); |
| 137 | stamp.Add("nsec", int(alive_ids_msg->header.stamp.nsec)); |
| 138 | header.Add("stamp", stamp); |
| 139 | header.Add("frame_id", "heartbeat"); |
| 140 | root.Add("header", header); |
| 141 | |
| 142 | Jzon::Array alive_IDs; |
| 143 | for (unsigned int i = 0; i < alive_ids_msg->ids.size(); i++) |
| 144 | { |
| 145 | alive_IDs.Add(alive_ids_msg->ids[i]); |
| 146 | } |
| 147 | root.Add("alive_IDs", alive_IDs); |
| 148 | root.Add("max_ID", alive_ids_msg->max_ID); |
| 149 | |
| 150 | /// Convert JSON object to string: |
| 151 | Jzon::Format message_format = Jzon::StandardFormat; |
| 152 | message_format.indentSize = json_indent_size; |
| 153 | message_format.newline = json_newline; |
| 154 | message_format.spacing = json_spacing; |
| 155 | message_format.useTabs = json_use_tabs; |
| 156 | Jzon::Writer writer(root, message_format); |
| 157 | writer.Write(); |
| 158 | std::string json_string = writer.GetResult(); |
| 159 | // std::cout << "String sent: " << json_string << std::endl; |
| 160 | |
| 161 | /// Copy string to message buffer: |
| 162 | udp_data.si_num_byte_ = json_string.length()+1; |
| 163 | char buf[udp_data.si_num_byte_]; |
| 164 | for (unsigned int i = 0; i < udp_data.si_num_byte_; i++) |
| 165 | { |
| 166 | buf[i] = 0; |
| 167 | } |
| 168 | sprintf(buf, "%s", json_string.c_str()); |
| 169 | udp_data.pc_pck_ = buf; // buffer where the message is written |
| 170 | |
| 171 | /// Send message: |
| 172 | udp_messaging.sendFromSocketUDP(&udp_data); |
| 173 | |
| 174 | last_heartbeat_time = msg_time; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | |
| 179 |
nothing calls this directly
no test coverage detected