From 47a4d2dae9aaa41c9d59c6edebf058a9b6caac3b Mon Sep 17 00:00:00 2001 From: Asbelos Date: Wed, 1 Jul 2020 16:58:48 +0100 Subject: [PATCH] Cleanup and ACK debugs --- DCC.cpp | 4 ++-- DCCEXParser.cpp | 7 ++++--- DCCEXParser.h | 6 ++++-- DIAG.h | 5 +---- PWMServoDriver.cpp | 1 - 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index 248c96a..2725f28 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -514,13 +514,13 @@ void DCC::ackManagerLoop() { // detected trailing edge of pulse long pulseDuration=micros()-ackPulseStart; - if (pulseDuration>4000 && pulseDuration<9000) { + if (pulseDuration>1000 && pulseDuration<9000) { if (debugMode) DIAG(F("\nWACK-OK polls=%d, max=%dmA, pulse=%duS"),ackPollCount, ackMaxCurrent, pulseDuration); ackReceived=true; DCCWaveform::progTrack.killRemainingRepeats(); // probably no need after 8.5ms!! break; // we have a genuine ACK result } - if (debugMode) DIAG(F("\nWACK-bad pulse polls=%d, max=%dmA, pulse=%duS"), ackPollCount, ackMaxCurrent, pulseDuration); + if (debugMode) DIAG(F("\nWACK-bad pulse polls=%d, max=%dmA, now=%dmA, pulse=%duS"), ackPollCount, ackMaxCurrent,current, pulseDuration); ackPulseStart=0; // We have detected a too-short or too-long pulse so ignore and wait for next leading edge return; // keep waiting } diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index f935c66..b8bc54e 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -45,7 +45,7 @@ void DCCEXParser::loop(Stream & stream) { } else if (ch == '>') { buffer[bufferLength]='\0'; - parse( stream, buffer); + parse( stream, buffer, false); // Parse this allowing async responses inCommandPayload = false; break; } else if(inCommandPayload) { @@ -109,8 +109,9 @@ void DCCEXParser::setFilter(FILTER_CALLBACK filter) { } // See documentation on DCC class for info on this section -void DCCEXParser::parse(Print & stream, const byte *com) { +void DCCEXParser::parse(Print & stream, const byte *com, bool banAsync) { DIAG(F("\nPARSING:%s\n"),com); + asyncBanned=banAsync; (void) EEPROM; // tell compiler not to warn thi is unused int p[MAX_PARAMS]; byte params=splitValues(p, com); @@ -353,7 +354,7 @@ bool DCCEXParser::parseS( Print & stream,int params, int p[]) { // CALLBACKS must be static bool DCCEXParser::stashCallback(Print & stream,int p[MAX_PARAMS]) { - if (stashBusy) return false; + if (stashBusy || asyncBanned) return false; stashBusy=true; stashStream=stream; memcpy(stashP,p,MAX_PARAMS*sizeof(p[0])); diff --git a/DCCEXParser.h b/DCCEXParser.h index ed6bfb8..9408de9 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -8,7 +8,7 @@ struct DCCEXParser { DCCEXParser(); void loop(Stream & pstream); - void parse(Print & stream, const byte * command); + void parse(Print & stream, const byte * command, bool banAsync); void flush(); static void setFilter(FILTER_CALLBACK filter); static const int MAX_PARAMS=10; // Must not exceed this @@ -18,6 +18,7 @@ struct DCCEXParser static const int MAX_BUFFER=50; // longest command sent in byte bufferLength=0; bool inCommandPayload=false; + bool asyncBanned; // true when called with stream that must complete before returning byte buffer[MAX_BUFFER+2]; int splitValues( int result[MAX_PARAMS], const byte * command); @@ -28,9 +29,10 @@ struct DCCEXParser static bool stashBusy; + static Print & stashStream; static int stashP[MAX_PARAMS]; - static bool stashCallback(Print & stream, int p[MAX_PARAMS]); + bool stashCallback(Print & stream, int p[MAX_PARAMS]); static void callback_W(int result); static void callback_B(int result); static void callback_R(int result); diff --git a/DIAG.h b/DIAG.h index e5d0213..9fe8fd3 100644 --- a/DIAG.h +++ b/DIAG.h @@ -2,8 +2,5 @@ #define DIAG_h #include "StringFormatter.h" -#ifndef DIAG_ENABLED - #define DIAG_ENABLED true -#endif -#define DIAG if (DIAG_ENABLED) StringFormatter::print +#define DIAG StringFormatter::print #endif diff --git a/PWMServoDriver.cpp b/PWMServoDriver.cpp index 8e2edf4..75af8e1 100644 --- a/PWMServoDriver.cpp +++ b/PWMServoDriver.cpp @@ -25,7 +25,6 @@ #include #include #include "PWMServoDriver.h" -#define DIAG_ENABLED true #include "DIAG.h"