We gaan het beleven. Je hebt een mooie spreuk in jouw onderschrift staan.
mcp2515 *sender = new mcp2515(10);
//// Ieder systeem heeft een uniek nummertje nodig op de Canbus. Hoe we aan dat nummer komen// laten we hier nog even open.//int systemId = .......;//// Canbus interface die alleen berichten moet ontvangen//CanBus *messageReceiver = new CanBus( systemId, nullptr, new mcp2515(9));//// Canbus interface die alleen berichten moet zenden//CanBus *messageSender = new CanBus(systemId, new mcp2515(10), nullptr);//// Canbus interface die berichten moet ontvangen en zenden (er zijn 2 mcp2515 kaartjes)//CanBus *cbSenderReceiver = new CanBus(systemId, new mcp2515(10), new mcp2515(9);
//// Id's of the different types of controllers on the CanBus// Maximum nr of ID's is 127!!!//#define BEZETMELDER_CONTROLLER_ID 1 // 16 Bezetmelder controllers supported#define WISSEL_CONTROLLER_ID 17 // 16 Wissel controllers supported#define SEIN_CONTROLLER_ID 33 // 16 Sein controllers supported#define DCC_INTERFACE_ID 126 // 1 DCC Interface system supported#define S88_INTERFACE_ID 127 // 1 S88 Interface system supported
//// The CanBus//CanBus *canBus;void setup(){ // // Start the CanBus communication // canBus = new CanBus(DCC_INTERFACE_ID, new Mcp2515(10), nullptr); // Only a sender canBus->setSendWaitTime(4); // Set minimum delay between messages canBus->begin(); // Make the CanBus interface active}// End of setup
void setup(){ // // Based on which pin is connected to ground, the controller ID is established // pinMode(A0, INPUT_PULLUP); pinMode(A1, INPUT_PULLUP); pinMode(A2, INPUT_PULLUP); pinMode(A3, INPUT_PULLUP); systemId = 0; if (!digitalRead(A0)) systemId = systemId+1; if (!digitalRead(A1)) systemId = systemId+2; if (!digitalRead(A2)) systemId = systemId+4; if (!digitalRead(A3)) systemId = systemId+8; // // Start the CanBus communication // canBus = new CanBus(BEZETMELDER_CONTROLLER_ID+systemId, new Mcp2515(10), nullptr); // Only a sender canBus->begin(); // Make the CanBus interface active}
void loop(){ // // Monitor the canBus // canBus->heartBeat(); // Andere code}
//// There are several types of messages, each is identified by an unique number// the lowest id's have the highest priority//// DCC_ACC defines a DCC Accesory command// OCC_DT defines an Occupance detector that triggered// DCC_LOC defines a DCC locomotive command//enum messageId { OCC_DT = 1, DCC_ACC = 2, DCC_LOC = 3};typedef struct{ unsigned short address; byte state;} OCC_DT_MSG;typedef struct{ unsigned short address; byte direction;} DCC_ACC_MSG;
// // Send the new state to the S88 Interface // OCC_DT_MSG buf; buf.address = ((s88Bank-1)*16)+(s88Id-1); if (occupied) buf.state = 1; else buf.state = 0; // // Repeat the message, to cover the occasional mishap // canBus->sendMsg(OCC_DT, sizeof(OCC_DT_MSG), &buf); canBus->sendMsg(OCC_DT, sizeof(OCC_DT_MSG), &buf);
void setup(){ canBus->setMsgReceiver(OCC_DT, occDtReceiver); }
/// A function that executes whenever a message is received from the Canbus// It's purpose is to analyze the received event Occupancy detector and// update the proper element in the semaphore table or turnout table.//void occDtReceiver(unsigned char aMsgLen, OCC_DT_MSG *msgData){ if (msgData->address < nrOfOccDetectors) { pendingStates[msgData->address] = msgData->state;