Compare commits

..

2 Commits

2 changed files with 35 additions and 2 deletions

View File

@ -336,13 +336,14 @@ void LinBusListener::read_lin_frame_() {
TRUMA_LOGV_ISR(log_msg);
#endif // ESPHOME_LOG_HAS_VERBOSE
if (this->current_data_valid && message_from_master) {
if (this->current_data_valid) {
QUEUE_LIN_MSG lin_msg;
lin_msg.current_PID = this->current_PID_;
lin_msg.len = this->current_data_count_ - 1;
lin_msg.len = this->current_data_count_ - 1; // exclude CRC
for (u_int8_t i = 0; i < lin_msg.len; i++) {
lin_msg.data[i] = this->current_data_[i];
}
lin_msg.from_master = message_from_master ? 1 : 0;
xQueueSendFromISR(this->lin_msg_queue_, (void *) &lin_msg, QUEUE_WAIT_DONT_BLOCK);
}
this->current_state_ = READ_STATE_BREAK;
@ -358,6 +359,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 +443,32 @@ 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;
}
}
line += (lin_msg.from_master ? " MASTER" : " SLAVE");
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_();

View File

@ -33,6 +33,7 @@ struct QUEUE_LIN_MSG {
u_int8_t current_PID;
u_int8_t data[8];
u_int8_t len;
u_int8_t from_master; // 1 = master order, 0 = slave response
};
class LinBusListener : public PollingComponent, public uart::UARTDevice {
@ -151,6 +152,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_;