mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-24 00:26:13 +01:00
Compare commits
No commits in common. "fcbd5f96ab975486a326f972954a8708630838bd" and "8bd6403cd1f7a251e3ca6fb866d46a152fce91e2" have entirely different histories.
fcbd5f96ab
...
8bd6403cd1
|
@ -119,10 +119,8 @@ void DCCWaveform::interruptHandler() {
|
||||||
// WAVE_START is at start of bit where we need to find
|
// WAVE_START is at start of bit where we need to find
|
||||||
// out if this is an railcom start or stop time
|
// out if this is an railcom start or stop time
|
||||||
if (useRailcom) {
|
if (useRailcom) {
|
||||||
if (mainTrack.state==WAVE_MID_1) mainTrack.railcom2(true);
|
if ((mainTrack.state==WAVE_START) || (mainTrack.state== WAVE_MID_1)) mainTrack.railcom2();
|
||||||
if (mainTrack.state==WAVE_START) mainTrack.railcom2(false);
|
if ((progTrack.state==WAVE_START) || (progTrack.state== WAVE_MID_1)) progTrack.railcom2();
|
||||||
if (progTrack.state==WAVE_MID_1) progTrack.railcom2(true);
|
|
||||||
if (progTrack.state==WAVE_START) progTrack.railcom2(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move on in the state engine
|
// Move on in the state engine
|
||||||
|
@ -130,8 +128,8 @@ void DCCWaveform::interruptHandler() {
|
||||||
progTrack.state=stateTransform[progTrack.state];
|
progTrack.state=stateTransform[progTrack.state];
|
||||||
|
|
||||||
// WAVE_PENDING means we dont yet know what the next bit is
|
// WAVE_PENDING means we dont yet know what the next bit is
|
||||||
if (mainTrack.state==WAVE_PENDING) mainTrack.interrupt2();
|
if ((mainTrack.state==WAVE_PENDING) || (mainTrack.state== WAVE_START)) mainTrack.interrupt2();
|
||||||
if (progTrack.state==WAVE_PENDING) {
|
if ((progTrack.state==WAVE_PENDING) || (progTrack.state == WAVE_START)) {
|
||||||
progTrack.interrupt2();
|
progTrack.interrupt2();
|
||||||
} else {
|
} else {
|
||||||
DCCACK::checkAck(progTrack.getResets());
|
DCCACK::checkAck(progTrack.getResets());
|
||||||
|
@ -154,7 +152,7 @@ DCCWaveform::DCCWaveform( byte preambleBits, bool isMain) {
|
||||||
// The +1 below is to allow the preamble generator to create the stop bit
|
// The +1 below is to allow the preamble generator to create the stop bit
|
||||||
// for the previous packet.
|
// for the previous packet.
|
||||||
requiredPreambles = preambleBits+1;
|
requiredPreambles = preambleBits+1;
|
||||||
//requiredPreambles <<=1; // double the number of preamble wave halves
|
requiredPreambles <<=1; // double the number of preamble wave halves
|
||||||
|
|
||||||
remainingPreambles=0;
|
remainingPreambles=0;
|
||||||
bytes_sent = 0;
|
bytes_sent = 0;
|
||||||
|
@ -163,11 +161,11 @@ DCCWaveform::DCCWaveform( byte preambleBits, bool isMain) {
|
||||||
|
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize ("-O3")
|
#pragma GCC optimize ("-O3")
|
||||||
void DCCWaveform::railcom2(bool starting) {
|
void DCCWaveform::railcom2() {
|
||||||
bool cutout;
|
bool cutout;
|
||||||
if (starting && remainingPreambles==(requiredPreambles-2)) {
|
if (remainingPreambles==(requiredPreambles-4)) {
|
||||||
cutout=true;
|
cutout=true;
|
||||||
} else if (!starting && remainingPreambles==(requiredPreambles-5)) {
|
} else if (remainingPreambles==(requiredPreambles-11)) {
|
||||||
cutout=false;
|
cutout=false;
|
||||||
} else {
|
} else {
|
||||||
return; // neither start or end of cutout, do nothing
|
return; // neither start or end of cutout, do nothing
|
||||||
|
@ -196,7 +194,9 @@ void DCCWaveform::interrupt2() {
|
||||||
// or WAVE_HIGH_0 for a 0 bit.
|
// or WAVE_HIGH_0 for a 0 bit.
|
||||||
|
|
||||||
if (remainingPreambles > 0 ) {
|
if (remainingPreambles > 0 ) {
|
||||||
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
if (state==WAVE_PENDING) {
|
||||||
|
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
||||||
|
}
|
||||||
remainingPreambles--;
|
remainingPreambles--;
|
||||||
|
|
||||||
// Update free memory diagnostic as we don't have anything else to do this time.
|
// Update free memory diagnostic as we don't have anything else to do this time.
|
||||||
|
@ -205,43 +205,45 @@ void DCCWaveform::interrupt2() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wave has gone HIGH but what happens next depends on the bit to be transmitted
|
if (state==WAVE_PENDING) {
|
||||||
// beware OF 9-BIT MASK generating a zero to start each byte
|
// Wave has gone HIGH but what happens next depends on the bit to be transmitted
|
||||||
state=(transmitPacket[bytes_sent] & bitMask[bits_sent])? WAVE_MID_1 : WAVE_HIGH_0;
|
// beware OF 9-BIT MASK generating a zero to start each byte
|
||||||
bits_sent++;
|
state=(transmitPacket[bytes_sent] & bitMask[bits_sent])? WAVE_MID_1 : WAVE_HIGH_0;
|
||||||
|
bits_sent++;
|
||||||
|
|
||||||
// If this is the last bit of a byte, prepare for the next byte
|
// If this is the last bit of a byte, prepare for the next byte
|
||||||
|
|
||||||
if (bits_sent == 9) { // zero followed by 8 bits of a byte
|
if (bits_sent == 9) { // zero followed by 8 bits of a byte
|
||||||
//end of Byte
|
//end of Byte
|
||||||
bits_sent = 0;
|
bits_sent = 0;
|
||||||
bytes_sent++;
|
bytes_sent++;
|
||||||
// if this is the last byte, prepere for next packet
|
// if this is the last byte, prepere for next packet
|
||||||
if (bytes_sent >= transmitLength) {
|
if (bytes_sent >= transmitLength) {
|
||||||
// end of transmission buffer... repeat or switch to next message
|
// end of transmission buffer... repeat or switch to next message
|
||||||
bytes_sent = 0;
|
bytes_sent = 0;
|
||||||
remainingPreambles = requiredPreambles;
|
remainingPreambles = requiredPreambles;
|
||||||
|
|
||||||
if (transmitRepeats > 0) {
|
if (transmitRepeats > 0) {
|
||||||
transmitRepeats--;
|
transmitRepeats--;
|
||||||
}
|
}
|
||||||
else if (packetPending) {
|
else if (packetPending) {
|
||||||
// Copy pending packet to transmit packet
|
// Copy pending packet to transmit packet
|
||||||
// a fixed length memcpy is faster than a variable length loop for these small lengths
|
// a fixed length memcpy is faster than a variable length loop for these small lengths
|
||||||
// for (int b = 0; b < pendingLength; b++) transmitPacket[b] = pendingPacket[b];
|
// for (int b = 0; b < pendingLength; b++) transmitPacket[b] = pendingPacket[b];
|
||||||
memcpy( transmitPacket, pendingPacket, sizeof(pendingPacket));
|
memcpy( transmitPacket, pendingPacket, sizeof(pendingPacket));
|
||||||
|
|
||||||
transmitLength = pendingLength;
|
transmitLength = pendingLength;
|
||||||
transmitRepeats = pendingRepeats;
|
transmitRepeats = pendingRepeats;
|
||||||
packetPending = false;
|
packetPending = false;
|
||||||
clearResets();
|
clearResets();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Fortunately reset and idle packets are the same length
|
// Fortunately reset and idle packets are the same length
|
||||||
memcpy( transmitPacket, isMainTrack ? idlePacket : resetPacket, sizeof(idlePacket));
|
memcpy( transmitPacket, isMainTrack ? idlePacket : resetPacket, sizeof(idlePacket));
|
||||||
transmitLength = sizeof(idlePacket);
|
transmitLength = sizeof(idlePacket);
|
||||||
transmitRepeats = 0;
|
transmitRepeats = 0;
|
||||||
if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!)
|
if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ class DCCWaveform {
|
||||||
#endif
|
#endif
|
||||||
static void interruptHandler();
|
static void interruptHandler();
|
||||||
void interrupt2();
|
void interrupt2();
|
||||||
void railcom2(bool starting);
|
void railcom2();
|
||||||
|
|
||||||
bool isMainTrack;
|
bool isMainTrack;
|
||||||
// Transmission controller
|
// Transmission controller
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "railcomtests-202401142146Z"
|
#define GITHUB_SHA "3bddf4d"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user