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

Cleanup and ACK debugs

This commit is contained in:
Asbelos 2020-07-01 16:58:48 +01:00
parent bec57345f1
commit 47a4d2dae9
5 changed files with 11 additions and 12 deletions

View File

@ -514,13 +514,13 @@ void DCC::ackManagerLoop() {
// detected trailing edge of pulse // detected trailing edge of pulse
long pulseDuration=micros()-ackPulseStart; 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); if (debugMode) DIAG(F("\nWACK-OK polls=%d, max=%dmA, pulse=%duS"),ackPollCount, ackMaxCurrent, pulseDuration);
ackReceived=true; ackReceived=true;
DCCWaveform::progTrack.killRemainingRepeats(); // probably no need after 8.5ms!! DCCWaveform::progTrack.killRemainingRepeats(); // probably no need after 8.5ms!!
break; // we have a genuine ACK result 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 ackPulseStart=0; // We have detected a too-short or too-long pulse so ignore and wait for next leading edge
return; // keep waiting return; // keep waiting
} }

View File

@ -45,7 +45,7 @@ void DCCEXParser::loop(Stream & stream) {
} }
else if (ch == '>') { else if (ch == '>') {
buffer[bufferLength]='\0'; buffer[bufferLength]='\0';
parse( stream, buffer); parse( stream, buffer, false); // Parse this allowing async responses
inCommandPayload = false; inCommandPayload = false;
break; break;
} else if(inCommandPayload) { } else if(inCommandPayload) {
@ -109,8 +109,9 @@ void DCCEXParser::setFilter(FILTER_CALLBACK filter) {
} }
// See documentation on DCC class for info on this section // 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); DIAG(F("\nPARSING:%s\n"),com);
asyncBanned=banAsync;
(void) EEPROM; // tell compiler not to warn thi is unused (void) EEPROM; // tell compiler not to warn thi is unused
int p[MAX_PARAMS]; int p[MAX_PARAMS];
byte params=splitValues(p, com); byte params=splitValues(p, com);
@ -353,7 +354,7 @@ bool DCCEXParser::parseS( Print & stream,int params, int p[]) {
// CALLBACKS must be static // CALLBACKS must be static
bool DCCEXParser::stashCallback(Print & stream,int p[MAX_PARAMS]) { bool DCCEXParser::stashCallback(Print & stream,int p[MAX_PARAMS]) {
if (stashBusy) return false; if (stashBusy || asyncBanned) return false;
stashBusy=true; stashBusy=true;
stashStream=stream; stashStream=stream;
memcpy(stashP,p,MAX_PARAMS*sizeof(p[0])); memcpy(stashP,p,MAX_PARAMS*sizeof(p[0]));

View File

@ -8,7 +8,7 @@ struct DCCEXParser
{ {
DCCEXParser(); DCCEXParser();
void loop(Stream & pstream); void loop(Stream & pstream);
void parse(Print & stream, const byte * command); void parse(Print & stream, const byte * command, bool banAsync);
void flush(); void flush();
static void setFilter(FILTER_CALLBACK filter); static void setFilter(FILTER_CALLBACK filter);
static const int MAX_PARAMS=10; // Must not exceed this 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 static const int MAX_BUFFER=50; // longest command sent in
byte bufferLength=0; byte bufferLength=0;
bool inCommandPayload=false; bool inCommandPayload=false;
bool asyncBanned; // true when called with stream that must complete before returning
byte buffer[MAX_BUFFER+2]; byte buffer[MAX_BUFFER+2];
int splitValues( int result[MAX_PARAMS], const byte * command); int splitValues( int result[MAX_PARAMS], const byte * command);
@ -28,9 +29,10 @@ struct DCCEXParser
static bool stashBusy; static bool stashBusy;
static Print & stashStream; static Print & stashStream;
static int stashP[MAX_PARAMS]; 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_W(int result);
static void callback_B(int result); static void callback_B(int result);
static void callback_R(int result); static void callback_R(int result);

5
DIAG.h
View File

@ -2,8 +2,5 @@
#define DIAG_h #define DIAG_h
#include "StringFormatter.h" #include "StringFormatter.h"
#ifndef DIAG_ENABLED #define DIAG StringFormatter::print
#define DIAG_ENABLED true
#endif
#define DIAG if (DIAG_ENABLED) StringFormatter::print
#endif #endif

View File

@ -25,7 +25,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h> #include <Wire.h>
#include "PWMServoDriver.h" #include "PWMServoDriver.h"
#define DIAG_ENABLED true
#include "DIAG.h" #include "DIAG.h"