Repository navigation
Raw frame logging hook and TX safety fixes
Improvements Made:
- Raw Frame Logging Hook
- Added
onRawFrame(RawFrameCallback)onCANPubSubBase, inherited by both broker and client - Fires for every physical CAN frame: RX fires before target-ID filtering/message-type dispatch (a broker sees all bus traffic, not just messages addressed to it), TX fires once per physical frame sent - including once per fragment of an extended/multi-frame message
- Enables external logging/sniffing of the full bus without a separate observe-mode listener node
- Added
CANControllerClass::packetData()- a non-destructive copy of the already-buffered RX payload, used internally by the raw-frame hook without disturbing existing Stream-based reads
- TX Result Correctness
- Added
sendFrame()- a single helper now used by every protocol TX call site (roughly two dozen, across both broker and client), replacing duplicated beginPacket/write/endPacket sequences publish(),subscribe(),unsubscribe(), andsendDirectMessage()now return the real transmit result instead of a hardcodedtrue- Added
getTxFailCount()- a running counter of failed transmits, for basic bus-health monitoring
- Safety Fixes
- Fixed an unclamped stack-buffer index in the registration checksum path that could overflow with a long enough serial number
- Fixed an unclamped stack-buffer index in the subscribe/topic-name path with the same overflow risk for a long enough topic name
- Fixed two
uint8_tclient-count guards that compared against 256 - always true for auint8_t, silently letting the counter wrap 255 to 0
Key Benefits:
- Full bus observability - a broker can now log 100% of CAN traffic (not just what it's addressed to) for external diagnostics/cloud logging
- TX failures are no longer silently swallowed
- Two stack-overflow-prone code paths hardened
- Wire-compatible - no message IDs or payload layouts changed; drop-in for currently-deployed clients/brokers
Deliberately out of scope for this release (tracked as follow-up work, pending hardware-in-the-loop testing): switching the ESP32 driver to the native ESP-IDF TWAI driver, bus-off recovery, non-blocking handler rework, wire-format/multi-frame-reassembly hardening, built-in client liveness/reconnect, and delivery-confirmed (ACKed) direct messages.
See docs/RAW_FRAME_LOGGING.md for the full API reference and usage examples.