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).
56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#pragma once
|
|
// BMW I/K-Bus interface — backward-compatible facade
|
|
// Wraps KLineTransport + IbusHandler so existing sketches need zero changes.
|
|
// For new code, use KLineTransport + IbusHandler (or KLineObd2) directly.
|
|
|
|
#include <Arduino.h>
|
|
#include <functional>
|
|
#include "KLineTransport.h"
|
|
#include "IbusHandler.h"
|
|
|
|
// Re-export library defaults for existing config.h compatibility
|
|
#ifndef IBUS_BAUD
|
|
#define IBUS_BAUD 9600
|
|
#endif
|
|
#ifndef IBUS_FRAMING
|
|
#define IBUS_FRAMING SERIAL_8E1
|
|
#endif
|
|
#ifndef IBUS_IDLE_TIMEOUT_US
|
|
#define IBUS_IDLE_TIMEOUT_US 1500
|
|
#endif
|
|
#ifndef IBUS_IDLE_CHECK_US
|
|
#define IBUS_IDLE_CHECK_US 250
|
|
#endif
|
|
#ifndef IBUS_PACKET_GAP_MS
|
|
#define IBUS_PACKET_GAP_MS 10
|
|
#endif
|
|
#ifndef IBUS_UART_NUM
|
|
#define IBUS_UART_NUM 1
|
|
#endif
|
|
|
|
class IbusEsp32 {
|
|
public:
|
|
using PacketCallback = std::function<void(const uint8_t* packet, uint8_t length)>;
|
|
|
|
IbusEsp32();
|
|
|
|
void begin(HardwareSerial& serial, int8_t rxPin, int8_t txPin,
|
|
int8_t ledPin = -1, uint8_t uartNum = IBUS_UART_NUM);
|
|
|
|
void run();
|
|
|
|
void write(const uint8_t* message, uint8_t size);
|
|
|
|
void onPacket(PacketCallback callback);
|
|
|
|
void setFilterEnabled(bool enabled);
|
|
void setFilterAddress(uint8_t addr);
|
|
void setFilterAddresses(const uint8_t* addrs, uint8_t count);
|
|
|
|
static uint8_t calculateChecksum(const uint8_t* data, uint8_t length);
|
|
|
|
private:
|
|
KLineTransport _transport;
|
|
IbusHandler _handler;
|
|
};
|