Split the monolithic IbusEsp32 class into composable layers: - KLineTransport: UART, GPIO ISR, ring buffers, idle detection - IbusHandler: BMW I/K-Bus FSM, source filtering, packet callback - IbusEsp32: thin facade preserving the original API Library renamed from IbusEsp32 to AutoWire. Existing sniffer sketch (main.cpp) requires zero changes. All 3 ESP32 environments build cleanly (esp32dev, esp32-c3, esp32-s3).
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
// BMW I/K-Bus interface — backward-compatible facade
|
|
// Delegates everything to KLineTransport + IbusHandler.
|
|
|
|
#include "IbusEsp32.h"
|
|
|
|
IbusEsp32::IbusEsp32()
|
|
: _transport(),
|
|
_handler(_transport) {}
|
|
|
|
void IbusEsp32::begin(HardwareSerial& serial, int8_t rxPin, int8_t txPin,
|
|
int8_t ledPin, uint8_t uartNum) {
|
|
KLineConfig config;
|
|
config.baud = IBUS_BAUD;
|
|
config.framing = IBUS_FRAMING;
|
|
config.idleTimeoutUs = IBUS_IDLE_TIMEOUT_US;
|
|
config.idleCheckUs = IBUS_IDLE_CHECK_US;
|
|
config.packetGapMs = IBUS_PACKET_GAP_MS;
|
|
config.txInvert = true;
|
|
config.checksumType = CHECKSUM_XOR;
|
|
|
|
_transport.begin(serial, rxPin, txPin, ledPin, uartNum, config);
|
|
}
|
|
|
|
void IbusEsp32::run() {
|
|
_transport.drainUart();
|
|
_handler.process();
|
|
_transport.run();
|
|
}
|
|
|
|
void IbusEsp32::write(const uint8_t* message, uint8_t size) {
|
|
_handler.write(message, size);
|
|
}
|
|
|
|
void IbusEsp32::onPacket(PacketCallback callback) {
|
|
_handler.onPacket(callback);
|
|
}
|
|
|
|
void IbusEsp32::setFilterEnabled(bool enabled) {
|
|
_handler.setFilterEnabled(enabled);
|
|
}
|
|
|
|
void IbusEsp32::setFilterAddress(uint8_t addr) {
|
|
_handler.setFilterAddress(addr);
|
|
}
|
|
|
|
void IbusEsp32::setFilterAddresses(const uint8_t* addrs, uint8_t count) {
|
|
_handler.setFilterAddresses(addrs, count);
|
|
}
|
|
|
|
uint8_t IbusEsp32::calculateChecksum(const uint8_t* data, uint8_t length) {
|
|
return KLineTransport::checksumXor(data, length);
|
|
}
|