dus pak er een biertje bij
OpenLCB en LCC, ik heb weer genoeg te lezen
Heb je nog voortgang gemaakt met je baan?
/* A program to convert DCC commands to Canbus messages Copyright (C) Meino, all rights reserved This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.*/#include <DCC_Decoder.h>#include <CanBus.h>//// Other pin's used//#define DCCPIN 2//// Definitions for the DCC interface//#define K_DCC_INTERRUPT 0//// The CanBus//CanBus *canBus;
//// DCC Accessory packet handler//void DCC_PacketHandler(int address, bool activate, byte data){ // // Convert NMRA packet address to a useable address // // This calculation seems to be a little weird. However it has to do with // the way NMRA has implemented these things. Accessory decoders have an // basic address and a sub address. // F.I. decoder address 1 means first decoder (address 1) sub address 0. // Decoder address 2 means first decoder (address 1) sub address 1. // Decoder address 5 means second decoder (address 2), sub address 0, etc. // So the basic decoder address is not a C like index but a counter like in // Cobol, it doesn't start with 0. // // // Start with the base address // address -= 1; address *= 4; // // Add de sub address // address += 1; address += (data & 0x06) >> 1; // // Do we perform a normal(-) or a switch(/) operation? // For a normal operation enable is true, for a switch operation // enable is false. // bool enable = (data & 0x01) ? 1 : 0; // This bit actual specifies which of the two coils need // to be activated. (or deactivated if activate is false, which is not used // by this code) DCC_ACC_MSG buf; buf.address = address; if (enable) { buf.direction = 0; } else { buf.direction = 1; } // // Send the received accessory command // canBus->sendMsg(DCC_ACC, sizeof(DCC_ACC_MSG), &buf);}
void setup(){ // // Setup and start the CanBus communication // static const int nrOfBuffers = 7; static const int waitTime = 4; canBus = new CanBus(DCC_INTERFACE_ID, new Mcp2515(10, waitTime, nrOfBuffers), nullptr); // Only a sender, 250msg/sec, 10 sendbuffers canBus->begin(); // // Setup the DCC packet handler // DCC.SetBasicAccessoryDecoderPacketHandler(DCC_PacketHandler, true); DCC.SetupDecoder(0x00, 0x00, K_DCC_INTERRUPT); }
void loop(){ // // Check for DCC packets // DCC.loop(); // // Activate the CanBus // canBus->heartBeat(); }
Overigens weet ik niet of jouw idee van signaal versterking gaat werken
/* A program to accept occupancy detector status from the Canbus and set the proper bit in the S88 shift register Copyright (C) Meino de Graaf, all rights reserved This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. email: meino@innerside.demon.nl*/#include <CanBus.h>//// Pin layout is for the Arduino Uno//// Connections for S88 bus://// s88 pin 1 Data - Arduino pin 8 = Data_Out to Oommand Station, or pin 7 (Data in) from the next Arduino in the chain// s88 pin 2 GND - Arduino GND// s88 pin 3 Clock - Arduino pin 2, interrupt 0// s88 pin 4 PS - Arduino pin 3, interrupt 1// S88 pin 5 Reset (not used)// s88 pin 6 V+ - Arduino 5V (not used)//// Connections for S88N (RJ45)//// RJ45 pin 1 12V/5V (not used)// RJ45 pin 2 DATA - Arduino pin 8 Data_Out to Oommand Station, or pin 7 Data In from the next Arduino in the chain// RJ45 pin 3 GND - Arduino GND// RJ45 pin 4 CLOCK - Arduino pin 2, interrupt 0// RJ45 pin 5 GND - Arduino GND// RJ45 pin 6 PS - Arduino pin 3, interrupt 1// RJ45 pin 7 RESET (not used)// RJ45 pin 8 RAILDATA (not used)//#define S88_DATAOUT_PIN 8#define S88_DATAIN_PIN 7#define S88_CLOCK_PIN 2#define S88_PS_PIN 3#define S88_CLOCK_INTERRUPT 0#define S88_PS_INTERRUPT 1const int nrOfOccDetectors = 6 * 16;volatile byte pendingStates[nrOfOccDetectors];volatile byte dataRegister[nrOfOccDetectors];volatile long clockTicks = 0;CanBus *canBus;
void PS_Int(){ // // Load the detector states in the data register // memcpy(dataRegister,pendingStates,nrOfOccDetectors); clockTicks = 0; // reset index in the dataRegister}//// Set the state of the next detector on the output pin//void clock_Int(){ digitalWrite(S88_DATAOUT_PIN, dataRegister[clockTicks]); // // If we are chained to additional detectors, reads a bit from the chain and // store it in the current, just written, position // // // Delay makes reading output signal from next Arduino in chain more reliable. // //delayMicroseconds(2); //dataRegister[clockTicks]=digitalRead(S88_DATAIN_PIN); clockTicks = (++clockTicks) % nrOfOccDetectors; // Goto next bit in dataRegister}
//// 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; }}
void setup(){ // // Intialize the dataRegister // memset(pendingStates,0,nrOfOccDetectors); memset(dataRegister,0,nrOfOccDetectors); // // Setup the input/output pins and the interrupts for the S88 communication // //pinMode(S88_CLOCK_PIN, INPUT_PULLUP); //pinMode(S88_PS_PIN, INPUT_PULLUP); pinMode(S88_DATAIN_PIN, INPUT_PULLUP); pinMode(S88_DATAOUT_PIN, OUTPUT); digitalWrite(S88_DATAOUT_PIN, LOW); attachInterrupt(S88_CLOCK_INTERRUPT, clock_Int, RISING); attachInterrupt(S88_PS_INTERRUPT, PS_Int, RISING); // // Setup and start the CanBus communication // canBus = new CanBus(S88_INTERFACE_ID, nullptr, new Mcp2515(10)); // Only a receiver canBus->setMsgReceiver(OCC_DT, occDtReceiver); canBus->begin();}
void loop(){ // // Are there messages on the CanBus? // canBus->heartBeat();}
Code: [Selecteer]CanBus *canBus;
CanBus *canBus;