Back to engineering archive

Record 079 / Connected systems

Triple channel CAN diagnostic interface

A CANBusTriple-based diagnostic application reads and sends frames across three CAN channel contexts.

Development work
CANBus diagnosticsFrame handling

Firmware flow

Read a CAN buffer into the receive queue

The selected readMsgFromBuffer() helper from a CANBusTriple application revision.

A full software queue stops this helper before the hardware-buffer read. Otherwise the frame keeps its source-bus context when it is queued.

This is an attributed source explanation, not physical bus-test evidence or a claim that queueing guarantees delivery.

Read the implementation

CANBusTriple.ino — receive-buffer helper. CANBusTriple, MIT licensed.

bool readMsgFromBuffer(CANBus * bus, byte bufferId, byte rx_status) {
    if (readQueue.isFull()) return false;
    Message msg;
    msg.busStatus = rx_status;
    msg.busId = bus->busId;
    msg.dispatch = false;
    bus->readFullFrame(bufferId, &msg.length, msg.frame_data, &msg.frame_id);
    return readQueue.push(msg);
}

CANBusTriple copyright © 2013 etx. Read the MIT licence and attribution.

ResultReturn false without reading the buffer
ActionCreate a message with bus ID, status and dispatch=false
ActionRead frame ID, length and data from the selected buffer
ResultPush the message and return the queue result

Technical notes

Keep each bus identifiable

Each queued receive message records the source bus ID and status alongside the frame ID, data and length. readBus() checks the two hardware receive-buffer flags and stops when no receive work remains or the software queue cannot accept another message.

Queue before reading

readMsgFromBuffer() returns immediately when the receive queue is full. Otherwise it creates a message, records its bus context, clears its dispatch flag, reads the selected hardware buffer and returns the result of pushing it to the queue.

Respect the framework boundary

The application uses the MIT-licensed CANBusTriple framework. The selected local revision includes modified transmit handling; receive helpers also exist in the upstream snapshot. These routines illustrate integration with that framework, not original authorship of the library or proof of traffic captured on physical buses.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project