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

}


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);
}

#define WRITE_BUFFER_SIZE 10


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

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