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

Better diagnostics

This commit is contained in:
Asbelos 2020-05-26 09:44:20 +01:00
parent a43db19cc0
commit 28be07610a
4 changed files with 7 additions and 6 deletions

View File

@ -28,7 +28,7 @@ void setup() {
for (byte x=0;x<sizeof(cvnums)/sizeof(cvnums[0]);x++) {
int value=DCC::readCV(cvnums[x]);
DIAG(F("\nCV %d = %d 0x%x %s"),cvnums[x],value,value, value>=0?" VERIFIED OK":"FAILED VERIFICATION");
DIAG(F("\nCV %d = %d 0x%x %s\n"),cvnums[x],value,value, value>=0?" VERIFIED OK":"FAILED VERIFICATION");
}
DIAG(F("\n===== CVReader done ==============================\n"));
DIAG(F("\nReady for JMRI commands\n"));

View File

@ -182,6 +182,7 @@ byte DCC::cv2(int cv) {
bool DCC::verifyCV(int cv, byte value) {
byte message[] = { cv1(0x74, cv), cv2(cv), value};
DIAG(F("\n\nVerifying cv %d = %d"),cv, value);
DCCWaveform::progTrack.schedulePacket(message, sizeof(message), 5);
return DCCWaveform::progTrack.getAck();
}

View File

@ -83,7 +83,7 @@ DCCWaveform::DCCWaveform(byte powerPinNo, byte directionPinNo, byte sensePinNo,
void DCCWaveform::setPowerMode(POWERMODE mode) {
powerMode=mode;
digitalWrite2f(powerPin, mode==POWERMODE::ON ? HIGH:LOW);
if (mode==POWERMODE::ON) schedulePacket(resetMessage,2,20);
if (mode==POWERMODE::ON) delay(200);
}
@ -213,7 +213,7 @@ void DCCWaveform::checkRailcom() {
// Wait until there is no packet pending, then make this pending
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
if (byteCount>=MAX_PACKET_SIZE) return; // allow for chksum
while(packetPending) delay(1);
while(packetPending);
byte checksum=0;
for (int b=0;b<byteCount; b++) {
@ -233,7 +233,7 @@ bool DCCWaveform::getAck()
if (isMainTrack) return false; // cant do this on main track
while(packetPending) delay(1); // wait until transmitter has started transmitting the message
while(packetPending); // wait until transmitter has started transmitting the message
unsigned long timeout=millis()+ACK_TIMEOUT;
int maxCurrent=0;
bool result=false;
@ -257,6 +257,6 @@ bool DCCWaveform::getAck()
}
// The following DIAG is really useful as it can show how long and how far the
// current changes during an ACK from the decoder.
// DIAG(F("\nack=%d max=%d, up=%d, down=%d "),result,maxCurrent, upsamples,downsamples);
DIAG(F("\nack=%d max=%d, up=%d, down=%d "),result,maxCurrent, upsamples,downsamples);
return result;
}

View File

@ -16,7 +16,7 @@ const int POWER_SAMPLE_OVERLOAD_WAIT = 4000;
// ACK current analogRead values (vary depending on motor shield and cpu voltage)
const int ACK_TIMEOUT = 25 ; // millis getAck is prepared to wait for a signal
const int ACK_MAX_NOT_PULSE = 10 ; // current below which this is NOT a pulse any more
const int ACK_MAX_NOT_PULSE = 40 ; // current below which this is NOT a pulse any more
const int ACK_MIN_PULSE = 50 ; // current above which a pulse is recognised
const int PREAMBLE_BITS_MAIN = 20;