diff --git a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp index abb2d04..adc8f1e 100644 --- a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp +++ b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp @@ -1,4 +1,4 @@ -#ifdef USE_ESP32_FRAMEWORK_ARDUINO +#ifdef USE_ESP32_FRAMEWORK_ARDUINO #include "LinBusListener.h" #include "esphome/core/log.h" #include "driver/uart.h" @@ -77,6 +77,24 @@ void LinBusListener::eventTask_(void *args) { } } + +bool LinBusListener::write_lin_master_frame_(uint8_t pid, const uint8_t *data, uint8_t len) { + if (!this->master_mode_) return false; + if (len > 8) return false; + auto uartComp = static_cast(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); + hw_serial->write(0x55); + uint8_t pid_with_parity = (pid & 0x3F) | (addr_parity(pid) << 6); + hw_serial->write(pid_with_parity); + uint8_t crc = data_checksum(data, len, 0); + if (len > 0) hw_serial->write((uint8_t*)data, len); + hw_serial->write(crc); + hw_serial->flush(); + return true; +} + } // namespace truma_inetbox } // namespace esphome @@ -84,27 +102,3 @@ void LinBusListener::eventTask_(void *args) { #undef ESPHOME_UART #endif // USE_ESP32_FRAMEWORK_ARDUINO -bool LinBusListener::write_lin_master_frame_(uint8_t pid, const uint8_t *data, uint8_t len) { - if (!this->master_mode_) return false; - if (len > 8) return false; - auto uartComp = static_cast(this->parent_); - auto uart_num = uartComp->get_hw_serial_number(); - auto hw_serial = uartComp->get_hw_serial(); - - // Send BREAK using ESP-IDF uart driver, then SYNC (0x55), PID, data, checksum - // Best effort: not all cores expose the same API; try common call. - // Begin BREAK - uart_tx_break((uart_port_t) uart_num, 13); - // SYNC - hw_serial->write(0x55); - // PID with parity (upper 2 bits) - uint8_t pid_with_parity = (pid & 0x3F) | (addr_parity(pid) << 6); - hw_serial->write(pid_with_parity); - - // Data - uint8_t crc = data_checksum(data, len, 0); - if (len > 0) hw_serial->write((uint8_t*)data, len); - hw_serial->write(crc); - hw_serial->flush(); - return true; -} diff --git a/components/truma_inetbox/TrumaiNetBoxApp.cpp b/components/truma_inetbox/TrumaiNetBoxApp.cpp index 5908ecd..ddde36b 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.cpp +++ b/components/truma_inetbox/TrumaiNetBoxApp.cpp @@ -38,7 +38,8 @@ void TrumaiNetBoxApp::update() { this->write_lin_master_frame_(req.pid, req.data, req.len); this->last_master_send_us_ = now; } - }\r\n#ifdef USE_TIME + } +#ifdef USE_TIME // Update time of CP Plus automatically when // - Time component configured // - Update was not done