mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56: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);
|
||||
}
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
// checkRessets return true if the caller should yield back to loop and try later.
|
||||
bool DCCACK::checkResets(uint8_t numResets) {
|
||||
|
|
|
@ -243,7 +243,8 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
|
|||
pendingPacket[byteCount] = checksum;
|
||||
pendingLength = byteCount + 1;
|
||||
pendingRepeats = repeats;
|
||||
clearResets();
|
||||
// The resets will be zero not only now but as well repeats packets into the future
|
||||
clearResets(repeats+1);
|
||||
{
|
||||
int ret;
|
||||
do {
|
||||
|
|
|
@ -57,15 +57,20 @@ class DCCWaveform {
|
|||
inline void clearResets() { sentResetsSincePacket=0; }
|
||||
inline byte getResets() { return sentResetsSincePacket; }
|
||||
#else
|
||||
inline void clearResets() { resetPacketBase = isMainTrack ?
|
||||
rmtMainChannel->packetCount() : rmtProgChannel->packetCount(); };
|
||||
// extrafudge is added when we know that the resets will first come extrafudge packets in the future
|
||||
inline void clearResets(byte extrafudge=0) {
|
||||
resetPacketBase = isMainTrack ? rmtMainChannel->packetCount() : rmtProgChannel->packetCount();
|
||||
resetPacketBase += extrafudge;
|
||||
};
|
||||
inline byte getResets() {
|
||||
uint32_t packetcount = isMainTrack ?
|
||||
rmtMainChannel->packetCount() : rmtProgChannel->packetCount();
|
||||
uint32_t count = packetcount - resetPacketBase;
|
||||
uint32_t count = packetcount - resetPacketBase; // Beware of unsigned interger arithmetic.
|
||||
if (count > UINT32_MAX/2) // we are in the extrafudge area
|
||||
return 0;
|
||||
if (count > 255) // cap to 255
|
||||
return 255;
|
||||
return count;
|
||||
return count; // all special cases handled above
|
||||
};
|
||||
#endif
|
||||
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