mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
take into account that the reset packets are sent first #repeat packets into the future
This commit is contained in:
parent
f57fd245a1
commit
67b14ec57d
|
@ -113,11 +113,7 @@ void DCCACK::Setup(int wordval, ackOp const program[], ACK_CALLBACK callback) {
|
||||||
Setup(0, 0, program, callback);
|
Setup(0, 0, program, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
const byte RESET_MIN=12; // Ugly fix until counting code is right
|
|
||||||
#else
|
|
||||||
const byte RESET_MIN=8; // tuning of reset counter before sending message
|
const byte RESET_MIN=8; // tuning of reset counter before sending message
|
||||||
#endif
|
|
||||||
|
|
||||||
// checkRessets return true if the caller should yield back to loop and try later.
|
// checkRessets return true if the caller should yield back to loop and try later.
|
||||||
bool DCCACK::checkResets(uint8_t numResets) {
|
bool DCCACK::checkResets(uint8_t numResets) {
|
||||||
|
|
|
@ -243,7 +243,8 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
|
||||||
pendingPacket[byteCount] = checksum;
|
pendingPacket[byteCount] = checksum;
|
||||||
pendingLength = byteCount + 1;
|
pendingLength = byteCount + 1;
|
||||||
pendingRepeats = repeats;
|
pendingRepeats = repeats;
|
||||||
clearResets();
|
// The resets will be zero not only now but as well repeats packets into the future
|
||||||
|
clearResets(repeats+1);
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -57,15 +57,20 @@ class DCCWaveform {
|
||||||
inline void clearResets() { sentResetsSincePacket=0; }
|
inline void clearResets() { sentResetsSincePacket=0; }
|
||||||
inline byte getResets() { return sentResetsSincePacket; }
|
inline byte getResets() { return sentResetsSincePacket; }
|
||||||
#else
|
#else
|
||||||
inline void clearResets() { resetPacketBase = isMainTrack ?
|
// extrafudge is added when we know that the resets will first come extrafudge packets in the future
|
||||||
rmtMainChannel->packetCount() : rmtProgChannel->packetCount(); };
|
inline void clearResets(byte extrafudge=0) {
|
||||||
|
resetPacketBase = isMainTrack ? rmtMainChannel->packetCount() : rmtProgChannel->packetCount();
|
||||||
|
resetPacketBase += extrafudge;
|
||||||
|
};
|
||||||
inline byte getResets() {
|
inline byte getResets() {
|
||||||
uint32_t packetcount = isMainTrack ?
|
uint32_t packetcount = isMainTrack ?
|
||||||
rmtMainChannel->packetCount() : rmtProgChannel->packetCount();
|
rmtMainChannel->packetCount() : rmtProgChannel->packetCount();
|
||||||
uint32_t count = packetcount - resetPacketBase;
|
uint32_t count = packetcount - resetPacketBase; // Beware of unsigned interger arithmetic.
|
||||||
if (count > 255) // cap to 255
|
if (count > UINT32_MAX/2) // we are in the extrafudge area
|
||||||
|
return 0;
|
||||||
|
if (count > 255) // cap to 255
|
||||||
return 255;
|
return 255;
|
||||||
return count;
|
return count; // all special cases handled above
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
void schedulePacket(const byte buffer[], byte byteCount, byte repeats);
|
void schedulePacket(const byte buffer[], byte byteCount, byte repeats);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "PORTX-HAL-20220804"
|
#define GITHUB_SHA "PORTX-HAL-20220804-1"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user