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

make ext acc packet format follow RCN-213

This commit is contained in:
Harald Barth 2024-02-17 18:51:13 +01:00
parent dcd332603c
commit fbbedc7577

45
DCC.cpp
View File

@ -289,28 +289,45 @@ decoders or data bytes to more complex accessory decoders. Each signal head can
XXXXX is for a single head. A value of 00000 for XXXXX indicates the absolute stop aspect. All other aspects
represented by the values for XXXXX are determined by the signaling system used and the prototype being
modeled.
*/
/* CAH Notes:
From https://normen.railcommunity.de/RCN-213.pdf:
More information is in RCN-213 about how the address bits are organized.
preamble -0- 1 0 A7 A6 A5 A4 A3 A2 -0- 0 ^A10 ^A9 ^A8 0 A1 A0 1 -0- ....
Thus in byte packet form the format is 10AAAAAA, 0AAA0AA1, 000XXXXX
Note that the Basic accessory format mentions
"By convention these bits (bits 4-6 of the second data byte) are in ones complement"
but this note is absent from the advanced packet description.
The (~address) construct below applies this because this appears to be
required.
Die Adresse für den ersten erweiterten Zubehördecoder ist wie bei den einfachen
Zubehördecodern die Adresse 4 = 1000-0001 0111-0001 . Diese Adresse wird in
Anwenderdialogen als Adresse 1 dargestellt.
This means that the first address shown to the user as "1" is mapped
to internal address 4.
Note that the Basic accessory format mentions "By convention these
bits (bits 4-6 of the second data byte) are in ones complement" but
this note is absent from the advanced packet description. The
english translation does not mention that the address format for
the advanced packet follows the one for the basic packet but
according to the RCN-213 this is the case.
We allow for addresses from -3 to 2047-3 as that allows to address the
whole range of the 11 bits sent to track.
*/
if (address != (address & 0x7FF)) return false; // 11 bits
if (value != (value & 0x1F)) return false; // 5 bits
if ((address > 2044) || (address < -3)) return false; // 2047-3, 11 bits but offset 3
if (value != (value & 0x1F)) return false; // 5 bits
address+=3; // +3 offset according to RCN-213
byte b[3];
b[0]= 0x80 | (address>>5);
b[1]= 0x01 | (((~address) & 0x1c)<<2) | ((address & 0x03)<<1);
b[0]= 0x80 // bits always on
| ((address>>2) & 0x3F); // shift out 2, mask out used bits
b[1]= 0x01 // bits always on
| (((~(address>>8)) & 0x07)<<4) // shift out 8, invert, mask 3 bits, shift up 4
| ((address & 0x03)<<1); // mask 2 bits, shift up 1
b[2]=value;
DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), repeats); // Repeat on packet three times
DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), repeats);
return true;
}
}
//
// writeCVByteMain: Write a byte with PoM on main. This writes