From 3faa48476cb39ae8aefe7530ff063f7fc8de2d40 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 24 Nov 2020 21:12:55 +0100 Subject: [PATCH 1/2] ack diag better messages --- DCCEXParser.cpp | 6 +++++- DCCWaveform.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2b90136..e122e71 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -49,6 +49,8 @@ const int HASH_KEYWORD_PROGBOOST = -6353; const int HASH_KEYWORD_EEPROM = -7168; const int HASH_KEYWORD_LIMIT = 27413; const int HASH_KEYWORD_ETHERNET = -30767; +//const int HASH_KEYWORD_MAX = 16244; +//const int HASH_KEYWORD_MIN = 15978; int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; @@ -598,8 +600,10 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[]) if (params >= 2 && p[1] == HASH_KEYWORD_LIMIT) { DCCWaveform::progTrack.setAckLimit(p[2]); StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]); - } else + } else { + StringFormatter::send(stream, F("\nAck diag %S\n"), onOff ? F("on") : F("off")); Diag::ACK = onOff; + } return true; case HASH_KEYWORD_CMD: // diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index bec16b3..36fb1b7 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -295,9 +295,10 @@ void DCCWaveform::setAckBaseline() { if (isMainTrack) return; int baseline = motorDriver->getCurrentRaw(); ackThreshold= baseline + motorDriver->mA2raw(ackLimitmA); - if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA threshold=%d/%dmA"), + if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA Threshold=%d/%dmA Duration: %dus <= pulse <= %dus"), baseline,motorDriver->raw2mA(baseline), - ackThreshold,motorDriver->raw2mA(ackThreshold)); + ackThreshold,motorDriver->raw2mA(ackThreshold), + MIN_ACK_PULSE_DURATION, MAX_ACK_PULSE_DURATION); } void DCCWaveform::setAckPending() { @@ -312,7 +313,7 @@ void DCCWaveform::setAckPending() { byte DCCWaveform::getAck() { if (ackPending) return (2); // still waiting - if (Diag::ACK) DIAG(F("\nACK-%S after %dmS max=%d/%dmA pulse=%duS"),ackDetected?F("OK"):F("FAIL"), ackCheckDuration, + if (Diag::ACK) DIAG(F("\n%S after %dmS max=%d/%dmA pulse=%duS"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration, ackMaxCurrent,motorDriver->raw2mA(ackMaxCurrent), ackPulseDuration); if (ackDetected) return (1); // Yes we had an ack return(0); // pending set off but not detected means no ACK. From edc39e734238838fb38156be74831927f7c55d5c Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 24 Nov 2020 21:39:21 +0100 Subject: [PATCH 2/2] ack pulse length configurable from diag --- DCCEXParser.cpp | 24 ++++++++++++++++-------- DCCWaveform.cpp | 6 +++--- DCCWaveform.h | 15 ++++++++++----- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index e122e71..e79a94a 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -49,8 +49,8 @@ const int HASH_KEYWORD_PROGBOOST = -6353; const int HASH_KEYWORD_EEPROM = -7168; const int HASH_KEYWORD_LIMIT = 27413; const int HASH_KEYWORD_ETHERNET = -30767; -//const int HASH_KEYWORD_MAX = 16244; -//const int HASH_KEYWORD_MIN = 15978; +const int HASH_KEYWORD_MAX = 16244; +const int HASH_KEYWORD_MIN = 15978; int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; @@ -596,10 +596,18 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[]) StringFormatter::send(stream, F("\nFree memory=%d\n"), freeMemory()); break; - case HASH_KEYWORD_ACK: // - if (params >= 2 && p[1] == HASH_KEYWORD_LIMIT) { - DCCWaveform::progTrack.setAckLimit(p[2]); - StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]); + case HASH_KEYWORD_ACK: // + if (params >= 3) { + if (p[1] == HASH_KEYWORD_LIMIT) { + DCCWaveform::progTrack.setAckLimit(p[2]); + StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]); + } else if (p[1] == HASH_KEYWORD_MIN) { + DCCWaveform::progTrack.setMinAckPulseDuration(p[2]); + StringFormatter::send(stream, F("\nAck min=%dus\n"), p[2]); + } else if (p[1] == HASH_KEYWORD_MAX) { + DCCWaveform::progTrack.setMaxAckPulseDuration(p[2]); + StringFormatter::send(stream, F("\nAck max=%dus\n"), p[2]); + } } else { StringFormatter::send(stream, F("\nAck diag %S\n"), onOff ? F("on") : F("off")); Diag::ACK = onOff; @@ -630,8 +638,8 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[]) DCC::setProgTrackBoost(true); return true; - case HASH_KEYWORD_EEPROM: - if (params >= 1) + case HASH_KEYWORD_EEPROM: // + if (params >= 2) EEStore::dump(p[1]); return true; diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 36fb1b7..123ba9e 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -298,7 +298,7 @@ void DCCWaveform::setAckBaseline() { if (Diag::ACK) DIAG(F("\nACK baseline=%d/%dmA Threshold=%d/%dmA Duration: %dus <= pulse <= %dus"), baseline,motorDriver->raw2mA(baseline), ackThreshold,motorDriver->raw2mA(ackThreshold), - MIN_ACK_PULSE_DURATION, MAX_ACK_PULSE_DURATION); + minAckPulseDuration, maxAckPulseDuration); } void DCCWaveform::setAckPending() { @@ -330,7 +330,7 @@ void DCCWaveform::checkAck() { lastCurrent=motorDriver->getCurrentRaw(); if (lastCurrent > ackMaxCurrent) ackMaxCurrent=lastCurrent; - // An ACK is a pulse lasting between MIN_ACK_PULSE_DURATION and MAX_ACK_PULSE_DURATION uSecs (refer @haba) + // An ACK is a pulse lasting between minAckPulseDuration and maxAckPulseDuration uSecs (refer @haba) if (lastCurrent>ackThreshold) { if (ackPulseStart==0) ackPulseStart=micros(); // leading edge of pulse detected @@ -343,7 +343,7 @@ void DCCWaveform::checkAck() { // detected trailing edge of pulse ackPulseDuration=micros()-ackPulseStart; - if (ackPulseDuration>=MIN_ACK_PULSE_DURATION && ackPulseDuration<=MAX_ACK_PULSE_DURATION) { + if (ackPulseDuration>=minAckPulseDuration && ackPulseDuration<=maxAckPulseDuration) { ackCheckDuration=millis()-ackCheckStart; ackDetected=true; ackPending=false; diff --git a/DCCWaveform.h b/DCCWaveform.h index 32041e6..c658577 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -27,10 +27,6 @@ const int POWER_SAMPLE_ON_WAIT = 100; const int POWER_SAMPLE_OFF_WAIT = 1000; const int POWER_SAMPLE_OVERLOAD_WAIT = 20; -// Ack time thresholds. Unit: microseconds -const int MIN_ACK_PULSE_DURATION = 2000; -const int MAX_ACK_PULSE_DURATION = 8500; - // Number of preamble bits. const int PREAMBLE_BITS_MAIN = 16; const int PREAMBLE_BITS_PROG = 22; @@ -79,7 +75,13 @@ class DCCWaveform { inline void setAckLimit(int mA) { ackLimitmA = mA; } - + inline void setMinAckPulseDuration(unsigned int i) { + minAckPulseDuration = i; + } + inline void setMaxAckPulseDuration(unsigned int i) { + maxAckPulseDuration = i; + } + private: static VirtualTimer * interruptTimer; static void interruptHandler(); @@ -128,6 +130,9 @@ class DCCWaveform { unsigned int ackPulseDuration; // micros unsigned long ackPulseStart; // micros + + unsigned int minAckPulseDuration = 2000; // micros + unsigned int maxAckPulseDuration = 8500; // micros }; #endif