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:
parent
bec57345f1
commit
47a4d2dae9
4
DCC.cpp
4
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
|
||||
}
|
||||
|
@ -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]));
|
||||
|
@ -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);
|
||||
|
5
DIAG.h
5
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
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include "PWMServoDriver.h"
|
||||
#define DIAG_ENABLED true
|
||||
#include "DIAG.h"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user