From 7248f611df0a9c51d3df790b505da12658af3a1f Mon Sep 17 00:00:00 2001 From: Hendrik Groove Date: Tue, 9 Sep 2025 11:54:25 +0200 Subject: [PATCH] truma_inetbox(stream): decouple UDP streaming from logger level by streaming master frames from lin_msg queue --- components/truma_inetbox/LinBusListener.cpp | 32 +++++++++++++++++++++ components/truma_inetbox/LinBusListener.h | 1 + 2 files changed, 33 insertions(+) diff --git a/components/truma_inetbox/LinBusListener.cpp b/components/truma_inetbox/LinBusListener.cpp index d1ce5f4..79e9d7c 100644 --- a/components/truma_inetbox/LinBusListener.cpp +++ b/components/truma_inetbox/LinBusListener.cpp @@ -358,6 +358,10 @@ void LinBusListener::clear_uart_buffer_() { void LinBusListener::process_lin_msg_queue(TickType_t xTicksToWait) { QUEUE_LIN_MSG lin_msg; while (xQueueReceive(this->lin_msg_queue_, &lin_msg, xTicksToWait) == pdPASS) { +#ifdef USE_ESP32 + // Also forward master frames to UDP stream regardless of logger level + this->maybe_send_stream_from_lin_msg_(lin_msg); +#endif this->lin_message_recieved_(lin_msg.current_PID, lin_msg.data, lin_msg.len); } } @@ -438,6 +442,34 @@ void LinBusListener::process_log_queue(TickType_t xTicksToWait) { } #ifdef USE_ESP32 +void LinBusListener::maybe_send_stream_from_lin_msg_(const QUEUE_LIN_MSG &lin_msg) { + if (!this->stream_enabled_) return; + if (this->udp_sock_ < 0) this->stream_try_init_(); + if (this->udp_sock_ < 0) return; + const uint8_t pid = lin_msg.current_PID; + if (this->stream_diag_only_ && !(pid == DIAGNOSTIC_FRAME_MASTER || pid == DIAGNOSTIC_FRAME_SLAVE)) { + return; + } + std::string line; + line.reserve(64); + char head[16]; + snprintf(head, sizeof(head), "PID %02X ", pid); + line += head; + // Local hex format to avoid dependency on verbose-only helper + { + char b[4]; + for (uint8_t i = 0; i < lin_msg.len; i++) { + if (!line.empty() && line.back() != ' ') line.push_back(' '); + snprintf(b, sizeof(b), "%02X", lin_msg.data[i]); + line += b; + } + } +#ifdef ESPHOME_LOG_HAS_VERBOSE + line += " MASTER"; // lin_msg comes from master orders +#endif + line.push_back('\n'); + this->stream_enqueue_line_(line); +} void LinBusListener::stream_send_test(const std::string &line) { if (!this->stream_enabled_) return; if (this->udp_sock_ < 0) this->stream_try_init_(); diff --git a/components/truma_inetbox/LinBusListener.h b/components/truma_inetbox/LinBusListener.h index 6763fb5..293e75b 100644 --- a/components/truma_inetbox/LinBusListener.h +++ b/components/truma_inetbox/LinBusListener.h @@ -151,6 +151,7 @@ class LinBusListener : public PollingComponent, public uart::UARTDevice { void stream_try_init_(); void stream_maybe_keepalive_(); void stream_enqueue_line_(const std::string &line); + void maybe_send_stream_from_lin_msg_(const QUEUE_LIN_MSG &lin_msg); uint8_t lin_msg_static_queue_storage[TRUMA_MSG_QUEUE_LENGTH * sizeof(QUEUE_LIN_MSG)]; StaticQueue_t lin_msg_static_queue_;