mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Allow acks longer than 65535us and specify ack length in the <C ACK MAX 20 MS> format
This commit is contained in:
parent
7dadecb5df
commit
2481f1c5d6
12
DCCACK.cpp
12
DCCACK.cpp
|
@ -27,8 +27,8 @@
|
|||
#include "DCCWaveform.h"
|
||||
#include "TrackManager.h"
|
||||
|
||||
unsigned int DCCACK::minAckPulseDuration = 2000; // micros
|
||||
unsigned int DCCACK::maxAckPulseDuration = 20000; // micros
|
||||
unsigned long DCCACK::minAckPulseDuration = 2000; // micros
|
||||
unsigned long DCCACK::maxAckPulseDuration = 20000; // micros
|
||||
|
||||
MotorDriver * DCCACK::progDriver=NULL;
|
||||
ackOp const * DCCACK::ackManagerProg;
|
||||
|
@ -50,8 +50,8 @@ volatile uint8_t DCCACK::numAckSamples=0;
|
|||
uint8_t DCCACK::trailingEdgeCounter=0;
|
||||
|
||||
|
||||
unsigned int DCCACK::ackPulseDuration; // micros
|
||||
unsigned long DCCACK::ackPulseStart; // micros
|
||||
unsigned long DCCACK::ackPulseDuration; // micros
|
||||
unsigned long DCCACK::ackPulseStart; // micros
|
||||
volatile bool DCCACK::ackDetected;
|
||||
unsigned long DCCACK::ackCheckStart; // millis
|
||||
volatile bool DCCACK::ackPending;
|
||||
|
@ -127,7 +127,7 @@ bool DCCACK::checkResets(uint8_t numResets) {
|
|||
void DCCACK::setAckBaseline() {
|
||||
int baseline=progDriver->getCurrentRaw();
|
||||
ackThreshold= baseline + progDriver->mA2raw(ackLimitmA);
|
||||
if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"),
|
||||
if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %lus and %lus"),
|
||||
baseline,progDriver->raw2mA(baseline),
|
||||
ackThreshold,progDriver->raw2mA(ackThreshold),
|
||||
minAckPulseDuration, maxAckPulseDuration);
|
||||
|
@ -146,7 +146,7 @@ void DCCACK::setAckPending() {
|
|||
|
||||
byte DCCACK::getAck() {
|
||||
if (ackPending) return (2); // still waiting
|
||||
if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%uuS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration,
|
||||
if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%luS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration,
|
||||
ackMaxCurrent,progDriver->raw2mA(ackMaxCurrent), ackPulseDuration, numAckSamples, numAckGaps);
|
||||
if (ackDetected) return (1); // Yes we had an ack
|
||||
return(0); // pending set off but not detected means no ACK.
|
||||
|
|
10
DCCACK.h
10
DCCACK.h
|
@ -79,10 +79,10 @@ class DCCACK {
|
|||
static inline void setAckLimit(int mA) {
|
||||
ackLimitmA = mA;
|
||||
}
|
||||
static inline void setMinAckPulseDuration(unsigned int i) {
|
||||
static inline void setMinAckPulseDuration(unsigned long i) {
|
||||
minAckPulseDuration = i;
|
||||
}
|
||||
static inline void setMaxAckPulseDuration(unsigned int i) {
|
||||
static inline void setMaxAckPulseDuration(unsigned long i) {
|
||||
maxAckPulseDuration = i;
|
||||
}
|
||||
|
||||
|
@ -126,11 +126,11 @@ class DCCACK {
|
|||
static unsigned long ackCheckStart; // millis
|
||||
static unsigned int ackCheckDuration; // millis
|
||||
|
||||
static unsigned int ackPulseDuration; // micros
|
||||
static unsigned long ackPulseDuration; // micros
|
||||
static unsigned long ackPulseStart; // micros
|
||||
|
||||
static unsigned int minAckPulseDuration ; // micros
|
||||
static unsigned int maxAckPulseDuration ; // micros
|
||||
static unsigned long minAckPulseDuration ; // micros
|
||||
static unsigned long maxAckPulseDuration ; // micros
|
||||
static MotorDriver* progDriver;
|
||||
static volatile uint8_t numAckGaps;
|
||||
static volatile uint8_t numAckSamples;
|
||||
|
|
|
@ -1073,15 +1073,24 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
|
|||
#ifndef DISABLE_PROG
|
||||
case "ACK"_hk: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX|RETRY] Value>
|
||||
if (params >= 3) {
|
||||
long duration;
|
||||
if (p[1] == "LIMIT"_hk) {
|
||||
DCCACK::setAckLimit(p[2]);
|
||||
LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42>
|
||||
LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42>
|
||||
} else if (p[1] == "MIN"_hk) {
|
||||
DCCACK::setMinAckPulseDuration(p[2]);
|
||||
LCD(0, F("Ack Min=%uus"), p[2]); // <D ACK MIN 1500>
|
||||
if (params == 4 && p[3] == "MS"_hk)
|
||||
duration = p[2] * 1000L;
|
||||
else
|
||||
duration = p[2];
|
||||
DCCACK::setMinAckPulseDuration(duration);
|
||||
LCD(0, F("Ack Min=%lus"), duration); // <D ACK MIN 1500>
|
||||
} else if (p[1] == "MAX"_hk) {
|
||||
DCCACK::setMaxAckPulseDuration(p[2]);
|
||||
LCD(0, F("Ack Max=%uus"), p[2]); // <D ACK MAX 9000>
|
||||
if (params == 4 && p[3] == "MS"_hk) // <D ACK MAX 80 MS>
|
||||
duration = p[2] * 1000L;
|
||||
else
|
||||
duration = p[2];
|
||||
DCCACK::setMaxAckPulseDuration(duration);
|
||||
LCD(0, F("Ack Max=%lus"), duration); // <D ACK MAX 9000>
|
||||
} else if (p[1] == "RETRY"_hk) {
|
||||
if (p[2] >255) p[2]=3;
|
||||
LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCCACK::setAckRetry(p[2])); // <D ACK RETRY 2>
|
||||
|
|
Loading…
Reference in New Issue
Block a user