truma_inetbox: fix compile on ESP32 Arduino

- Add missing member fields for stream+master config in LinBusListener
- Expose write_lin_master_frame_ as protected
- Make LinBusLog use <cstdint> and uint8_t
- Add <queue> + declarations for lin_reset_device/has_update_to_submit in TrumaiNetBoxApp.h
- Arduino: fix UART calls and add helper prototypes in LinBusListener_esp32_arduino.cpp

Tested: esphome compile tests/test.esp32_ard.yaml (build OK).
This commit is contained in:
Hendrik Groove 2025-09-08 14:53:35 +02:00
parent 891d3c59e8
commit 4298e675a5
5 changed files with 49 additions and 10 deletions

View File

@ -68,11 +68,27 @@ class LinBusListener : public PollingComponent, public uart::UARTDevice {
#endif // USE_RP2040
protected:
// Low-level: send a LIN master frame (break + sync + pid + data + crc)
bool write_lin_master_frame_(uint8_t pid, const uint8_t *data, uint8_t len);
LIN_CHECKSUM lin_checksum_ = LIN_CHECKSUM::LIN_CHECKSUM_VERSION_2;
GPIOPin *cs_pin_ = nullptr;
GPIOPin *fault_pin_ = nullptr;
bool observer_mode_ = false;
// Streaming config (UDP)
bool stream_enabled_ = false;
bool stream_diag_only_ = false;
uint32_t stream_keepalive_ms_ = 1000;
std::string udp_host_ = {};
uint16_t udp_port_ = 0;
// Master (LIN initiator) config
bool master_mode_ = false;
uint8_t master_nad_ = 0x00;
bool writes_armed_ = false;
void write_lin_answer_(const u_int8_t *data, u_int8_t len);
bool check_for_lin_fault_();
virtual bool answer_lin_order_(const u_int8_t pid) = 0;
@ -128,8 +144,6 @@ class LinBusListener : public PollingComponent, public uart::UARTDevice {
void clear_uart_buffer_();
void setup_framework();
void maybe_send_stream_(const QUEUE_LOG_MSG &log_msg);
// Low-level: send a LIN master frame (break + sync + pid + data + crc)
bool write_lin_master_frame_(uint8_t pid, const uint8_t *data, uint8_t len);
uint8_t lin_msg_static_queue_storage[TRUMA_MSG_QUEUE_LENGTH * sizeof(QUEUE_LIN_MSG)];
StaticQueue_t lin_msg_static_queue_;

View File

@ -12,9 +12,17 @@
#endif // CUSTOM_ESPHOME_UART
#include "esphome/components/uart/uart_component_esp32_arduino.h"
// Forward declarations for diag helpers
extern u_int8_t addr_parity(const u_int8_t pid);
extern u_int8_t data_checksum(const u_int8_t *message, u_int8_t length, uint16_t sum);
namespace esphome {
namespace truma_inetbox {
// Prototypes for helper functions in this namespace
u_int8_t addr_parity(const u_int8_t pid);
u_int8_t data_checksum(const u_int8_t *message, u_int8_t length, uint16_t sum);
static const char *const TAG = "truma_inetbox.LinBusListener";
#define QUEUE_WAIT_BLOCKING (portTickType) portMAX_DELAY
@ -39,7 +47,7 @@ void LinBusListener::setup_framework() {
uart_intr.rx_timeout_thresh =
10; // UART_TOUT_THRESH_DEFAULT, //10 works well for my short messages I need send/receive
uart_intr.txfifo_empty_intr_thresh = 10; // UART_EMPTY_THRESH_DEFAULT
uart_intr_config(uart_num, &uart_intr);
uart_intr_config((uart_port_t) uart_num, &uart_intr);
hw_serial->onReceive([this]() { this->onReceive_(); }, false);
hw_serial->onReceiveError([this](hardwareSerial_error_t val) {
@ -84,7 +92,7 @@ bool LinBusListener::write_lin_master_frame_(uint8_t pid, const uint8_t *data, u
auto uartComp = static_cast<ESPHOME_UART *>(this->parent_);
auto uart_num = uartComp->get_hw_serial_number();
auto hw_serial = uartComp->get_hw_serial();
uart_tx_break((uart_port_t) uart_num, 13);
uart_send_break((uint8_t) uart_num);
hw_serial->write(0x55);
uint8_t pid_with_parity = (pid & 0x3F) | (addr_parity(pid) << 6);
hw_serial->write(pid_with_parity);

View File

@ -66,9 +66,9 @@ enum class QUEUE_LOG_MSG_TYPE {
// Log messages generated during interrupt are pushed to log queue.
struct QUEUE_LOG_MSG {
QUEUE_LOG_MSG_TYPE type;
u_int8_t current_PID;
u_int8_t data[9];
u_int8_t len;
uint8_t current_PID;
uint8_t data[9];
uint8_t len;
#ifdef ESPHOME_LOG_HAS_VERBOSE
bool current_data_valid;
bool message_source_know;

View File

@ -411,6 +411,8 @@ bool TrumaiNetBoxApp::has_update_to_submit_() {
} // namespace truma_inetbox
} // namespace esphome
namespace esphome { namespace truma_inetbox {
bool TrumaiNetBoxApp::master_send_diag_single(uint8_t nad, const std::vector<uint8_t> &payload) {
if (!this->master_mode_) return false;
if (payload.size() == 0 || payload.size() > 6) return false; // SID + up to 5 bytes
@ -443,3 +445,5 @@ bool TrumaiNetBoxApp::master_scan_b2(uint8_t nad, uint8_t ident_start, uint8_t i
}
return true;
}
} }

View File

@ -1,5 +1,7 @@
#pragma once
#include <queue>
#include "LinBusProtocol.h"
#include "TrumaStructs.h"
#include "TrumaiNetBoxAppAirconAuto.h"
@ -25,9 +27,12 @@ class TrumaiNetBoxApp : public LinBusProtocol {
const std::array<u_int8_t, 4> lin_identifier() override;
void lin_heartbeat() override;
void lin_reset_device() override;
// Master scanner API
bool master_send_diag_single(uint8_t nad, const std::vector<uint8_t> &payload);
bool master_scan_b2(uint8_t nad, uint8_t ident_start, uint8_t ident_end);\r\n TRUMA_DEVICE get_heater_device() const { return this->heater_device_; }
bool master_scan_b2(uint8_t nad, uint8_t ident_start, uint8_t ident_end );
TRUMA_DEVICE get_heater_device() const { return this->heater_device_; }
TRUMA_DEVICE get_aircon_device() const { return this->aircon_device_; }
TrumaiNetBoxAppAirconAuto *get_aircon_auto() { return &this->airconAuto_; }
@ -75,13 +80,21 @@ class TrumaiNetBoxApp : public LinBusProtocol {
bool answer_lin_order_(const u_int8_t pid) override;
bool has_update_to_submit_();
bool lin_read_field_by_identifier_(u_int8_t identifier, std::array<u_int8_t, 5> *response) override;
const u_int8_t *lin_multiframe_recieved(const u_int8_t *message, const u_int8_t message_len,
u_int8_t *return_len) override;
\r\n\r\n struct MasterReq { uint8_t pid; uint8_t len; uint8_t data[9]; };
struct MasterReq { uint8_t pid; uint8_t len; uint8_t data[9]; };
std::queue<MasterReq> master_tx_queue_;
uint32_t last_master_send_us_ = 0;\r\n};
uint32_t last_master_send_us_ = 0;
};
} // namespace truma_inetbox
} // namespace esphome