1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

make sentResetsSincePacket private to the class and replace all accesses with with methods

This commit is contained in:
Harald Barth 2022-08-02 15:57:45 +02:00
parent 863f2f4a85
commit c7cf8246a7
3 changed files with 9 additions and 9 deletions

View File

@ -81,7 +81,7 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C
if (ackManagerRejoin ) { if (ackManagerRejoin ) {
// Change from JOIN must zero resets packet. // Change from JOIN must zero resets packet.
TrackManager::setJoin(false); TrackManager::setJoin(false);
DCCWaveform::progTrack.sentResetsSincePacket = 0; DCCWaveform::progTrack.clearResets();
} }
autoPowerOff=false; autoPowerOff=false;
@ -93,7 +93,7 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C
/* TODO !!! in MotorDriver surely! /* TODO !!! in MotorDriver surely!
if (MotorDriver::commonFaultPin) if (MotorDriver::commonFaultPin)
DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON); DCCWaveform::mainTrack.setPowerMode(POWERMODE::ON);
DCCWaveform::progTrack.sentResetsSincePacket = 0; DCCWaveform::progTrack.clearResets();
**/ **/
} }
@ -117,7 +117,7 @@ const byte RESET_MIN=8; // tuning of reset counter before sending message
// 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) {
return DCCWaveform::progTrack.sentResetsSincePacket < numResets; return DCCWaveform::progTrack.getResets() < numResets;
} }
// Operations applicable to PROG track ONLY. // Operations applicable to PROG track ONLY.
// (yes I know I could have subclassed the main track but...) // (yes I know I could have subclassed the main track but...)

View File

@ -89,7 +89,7 @@ void DCCWaveform::interruptHandler() {
// 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.interrupt2();
if (progTrack.state==WAVE_PENDING) progTrack.interrupt2(); if (progTrack.state==WAVE_PENDING) progTrack.interrupt2();
else DCCACK::checkAck(progTrack.sentResetsSincePacket); else DCCACK::checkAck(progTrack.getResets());
} }
#pragma GCC pop_options #pragma GCC pop_options
@ -160,14 +160,14 @@ void DCCWaveform::interrupt2() {
transmitLength = pendingLength; transmitLength = pendingLength;
transmitRepeats = pendingRepeats; transmitRepeats = pendingRepeats;
packetPending = false; packetPending = false;
sentResetsSincePacket=0; 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 (sentResetsSincePacket<250) sentResetsSincePacket++; if (getResets() < 250) sentResetsSincePacket++; // only place to increment (private!)
} }
} }
} }
@ -189,7 +189,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
pendingLength = byteCount + 1; pendingLength = byteCount + 1;
pendingRepeats = repeats; pendingRepeats = repeats;
packetPending = true; packetPending = true;
sentResetsSincePacket=0; clearResets();
} }
bool DCCWaveform::getPacketPending() { bool DCCWaveform::getPacketPending() {
return packetPending; return packetPending;
@ -237,7 +237,7 @@ 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;
sentResetsSincePacket=0; clearResets();
{ {
int ret; int ret;
do { do {

View File

@ -69,12 +69,12 @@ class DCCWaveform {
}; };
#endif #endif
void schedulePacket(const byte buffer[], byte byteCount, byte repeats); void schedulePacket(const byte buffer[], byte byteCount, byte repeats);
volatile byte sentResetsSincePacket;
bool getPacketPending(); bool getPacketPending();
private: private:
#ifndef ARDUINO_ARCH_ESP32 #ifndef ARDUINO_ARCH_ESP32
volatile bool packetPending; volatile bool packetPending;
volatile byte sentResetsSincePacket;
#else #else
volatile uint32_t resetPacketBase; volatile uint32_t resetPacketBase;
#endif #endif