MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / MavlinkTelemetrySink

Class MavlinkTelemetrySink

OpenHD/ohd_common/src/openhd_spdlog.cpp:56–80  ·  view source on GitHub ↗

Sinks the messages into a buffer For the telemetry thread to fetch

Source from the content-addressed store, hash-verified

54// Sinks the messages into a buffer
55// For the telemetry thread to fetch
56class MavlinkTelemetrySink : public spdlog::sinks::base_sink<std::mutex> {
57 protected:
58 void sink_it_(const spdlog::details::log_msg& msg) override {
59 // log_msg is a struct containing the log entry info like level, timestamp,
60 // thread id etc. msg.raw contains pre formatted log If needed (very likely
61 // but not mandatory), the sink formats the message before sending it to its
62 // final destination:
63 if (msg.level >= spdlog::level::warn) {
64 // We do not use the formatter here, since we are limited by 50 chars (and
65 // the level, for example, is embedded already but not as a string).
66 // spdlog::memory_buf_t formatted;
67 // spdlog::sinks::base_sink<std::mutex>::formatter_->format(msg,
68 // formatted);
69 const auto msg_string = fmt::to_string(msg.payload);
70 const std::string msg_with_tag =
71 fmt::format("{} {}", msg.logger_name, msg_string);
72 const auto level = openhd::log::level_spdlog_to_mavlink(msg.level);
73 auto tmp = safe_create(static_cast<int>(level), msg_with_tag);
74 MavlinkLogMessageBuffer::instance().enqueue_log_message(tmp);
75 }
76 }
77 void flush_() override {
78 // std::cout << std::flush;
79 }
80};
81
82} // namespace openhd::log::sink
83

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected