mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
Cleanup & comments
This commit is contained in:
parent
2ebf1a6f66
commit
efc2197a7e
37
CVReader.ino
37
CVReader.ino
|
@ -1,5 +1,21 @@
|
||||||
#include "DCCWaveform.h"
|
#include "DCCWaveform.h"
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
|
|
||||||
|
/* this code is here to test the waveforwe generator and reveal the issues involved in programming track operations.
|
||||||
|
*
|
||||||
|
* It tests the Waveform genartor and demonstrates how a DCC API function can be simply written
|
||||||
|
* to transmit and receive DCC data on the programming track.
|
||||||
|
*
|
||||||
|
* Important... DCCWaveform.h contains hardware specific confioguration settings
|
||||||
|
* that you will need to check.
|
||||||
|
*
|
||||||
|
* Notes: the waveform generator sends reset packets on progTrack when it has nothing better to do, this means that
|
||||||
|
* the decoder does not step out of service mode. (The main track sends idles).
|
||||||
|
* It also means that the API functions dont have to mess with reset packets.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
bool verifyCV(int cv, byte bValue);
|
bool verifyCV(int cv, byte bValue);
|
||||||
int readCv(int cv);
|
int readCv(int cv);
|
||||||
const int cvnums[]={1,2,3,4,5,17,18,19,21,22,29};
|
const int cvnums[]={1,2,3,4,5,17,18,19,21,22,29};
|
||||||
|
@ -7,20 +23,22 @@ const int cvnums[]={1,2,3,4,5,17,18,19,21,22,29};
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
DCCWaveform::begin();
|
DCCWaveform::begin();
|
||||||
Serial.println(F("CVReader"));
|
|
||||||
|
|
||||||
DIAG(F("\n===================================\n"));
|
DIAG(F("\n===== CVReader begin ==============================\n"));
|
||||||
|
|
||||||
for (byte x=0;x<sizeof(cvnums)/sizeof(cvnums[0]);x++) {
|
for (byte x=0;x<sizeof(cvnums)/sizeof(cvnums[0]);x++) {
|
||||||
DIAG(F("\n\nCV VERIFICATION %d = %s\n"),cvnums[x],readCV(cvnums[x])>=0?"OK":"FAIL");
|
int value=readCV(cvnums[x]);
|
||||||
|
DIAG(F("\nCV %d = %d 0x%x %s"),cvnums[x],value,value, value>=0?" VERIFIED OK":"FAILED VERIFICATION");
|
||||||
}
|
}
|
||||||
|
|
||||||
DIAG(F("\nProgram complete, press reset to retry"));
|
DIAG(F("\nProgram complete, press reset to retry"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
DCCWaveform::loop();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// Two helpers to make API functions look simpler
|
||||||
|
|
||||||
byte cv1(byte opcode, int cv) {
|
byte cv1(byte opcode, int cv) {
|
||||||
cv--;
|
cv--;
|
||||||
|
@ -31,13 +49,9 @@ byte cv2(int cv) {
|
||||||
return lowByte(cv);
|
return lowByte(cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
//// The functions below are lifted from the DCCApi for easy testing and experimentation.
|
// The functions below are lifted from the DCCApi and then fixed up
|
||||||
// Once reliable, tha DCCApi should be updated to match
|
// Once reliable, tha DCCApi should be updated to match
|
||||||
bool verifyCV(int cv, byte value) {
|
bool verifyCV(int cv, byte value) {
|
||||||
|
|
||||||
delay(2); // allow for decoder to quiesce latest pulse
|
|
||||||
|
|
||||||
|
|
||||||
byte message[] = {
|
byte message[] = {
|
||||||
cv1(0x74,cv) , // set-up to re-verify entire byte
|
cv1(0x74,cv) , // set-up to re-verify entire byte
|
||||||
cv2(cv),
|
cv2(cv),
|
||||||
|
@ -59,9 +73,10 @@ int readCV(int cv)
|
||||||
|
|
||||||
for (int i = 0; i<8; i++) {
|
for (int i = 0; i<8; i++) {
|
||||||
message[2] = 0xE8 + i;
|
message[2] = 0xE8 + i;
|
||||||
DCCWaveform::progTrack.schedulePacket(message,sizeof(message), 4); // NMRA recommends 5 rerad packets
|
DCCWaveform::progTrack.schedulePacket(message,sizeof(message), 4); // NMRA recommends 5 read packets
|
||||||
value+= (DCCWaveform::progTrack.getAck()<<i);
|
value+= (DCCWaveform::progTrack.getAck()<<i);
|
||||||
}
|
}
|
||||||
DIAG(F("\n*** READ CV %d = %d ******\n"),cv,value);
|
|
||||||
|
// DIAG(F("\n*** readCV(%d) = %d ******\n"),cv,value);
|
||||||
return verifyCV(cv,value)?value:-1;
|
return verifyCV(cv,value)?value:-1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,6 +230,8 @@ bool DCCWaveform::getAck()
|
||||||
maxCurrent=max(maxCurrent,current);
|
maxCurrent=max(maxCurrent,current);
|
||||||
if (current<= ACK_MAX_NOT_PULSE)break;
|
if (current<= ACK_MAX_NOT_PULSE)break;
|
||||||
}
|
}
|
||||||
DIAG(F("\nack=%d max=%d, up=%d, down=%d "),result,maxCurrent, upsamples,downsamples);
|
// 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);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user