2020-05-24 17:07:16 +02:00
|
|
|
#include "DCC.h"
|
2020-05-24 00:02:54 +02:00
|
|
|
#include "DIAG.h"
|
2020-05-25 14:38:18 +02:00
|
|
|
#include "JMRIParser.h"
|
2020-05-24 00:22:12 +02:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-05-24 17:07:16 +02:00
|
|
|
|
2020-05-24 00:02:54 +02:00
|
|
|
const int cvnums[]={1,2,3,4,5,17,18,19,21,22,29};
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
2020-05-24 17:07:16 +02:00
|
|
|
DCC::begin();
|
2020-05-24 00:22:12 +02:00
|
|
|
|
|
|
|
DIAG(F("\n===== CVReader begin ==============================\n"));
|
2020-05-24 00:02:54 +02:00
|
|
|
|
|
|
|
for (byte x=0;x<sizeof(cvnums)/sizeof(cvnums[0]);x++) {
|
2020-05-24 17:07:16 +02:00
|
|
|
int value=DCC::readCV(cvnums[x]);
|
2020-05-24 00:22:12 +02:00
|
|
|
DIAG(F("\nCV %d = %d 0x%x %s"),cvnums[x],value,value, value>=0?" VERIFIED OK":"FAILED VERIFICATION");
|
2020-05-24 00:02:54 +02:00
|
|
|
}
|
2020-05-25 14:38:18 +02:00
|
|
|
DIAG(F("\n===== CVReader done ==============================\n"));
|
2020-05-24 00:02:54 +02:00
|
|
|
|
2020-05-25 14:38:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
DIAG(F("\nReady for JMRI\n"));
|
2020-05-24 00:02:54 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 14:38:18 +02:00
|
|
|
const byte MAX_BUFFER=100;
|
|
|
|
char buffer[MAX_BUFFER];
|
|
|
|
byte bufferLength=0;
|
|
|
|
bool inCommandPayload=false;
|
|
|
|
|
2020-05-24 00:02:54 +02:00
|
|
|
void loop() {
|
2020-05-24 17:07:16 +02:00
|
|
|
DCC::loop();
|
2020-05-25 14:38:18 +02:00
|
|
|
while(Serial.available()) {
|
|
|
|
if (bufferLength==MAX_BUFFER) {
|
|
|
|
DIAG(F("\n**Buffer cleared**\n"));
|
|
|
|
bufferLength=0;
|
|
|
|
inCommandPayload=false;
|
|
|
|
}
|
|
|
|
char ch = Serial.read();
|
|
|
|
if (ch == '<') {
|
|
|
|
inCommandPayload = true;
|
|
|
|
bufferLength=0;
|
|
|
|
buffer[0]='\0';
|
|
|
|
}
|
|
|
|
else if (ch == '>') {
|
|
|
|
buffer[bufferLength]='\0';
|
2020-05-25 20:59:47 +02:00
|
|
|
JMRIParser::parse(Serial, buffer);
|
2020-05-25 14:38:18 +02:00
|
|
|
inCommandPayload = false;
|
|
|
|
} else if(inCommandPayload) {
|
|
|
|
buffer[bufferLength++]= ch;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 00:22:12 +02:00
|
|
|
}
|
2020-05-25 14:38:18 +02:00
|
|
|
|
|
|
|
|