 /*
 *  Load CAN Controller buffer and set send flag
 */
-bool sendMessage( Message msg, CANBus bus )
-{
-    int ch = bus.getNextTxBuffer();
+bool sendMessage( Message msg, CANBus * bus )
+{
+    int ch = bus->getNextTxBuffer();
     if (ch < 0 || ch > 2) return false; // All TX buffers full
 
     digitalWrite(BOOT_LED, HIGH);
-    bus.loadFullFrame(ch, msg.length, msg.frame_id, msg.frame_data );
-    bus.transmitBuffer(ch);
+    bus->loadFullFrame(ch, msg.length, msg.frame_id, msg.frame_data );
+    bus->transmitBuffer(ch);
     digitalWrite(BOOT_LED, LOW );
 
     return true;

#define WRITE_BUFFER_SIZE 10


CANBus CANBus1(CAN1SELECT, CAN1RESET, 1, "Bus 1");
CANBus CANBus2(CAN2SELECT, CAN2RESET, 2, "Bus 2");
CANBus CANBus3(CAN3SELECT, CAN3RESET, 3, "Bus 3");
CANBus busses[] = { CANBus1, CANBus2, CANBus3 };

#include "Middleware.h"
#include "Settings.h"

    while(!writeQueue.isEmpty() && !error) {
        Message msg = writeQueue.pop();
	if (msg.dispatch) {
	    error = !sendMessage(msg, &busses[msg.busId - 1]);
            // When TX Failure, add back to queue
            if (error) writeQueue.push(msg);
        }
