truma_inetbox(stream): decouple UDP streaming from logger level by streaming master frames from lin_msg queue
This commit is contained in:
parent
02cafc62dd
commit
7248f611df
@ -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_();
|
||||
|
||||
@ -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_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user