1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

define TURNOUT_RCN_218 to follow norm for DCC packet on rails

This commit is contained in:
Harald Barth 2021-08-22 10:41:09 +02:00
parent ddcd40860f
commit 20512b0c63
3 changed files with 43 additions and 15 deletions

20
DCC.cpp
View File

@ -17,6 +17,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>. * along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/ */
#if __has_include ( "config.h")
#include "config.h"
#else
#include "config.example.h"
#endif
#include "DIAG.h" #include "DIAG.h"
#include "DCC.h" #include "DCC.h"
#include "DCCWaveform.h" #include "DCCWaveform.h"
@ -246,8 +253,17 @@ void DCC::setAccessory(int address, byte number, bool activate) {
return; return;
byte b[2]; byte b[2];
b[0] = address % 64 + 128; // first byte is of the form 10AAAAAA, where AAAAAA represent 6 least signifcant bits of accessory address // first byte is of the form 10AAAAAA, where AAAAAA represent 6 least signifcant bits of accessory address
b[1] = ((((address / 64) % 8) << 4) + (number % 4 << 1) + activate % 2) ^ 0xF8; // second byte is of the form 1AAACDDD, where C should be 1, and the least significant D represent activate/deactivate b[0] = address % 64 + 128;
// second byte is of the form 1AAACDDD, where C should be 1, and the least significant D represent activate/deactivate
// if we follow RCN-213, activate has to be reversed because in DCC++/DCC-EX activate=1 is "thrown, diverging",
// but in RCN-213, 1 means "closed, straight" and 0 "thown, diverging"
#ifdef TURNOUTS_RCN_213
activate = !activate;
#else
#error fooo
#endif
b[1] = ((((address / 64) % 8) << 4) + (number % 4 << 1) + activate % 2) ^ 0xF8;
DCCWaveform::mainTrack.schedulePacket(b, 2, 4); // Repeat the packet four times DCCWaveform::mainTrack.schedulePacket(b, 2, 4); // Repeat the packet four times
} }

View File

@ -170,7 +170,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
StringFormatter::send(stream, F("HmTurnout %d created\n"),id); StringFormatter::send(stream, F("HmTurnout %d created\n"),id);
} }
switch (cmd[3]) { switch (cmd[3]) {
// T and C according to RCN-213 where 0 is Stop, Red, Thrown, Diverging.
case 'T': case 'T':
Turnout::setClosed(id,false); Turnout::setClosed(id,false);
break; break;

View File

@ -129,4 +129,17 @@ The configuration file for DCC-EX Command Station
#define SCROLLMODE 1 #define SCROLLMODE 1
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
//
// DEFINE TURNOUTS/ACCESSORIES FOLLOW NORM RCN-213
//
// According to norm RCN-213 a DCC packet with an 1 is closed/straight
// and one with a 0 is thrown/diverging. This is reversed to the
// definition from DCC++ in the DCC++ protocol. To make the states
// match with the norm, we need to reverse the bit in the DCC packet
// on the rails, but we don't want to cause havoc on existent layouts,
// so we define this only for new installations. For any new install
// there is no reason to not define this.
#define TURNOUTS_RCN_213
/////////////////////////////////////////////////////////////////////////////////////