Namespace CANProtocol
Public Functions
| Type | Name |
|---|---|
| bool | busOff () Return true if the CAN controller is in bus-off state. |
| void | drain () Process RX callbacks and batched-ControlPacket deadlines. Call once per loop(). |
| void | filterAcceptAll () Accept all incoming CAN frames. Use for PanelBridge . |
| void | filterAcceptId (uint32_t canId) Accept a specific CAN ID. Use for PanelGroup nodes. |
| void | flushBatched (uint32_t canId) Force a half-full ControlPacketPair batch to send immediately. |
| HeartbeatPayload | makeHeartbeatPayload (uint8_t nodeId, uint16_t rxCount) Build the standard 8-byte heartbeat payload for the current node. |
| void | onReceive (CanRxCallback cb) Register a general-purpose RX frame handler. |
| void | onStatusChange (CanStatusCallback cb) Register a CAN bus status change callback. |
| void | onSyncReq (CanSyncReqCallback cb) Register a SYNC_REQ handler. |
| uint8_t | rec () Return the CAN Receive Error Counter (0-255) from ESR. |
| void | send (uint32_t canId, const uint8_t * data, uint8_t len) Send a CAN frame. |
| void | sendBatched (uint32_t canId, const ControlPacket & pkt) Submit one ControlPacket to a CANProtocol-owned ControlPacketPair batch. |
| void | start () Start the CAN peripheral and apply registered filters. |
| void | startLoopback () Start in silent loopback mode — for bench testing only. |
| uint8_t | tec () Return the CAN Transmit Error Counter (0-255) from ESR. |
| uint32_t | txDropCount () Return the cumulative TX queue drop count since startup. |
Public Functions Documentation
function busOff
Return true if the CAN controller is in bus-off state.
bool CANProtocol::busOff ()
function drain
Process RX callbacks and batched-ControlPacket deadlines. Call once per loop().
void CANProtocol::drain ()
Drains all frames received since the last call: * SYNC_REQ: fires onSyncReq(), not forwarded to onReceive(). * TEST_SEQ: auto-replies with ECHO carrying the same payload, not forwarded. * All other frames: fires onReceive().
Also services sendBatched() deadlines: a half-full ControlPacketPair that has waited two drain() calls is flushed with slot B set to the null sentinel.
function filterAcceptAll
Accept all incoming CAN frames. Use for PanelBridge .
void CANProtocol::filterAcceptAll ()
Configures a pass-all hardware mask filter. Mandatory IDs (CTRL_BCAST, TEST_SEQ, SYNC_REQ) are included but have no effect with pass-all active.
function filterAcceptId
Accept a specific CAN ID. Use for PanelGroup nodes.
void CANProtocol::filterAcceptId (
uint32_t canId
)
Adds one ID to the hardware filter list. Call multiple times for multiple IDs. CTRL_BCAST (0x010), TEST_SEQ (0x011), and SYNC_REQ (0x012) are always included automatically by start() — do not add them manually.
Parameters:
canId11-bit standard CAN ID to accept.
function flushBatched
Force a half-full ControlPacketPair batch to send immediately.
void CANProtocol::flushBatched (
uint32_t canId
)
If the named CAN ID has a pending slot A, sends it with slot B as the null sentinel. No-op if no packet is pending.
Parameters:
canIdCAN_ID_CTRL_BCAST, canIdEvt(NODE_ID), canIdEvtRel(NODE_ID), or canIdEvtDir(NODE_ID).
function makeHeartbeatPayload
Build the standard 8-byte heartbeat payload for the current node.
HeartbeatPayload CANProtocol::makeHeartbeatPayload (
uint8_t nodeId,
uint16_t rxCount
)
Fills uptime, CAN health flags, and ESR-derived TEC/REC from CANProtocol state.
Parameters:
nodeIdNode ID (1-63 PanelGroup; 0 reserved for PanelBridge).rxCountCaller-owned receive counter to embed in the payload.
Returns:
Fully populated HeartbeatPayload ready to send as HB_n.
function onReceive
Register a general-purpose RX frame handler.
void CANProtocol::onReceive (
CanRxCallback cb
)
Fired by drain() for all frames except SYNC_REQ and TEST_SEQ. Only one handler per node — PanelGroup and PanelBridge each register their own.
Parameters:
cbCallback invoked with canId, data pointer, and payload length.
function onStatusChange
Register a CAN bus status change callback.
void CANProtocol::onStatusChange (
CanStatusCallback cb
)
Fires immediately with the current status upon registration (STARTING before start() is called), then on each subsequent status transition.
Parameters:
cbCallback to invoke with the new CanStatus.
function onSyncReq
Register a SYNC_REQ handler.
void CANProtocol::onSyncReq (
CanSyncReqCallback cb
)
Fired by drain() when SYNC_REQ (0x012) is received. PanelGroup registers this to trigger a re-poll of all registered input objects.
Parameters:
cbCallback to invoke on SYNC_REQ receipt.
function rec
Return the CAN Receive Error Counter (0-255) from ESR.
uint8_t CANProtocol::rec ()
function send
Send a CAN frame.
void CANProtocol::send (
uint32_t canId,
const uint8_t * data,
uint8_t len
)
Sends immediately if a TX mailbox is free; otherwise enqueues in the TX ring buffer (~16 entries), drained automatically via TX-complete interrupt. CTRL_BCAST coalesces stale queued state (newest wins). EVT/control frames retry up to 3 attempts then drop. All drops increment txDropCount().
Parameters:
canId11-bit standard CAN ID.dataPointer to payload bytes.lenPayload length in bytes (0-8).
function sendBatched
Submit one ControlPacket to a CANProtocol-owned ControlPacketPair batch.
void CANProtocol::sendBatched (
uint32_t canId,
const ControlPacket & pkt
)
Valid only for CAN_ID_CTRL_BCAST and the batched event frames — canIdEvt(n) (absolute), canIdEvtRel(n) (RotaryEncoder REL), and canIdEvtDir(n) (RotaryEncoder DIR) — each with its own pending slot. Pairs two consecutive packets into one 8-byte frame. If slot B does not arrive within two drain() calls, slot A is sent with slot B set to the null sentinel (controlId == 0x0000).
Parameters:
canIdCAN_ID_CTRL_BCAST, canIdEvt(NODE_ID), canIdEvtRel(NODE_ID), or canIdEvtDir(NODE_ID).pktControlPacket to batch.
function start
Start the CAN peripheral and apply registered filters.
void CANProtocol::start ()
Must be called after STM32Board::begin() and after all filter and callback registrations. Always adds CTRL_BCAST, TEST_SEQ, and SYNC_REQ to the active filter — mandatory for all nodes, cannot be excluded.
Fires the onStatusChange callback with NORMAL on success.
function startLoopback
Start in silent loopback mode — for bench testing only.
void CANProtocol::startLoopback ()
Identical to start() but uses CAN_MODE_SILENT_LOOPBACK: frames transmitted by this node are received back internally without going on the physical bus.
Note:
Never call this in production firmware.
function tec
Return the CAN Transmit Error Counter (0-255) from ESR.
uint8_t CANProtocol::tec ()
function txDropCount
Return the cumulative TX queue drop count since startup.
uint32_t CANProtocol::txDropCount ()
The documentation for this class was generated from the following file Firmware/Libraries/CANProtocol/CANProtocol.cpp