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

Merge pull request #189 from DCC-EX/EX-RAIL-Ash

Ex rail ash
This commit is contained in:
Ash-4 2021-09-11 13:35:11 -05:00 committed by GitHub
commit fc9aa71d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 8 deletions

23
DCC.cpp
View File

@ -357,6 +357,7 @@ const ackOp FLASH WRITE_BYTE_PROG[] = {
const ackOp FLASH VERIFY_BYTE_PROG[] = { const ackOp FLASH VERIFY_BYTE_PROG[] = {
BASELINE, BASELINE,
BIV, // ackManagerByte initial value
VB,WACK, // validate byte VB,WACK, // validate byte
ITCB, // if ok callback value ITCB, // if ok callback value
STARTMERGE, //clear bit and byte values ready for merge pass STARTMERGE, //clear bit and byte values ready for merge pass
@ -376,7 +377,7 @@ const ackOp FLASH VERIFY_BYTE_PROG[] = {
V0, WACK, MERGE, V0, WACK, MERGE,
V0, WACK, MERGE, V0, WACK, MERGE,
V0, WACK, MERGE, V0, WACK, MERGE,
VB, WACK, ITCB, // verify merged byte and return it if acked ok VB, WACK, ITCBV, // verify merged byte and return it if acked ok - with retry report
FAIL }; FAIL };
@ -688,11 +689,13 @@ int DCC::nextLoco = 0;
ackOp const * DCC::ackManagerProg; ackOp const * DCC::ackManagerProg;
ackOp const * DCC::ackManagerProgStart; ackOp const * DCC::ackManagerProgStart;
byte DCC::ackManagerByte; byte DCC::ackManagerByte;
byte DCC::ackManagerByteVerify;
byte DCC::ackManagerStash; byte DCC::ackManagerStash;
int DCC::ackManagerWord; int DCC::ackManagerWord;
byte DCC::ackManagerRetry; byte DCC::ackManagerRetry;
byte DCC::ackRetry = 2; byte DCC::ackRetry = 2;
int16_t DCC::ackRetrySum; int16_t DCC::ackRetrySum;
int16_t DCC::ackRetryPSum;
int DCC::ackManagerCv; int DCC::ackManagerCv;
byte DCC::ackManagerBitNum; byte DCC::ackManagerBitNum;
bool DCC::ackReceived; bool DCC::ackReceived;
@ -728,6 +731,7 @@ void DCC::ackManagerSetup(int cv, byte byteValueOrBitnum, ackOp const program[]
ackManagerProgStart = program; ackManagerProgStart = program;
ackManagerRetry = ackRetry; ackManagerRetry = ackRetry;
ackManagerByte = byteValueOrBitnum; ackManagerByte = byteValueOrBitnum;
ackManagerByteVerify = byteValueOrBitnum;
ackManagerBitNum=byteValueOrBitnum; ackManagerBitNum=byteValueOrBitnum;
ackManagerCallback = callback; ackManagerCallback = callback;
} }
@ -828,6 +832,17 @@ void DCC::ackManagerLoop() {
} }
break; break;
case ITCBV: // If True callback(byte) - Verify
if (ackReceived) {
if (ackManagerByte == ackManagerByteVerify) {
ackRetrySum ++;
LCD(1, F("v %d %d Sum=%d"), ackManagerCv, ackManagerByte, ackRetrySum);
}
callback(ackManagerByte);
return;
}
break;
case ITCB7: // If True callback(byte & 0x7F) case ITCB7: // If True callback(byte & 0x7F)
if (ackReceived) { if (ackReceived) {
callback(ackManagerByte & 0x7F); callback(ackManagerByte & 0x7F);
@ -846,6 +861,10 @@ void DCC::ackManagerLoop() {
callback(-1); callback(-1);
return; return;
case BIV: // ackManagerByte initial value
ackManagerByte = ackManagerByteVerify;
break;
case STARTMERGE: case STARTMERGE:
ackManagerBitNum=7; ackManagerBitNum=7;
ackManagerByte=0; ackManagerByte=0;
@ -914,7 +933,7 @@ void DCC::callback(int value) {
// check for automatic retry // check for automatic retry
if (value == -1 && ackManagerRetry > 0) { if (value == -1 && ackManagerRetry > 0) {
ackRetrySum ++; ackRetrySum ++;
LCD(0, F("RETRY %d %d %d %d"), ackManagerCv, ackManagerRetry, ackRetry, ackRetrySum); LCD(0, F("Retry %d %d Sum=%d"), ackManagerCv, ackManagerRetry, ackRetrySum);
ackManagerRetry --; ackManagerRetry --;
ackManagerProg = ackManagerProgStart; ackManagerProg = ackManagerProgStart;
return; return;

8
DCC.h
View File

@ -38,9 +38,11 @@ enum ackOp : byte
ITC1, // If True Callback(1) (if prevous WACK got an ACK) ITC1, // If True Callback(1) (if prevous WACK got an ACK)
ITC0, // If True callback(0); ITC0, // If True callback(0);
ITCB, // If True callback(byte) ITCB, // If True callback(byte)
ITCBV, // If True callback(byte) - end of Verify Byte
ITCB7, // If True callback(byte &0x7F) ITCB7, // If True callback(byte &0x7F)
NAKFAIL, // if false callback(-1) NAKFAIL, // if false callback(-1)
FAIL, // callback(-1) FAIL, // callback(-1)
BIV, // Set ackManagerByte to initial value for Verify retry
STARTMERGE, // Clear bit and byte settings ready for merge pass STARTMERGE, // Clear bit and byte settings ready for merge pass
MERGE, // Merge previous wack response with byte value and decrement bit number (use for readimng CV bytes) MERGE, // Merge previous wack response with byte value and decrement bit number (use for readimng CV bytes)
SETBIT, // sets bit number to next prog byte SETBIT, // sets bit number to next prog byte
@ -115,9 +117,11 @@ public:
static inline void setGlobalSpeedsteps(byte s) { static inline void setGlobalSpeedsteps(byte s) {
globalSpeedsteps = s; globalSpeedsteps = s;
}; };
static inline void setAckRetry(byte retry) { static inline int16_t setAckRetry(byte retry) {
ackRetry = retry; ackRetry = retry;
ackRetryPSum = ackRetrySum;
ackRetrySum = 0; // reset running total ackRetrySum = 0; // reset running total
return ackRetryPSum;
}; };
private: private:
@ -149,11 +153,13 @@ private:
static ackOp const *ackManagerProg; static ackOp const *ackManagerProg;
static ackOp const *ackManagerProgStart; static ackOp const *ackManagerProgStart;
static byte ackManagerByte; static byte ackManagerByte;
static byte ackManagerByteVerify;
static byte ackManagerBitNum; static byte ackManagerBitNum;
static int ackManagerCv; static int ackManagerCv;
static byte ackManagerRetry; static byte ackManagerRetry;
static byte ackRetry; static byte ackRetry;
static int16_t ackRetrySum; static int16_t ackRetrySum;
static int16_t ackRetryPSum;
static int ackManagerWord; static int ackManagerWord;
static byte ackManagerStash; static byte ackManagerStash;
static bool ackReceived; static bool ackReceived;

View File

@ -820,8 +820,7 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
LCD(0, F("Ack Max=%dus"), p[2]); // <D ACK MAX 9000> LCD(0, F("Ack Max=%dus"), p[2]); // <D ACK MAX 9000>
} else if (p[1] == HASH_KEYWORD_RETRY) { } else if (p[1] == HASH_KEYWORD_RETRY) {
if (p[2] >255) p[2]=3; if (p[2] >255) p[2]=3;
DCC::setAckRetry(p[2]); LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCC::setAckRetry(p[2])); // <D ACK RETRY 2>
LCD(0, F("Ack Retry=%d"), p[2]); // <D ACK RETRY 2>
} }
} else { } else {
StringFormatter::send(stream, F("Ack diag %S\n"), onOff ? F("on") : F("off")); StringFormatter::send(stream, F("Ack diag %S\n"), onOff ? F("on") : F("off"));