| 197 | } |
| 198 | |
| 199 | void GroundTelemetry::loop_infinite(bool& terminate, |
| 200 | const bool enableExtendedLogging) { |
| 201 | const auto log_intervall = std::chrono::seconds(5); |
| 202 | const auto loop_intervall = std::chrono::milliseconds(100); |
| 203 | auto last_log = std::chrono::steady_clock::now(); |
| 204 | while (!terminate) { |
| 205 | const auto loopBegin = std::chrono::steady_clock::now(); |
| 206 | if (std::chrono::steady_clock::now() - last_log >= log_intervall) { |
| 207 | last_log = std::chrono::steady_clock::now(); |
| 208 | // m_console->debug("GroundTelemetry::loopInfinite()"); |
| 209 | // for debugging, check if any of the endpoints is not alive |
| 210 | if (enableExtendedLogging && m_wb_endpoint) { |
| 211 | m_console->debug(m_wb_endpoint->createInfo()); |
| 212 | } |
| 213 | if (enableExtendedLogging && m_gcs_endpoint) { |
| 214 | m_console->debug(m_gcs_endpoint->createInfo()); |
| 215 | } |
| 216 | } |
| 217 | // send messages to the ground station in regular intervals, includes |
| 218 | // heartbeat. everything else is handled by the callbacks and their threads |
| 219 | { |
| 220 | // NOTE: No component from the ground station ever needs to talk to the |
| 221 | // air unit / FC itself |
| 222 | std::lock_guard<std::mutex> guard(m_components_lock); |
| 223 | for (auto& component : m_components) { |
| 224 | assert(component); |
| 225 | const auto messages = component->generate_mavlink_messages(); |
| 226 | send_messages_ground_station_clients(messages); |
| 227 | // exception: timesync |
| 228 | for (const auto& msg : messages) { |
| 229 | if (msg.m.msgid == MAVLINK_MSG_ID_TIMESYNC) { |
| 230 | m_console->debug("Sending timesync to air"); |
| 231 | send_messages_air_unit({msg}); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | const auto loopDelta = std::chrono::steady_clock::now() - loopBegin; |
| 237 | if (loopDelta > loop_intervall) { |
| 238 | // We can't keep up with the wanted loop interval |
| 239 | // We can't keep up with the wanted loop interval |
| 240 | m_console->debug( |
| 241 | "Warning GroundTelemetry cannot keep up with the wanted loop " |
| 242 | "interval. Took {}", |
| 243 | openhd::util::time_readable(loopDelta)); |
| 244 | } else { |
| 245 | const auto sleepTime = loop_intervall - loopDelta; |
| 246 | // send out in X second intervals |
| 247 | std::this_thread::sleep_for(loop_intervall); |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | std::string GroundTelemetry::create_debug() const { |
| 253 | std::stringstream ss; |
nothing calls this directly
no test coverage detected