mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
commit
fc9aa71d9f
29
DCC.cpp
29
DCC.cpp
|
@ -357,8 +357,9 @@ 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
|
||||||
// each bit is validated against 0 and the result inverted in MERGE
|
// each bit is validated against 0 and the result inverted in MERGE
|
||||||
// this is because there tend to be more zeros in cv values than ones.
|
// this is because there tend to be more zeros in cv values than ones.
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -827,7 +831,18 @@ void DCC::ackManagerLoop() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
@ -845,7 +860,11 @@ void DCC::ackManagerLoop() {
|
||||||
case FAIL: // callback(-1)
|
case FAIL: // callback(-1)
|
||||||
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
8
DCC.h
|
@ -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;
|
||||||
|
|
|
@ -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"));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user