| 128 | } |
| 129 | |
| 130 | void AirTelemetry::loop_infinite(bool& terminate, |
| 131 | const bool enableExtendedLogging) { |
| 132 | const auto log_intervall = std::chrono::seconds(5); |
| 133 | const auto loop_intervall = std::chrono::milliseconds(100); |
| 134 | auto last_log = std::chrono::steady_clock::now(); |
| 135 | while (!terminate) { |
| 136 | const auto loopBegin = std::chrono::steady_clock::now(); |
| 137 | if (std::chrono::steady_clock::now() - last_log >= log_intervall) { |
| 138 | // State debug logging |
| 139 | last_log = std::chrono::steady_clock::now(); |
| 140 | // m_console->debug("AirTelemetry::loopInfinite()"); |
| 141 | // for debugging, check if any of the endpoints is not alive |
| 142 | if (enableExtendedLogging && m_wb_endpoint) { |
| 143 | m_console->debug(m_wb_endpoint->createInfo()); |
| 144 | } |
| 145 | } |
| 146 | // send messages to the ground pi in regular intervals, includes heartbeat. |
| 147 | // everything else is handled by the callbacks and their threads |
| 148 | { |
| 149 | // NOTE: No component on the air unit ever needs to talk to the FC himself |
| 150 | std::lock_guard<std::mutex> guard(m_components_lock); |
| 151 | for (auto& component : m_components) { |
| 152 | auto messages = component->generate_mavlink_messages(); |
| 153 | send_messages_ground_unit(messages); |
| 154 | } |
| 155 | } |
| 156 | const auto loopDelta = std::chrono::steady_clock::now() - loopBegin; |
| 157 | if (loopDelta > loop_intervall) { |
| 158 | // We can't keep up with the wanted loop interval |
| 159 | m_console->debug( |
| 160 | "Warning AirTelemetry cannot keep up with the wanted loop interval. " |
| 161 | "Took {}", |
| 162 | openhd::util::time_readable(loopDelta)); |
| 163 | } else { |
| 164 | const auto sleepTime = loop_intervall - loopDelta; |
| 165 | // send out in X second intervals |
| 166 | std::this_thread::sleep_for(loop_intervall); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | std::string AirTelemetry::create_debug() { |
| 172 | std::stringstream ss; |
no test coverage detected