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

3.0.9 newlines

This commit is contained in:
Asbelos 2021-03-30 22:01:37 +01:00
parent 76c2b5ae91
commit a0538ca61b
7 changed files with 52 additions and 51 deletions

View File

@ -49,7 +49,7 @@ byte DCC::joinRelay=UNUSED_PIN;
void DCC::begin(const FSH * motorShieldName, MotorDriver * mainDriver, MotorDriver* progDriver) {
shieldName=(FSH *)motorShieldName;
DIAG(F("DCC-EX V-%S / %S / %S G-%S"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
StringFormatter::send(Serial,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
// Load stuff from EEprom
(void)EEPROM; // tell compiler not to warn this is unused
@ -881,10 +881,10 @@ void DCC::callback(int value) {
for (int reg = 0; reg < MAX_LOCOS; reg++) {
if (speedTable[reg].loco>0) {
used ++;
StringFormatter::send(stream,F("\ncab=%d, speed=%d, dir=%c "),
StringFormatter::send(stream,F("cab=%d, speed=%d, dir=%c \n"),
speedTable[reg].loco, speedTable[reg].speedCode & 0x7f,(speedTable[reg].speedCode & 0x80) ? 'F':'R');
}
}
StringFormatter::send(stream,F("\nUsed=%d, max=%d\n"),used,MAX_LOCOS);
StringFormatter::send(stream,F("Used=%d, max=%d\n"),used,MAX_LOCOS);
}

View File

@ -311,9 +311,9 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
DCC::setThrottle(cab, tspeed, direction);
if (params == 4)
StringFormatter::send(stream, F("<T %d %d %d>"), p[0], p[2], p[3]);
StringFormatter::send(stream, F("<T %d %d %d>\n"), p[0], p[2], p[3]);
else
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return;
}
case 'f': // FUNCTION <f CAB BYTE1 [BYTE2]>
@ -449,21 +449,21 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
DCCWaveform::progTrack.setPowerMode(mode);
if (mode == POWERMODE::OFF)
DCC::setProgTrackBoost(false); // Prog track boost mode will not outlive prog track off
StringFormatter::send(stream, F("<p%c>"), opcode);
StringFormatter::send(stream, F("<p%c>\n"), opcode);
return;
}
switch (p[0])
{
case HASH_KEYWORD_MAIN:
DCCWaveform::mainTrack.setPowerMode(mode);
StringFormatter::send(stream, F("<p%c MAIN>"), opcode);
StringFormatter::send(stream, F("<p%c MAIN>\n"), opcode);
return;
case HASH_KEYWORD_PROG:
DCCWaveform::progTrack.setPowerMode(mode);
if (mode == POWERMODE::OFF)
DCC::setProgTrackBoost(false); // Prog track boost mode will not outlive prog track off
StringFormatter::send(stream, F("<p%c PROG>"), opcode);
StringFormatter::send(stream, F("<p%c PROG>\n"), opcode);
return;
case HASH_KEYWORD_JOIN:
DCCWaveform::mainTrack.setPowerMode(mode);
@ -471,10 +471,10 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
if (mode == POWERMODE::ON)
{
DCC::setProgTrackSyncMain(true);
StringFormatter::send(stream, F("<p1 JOIN>"), opcode);
StringFormatter::send(stream, F("<p1 JOIN>\n"), opcode);
}
else
StringFormatter::send(stream, F("<p0>"));
StringFormatter::send(stream, F("<p0>\n"));
return;
}
break;
@ -487,9 +487,9 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
case 'c': // SEND METER RESPONSES <c>
// <c MeterName value C/V unit min max res warn>
StringFormatter::send(stream, F("<c CurrentMAIN %d C Milli 0 %d 1 %d>"), DCCWaveform::mainTrack.getCurrentmA(),
StringFormatter::send(stream, F("<c CurrentMAIN %d C Milli 0 %d 1 %d>\n"), DCCWaveform::mainTrack.getCurrentmA(),
DCCWaveform::mainTrack.getMaxmA(), DCCWaveform::mainTrack.getTripmA());
StringFormatter::send(stream, F("<a %d>"), DCCWaveform::mainTrack.get1024Current()); //'a' message deprecated, remove once JMRI 4.22 is available
StringFormatter::send(stream, F("<a %d>\n"), DCCWaveform::mainTrack.get1024Current()); //'a' message deprecated, remove once JMRI 4.22 is available
return;
case 'Q': // SENSORS <Q>
@ -497,8 +497,8 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
return;
case 's': // <s>
StringFormatter::send(stream, F("<p%d>"), DCCWaveform::mainTrack.getPowerMode() == POWERMODE::ON);
StringFormatter::send(stream, F("<iDCC-EX V-%S / %S / %S G-%S>"), F(VERSION), F(ARDUINO_TYPE), DCC::getMotorShieldName(), F(GITHUB_SHA));
StringFormatter::send(stream, F("<p%d>\n"), DCCWaveform::mainTrack.getPowerMode() == POWERMODE::ON);
StringFormatter::send(stream, F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), DCC::getMotorShieldName(), F(GITHUB_SHA));
Turnout::printAll(stream); //send all Turnout states
Output::printAll(stream); //send all Output states
Sensor::printAll(stream); //send all Sensor states
@ -507,12 +507,12 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
case 'E': // STORE EPROM <E>
EEStore::store();
StringFormatter::send(stream, F("<e %d %d %d>"), EEStore::eeStore->data.nTurnouts, EEStore::eeStore->data.nSensors, EEStore::eeStore->data.nOutputs);
StringFormatter::send(stream, F("<e %d %d %d>\n"), EEStore::eeStore->data.nTurnouts, EEStore::eeStore->data.nSensors, EEStore::eeStore->data.nOutputs);
return;
case 'e': // CLEAR EPROM <e>
EEStore::clear();
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return;
case ' ': // < >
@ -525,7 +525,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
return;
case '#': // NUMBER OF LOCOSLOTS <#>
StringFormatter::send(stream, F("<# %d>"), MAX_LOCOS);
StringFormatter::send(stream, F("<# %d>\n"), MAX_LOCOS);
return;
case '-': // Forget Loco <- [cab]>
@ -558,7 +558,7 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream)
} // end of opcode switch
// Any fallout here sends an <X>
StringFormatter::send(stream, F("<X>"));
StringFormatter::send(stream, F("<X>\n"));
}
bool DCCEXParser::parseZ(Print *stream, int params, int p[])
@ -573,20 +573,20 @@ bool DCCEXParser::parseZ(Print *stream, int params, int p[])
if (o == NULL)
return false;
o->activate(p[1]);
StringFormatter::send(stream, F("<Y %d %d>"), p[0], p[1]);
StringFormatter::send(stream, F("<Y %d %d>\n"), p[0], p[1]);
}
return true;
case 3: // <Z ID PIN INVERT>
if (!Output::create(p[0], p[1], p[2], 1))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
case 1: // <Z ID>
if (!Output::remove(p[0]))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
case 0: // <Z> list Output definitions
@ -595,7 +595,7 @@ bool DCCEXParser::parseZ(Print *stream, int params, int p[])
for (Output *tt = Output::firstOutput; tt != NULL; tt = tt->nextOutput)
{
gotone = true;
StringFormatter::send(stream, F("<Y %d %d %d %d>"), tt->data.id, tt->data.pin, tt->data.iFlag, tt->data.oStatus);
StringFormatter::send(stream, F("<Y %d %d %d %d>\n"), tt->data.id, tt->data.pin, tt->data.iFlag, tt->data.oStatus);
}
return gotone;
}
@ -657,7 +657,7 @@ bool DCCEXParser::parseT(Print *stream, int params, int p[])
for (Turnout *tt = Turnout::firstTurnout; tt != NULL; tt = tt->nextTurnout)
{
gotOne = true;
StringFormatter::send(stream, F("<H %d %d %d %d>"), tt->data.id, tt->data.address,
StringFormatter::send(stream, F("<H %d %d %d %d>\n"), tt->data.id, tt->data.address,
tt->data.subAddress, (tt->data.tStatus & STATUS_ACTIVE)!=0);
}
return gotOne; // will <X> if none found
@ -666,7 +666,7 @@ bool DCCEXParser::parseT(Print *stream, int params, int p[])
case 1: // <T id> delete turnout
if (!Turnout::remove(p[0]))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
case 2: // <T id 0|1> activate turnout
@ -675,14 +675,14 @@ bool DCCEXParser::parseT(Print *stream, int params, int p[])
if (!tt)
return false;
tt->activate(p[1]);
StringFormatter::send(stream, F("<H %d %d>"), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0);
StringFormatter::send(stream, F("<H %d %d>\n"), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0);
}
return true;
case 3: // <T id addr subaddr> define turnout
if (!Turnout::create(p[0], p[1], p[2]))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
default:
@ -698,13 +698,13 @@ bool DCCEXParser::parseS(Print *stream, int params, int p[])
case 3: // <S id pin pullup> create sensor. pullUp indicator (0=LOW/1=HIGH)
if (!Sensor::create(p[0], p[1], p[2]))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
case 1: // S id> remove sensor
if (!Sensor::remove(p[0]))
return false;
StringFormatter::send(stream, F("<O>"));
StringFormatter::send(stream, F("<O>\n"));
return true;
case 0: // <S> list sensor definitions
@ -712,7 +712,7 @@ bool DCCEXParser::parseS(Print *stream, int params, int p[])
return false;
for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor)
{
StringFormatter::send(stream, F("<Q %d %d %d>"), tt->data.snum, tt->data.pin, tt->data.pullUp);
StringFormatter::send(stream, F("<Q %d %d %d>\n"), tt->data.snum, tt->data.pin, tt->data.pullUp);
}
return true;
@ -734,23 +734,23 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[])
return true;
case HASH_KEYWORD_RAM: // <D RAM>
StringFormatter::send(stream, F("\nFree memory=%d\n"), minimumFreeMemory());
StringFormatter::send(stream, F("Free memory=%d\n"), minimumFreeMemory());
break;
case HASH_KEYWORD_ACK: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX] Value>
if (params >= 3) {
if (p[1] == HASH_KEYWORD_LIMIT) {
DCCWaveform::progTrack.setAckLimit(p[2]);
StringFormatter::send(stream, F("\nAck limit=%dmA\n"), p[2]);
StringFormatter::send(stream, F("Ack limit=%dmA\n"), p[2]);
} else if (p[1] == HASH_KEYWORD_MIN) {
DCCWaveform::progTrack.setMinAckPulseDuration(p[2]);
StringFormatter::send(stream, F("\nAck min=%dus\n"), p[2]);
StringFormatter::send(stream, F("Ack min=%dus\n"), p[2]);
} else if (p[1] == HASH_KEYWORD_MAX) {
DCCWaveform::progTrack.setMaxAckPulseDuration(p[2]);
StringFormatter::send(stream, F("\nAck max=%dus\n"), p[2]);
StringFormatter::send(stream, F("Ack max=%dus\n"), p[2]);
}
} else {
StringFormatter::send(stream, F("\nAck diag %S\n"), onOff ? F("on") : F("off"));
StringFormatter::send(stream, F("Ack diag %S\n"), onOff ? F("on") : F("off"));
Diag::ACK = onOff;
}
return true;
@ -826,42 +826,42 @@ void DCCEXParser::commitAsyncReplyStream() {
void DCCEXParser::callback_W(int result)
{
StringFormatter::send(getAsyncReplyStream(),
F("<r%d|%d|%d %d>"), stashP[2], stashP[3], stashP[0], result == 1 ? stashP[1] : -1);
F("<r%d|%d|%d %d>\n"), stashP[2], stashP[3], stashP[0], result == 1 ? stashP[1] : -1);
commitAsyncReplyStream();
}
void DCCEXParser::callback_B(int result)
{
StringFormatter::send(getAsyncReplyStream(),
F("<r%d|%d|%d %d %d>"), stashP[3], stashP[4], stashP[0], stashP[1], result == 1 ? stashP[2] : -1);
F("<r%d|%d|%d %d %d>\n"), stashP[3], stashP[4], stashP[0], stashP[1], result == 1 ? stashP[2] : -1);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Vbit(int result)
{
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d %d>"), stashP[0], stashP[1], result);
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d %d>\n"), stashP[0], stashP[1], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Vbyte(int result)
{
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d>"), stashP[0], result);
StringFormatter::send(getAsyncReplyStream(), F("<v %d %d>\n"), stashP[0], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_R(int result)
{
StringFormatter::send(getAsyncReplyStream(), F("<r%d|%d|%d %d>"), stashP[1], stashP[2], stashP[0], result);
StringFormatter::send(getAsyncReplyStream(), F("<r%d|%d|%d %d>\n"), stashP[1], stashP[2], stashP[0], result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Rloco(int result)
{
StringFormatter::send(getAsyncReplyStream(), F("<r %d>"), result);
StringFormatter::send(getAsyncReplyStream(), F("<r %d>\n"), result);
commitAsyncReplyStream();
}
void DCCEXParser::callback_Wloco(int result)
{
if (result==1) result=stashP[0]; // pick up original requested id from command
StringFormatter::send(getAsyncReplyStream(), F("<w %d>"), result);
StringFormatter::send(getAsyncReplyStream(), F("<w %d>\n"), result);
commitAsyncReplyStream();
}

View File

@ -88,7 +88,7 @@ the state of any outputs being monitored or controlled by a separate interface o
// print all output states to stream
void Output::printAll(Print *stream){
for (Output *tt = Output::firstOutput; tt != NULL; tt = tt->nextOutput)
StringFormatter::send(stream, F("<Y %d %d>"), tt->data.id, tt->data.oStatus);
StringFormatter::send(stream, F("<Y %d %d>\n"), tt->data.id, tt->data.oStatus);
} // Output::printAll
void Output::activate(int s){

View File

@ -101,7 +101,7 @@ void Sensor::checkAll(Print *stream){
// make the change
readingSensor->active = !sensorstate;
readingSensor->latchdelay=0; // reset
if (stream != NULL) StringFormatter::send(stream, F("<%c %d>"), readingSensor->active ? 'Q' : 'q', readingSensor->data.snum);
if (stream != NULL) StringFormatter::send(stream, F("<%c %d>\n"), readingSensor->active ? 'Q' : 'q', readingSensor->data.snum);
}
readingSensor=readingSensor->nextSensor;
@ -117,7 +117,7 @@ void Sensor::printAll(Print *stream){
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
if (stream != NULL)
StringFormatter::send(stream, F("<%c %d>"), tt->active ? 'Q' : 'q', tt->data.snum);
StringFormatter::send(stream, F("<%c %d>\n"), tt->active ? 'Q' : 'q', tt->data.snum);
} // loop over all sensors
} // Sensor::printAll

View File

@ -39,21 +39,21 @@ bool Diag::LCN=false;
void StringFormatter::diag( const FSH* input...) {
if (!diagSerial) return;
diagSerial->print(F("\n<* "));
diagSerial->print(F("<* "));
va_list args;
va_start(args, input);
send2(diagSerial,input,args);
diagSerial->print(F(" *>"));
diagSerial->print(F(" *>\n"));
}
void StringFormatter::lcd(byte row, const FSH* input...) {
va_list args;
// Issue the LCD as a diag first
send(diagSerial,F("\n<* LCD%d:"),row);
send(diagSerial,F("<* LCD%d:"),row);
va_start(args, input);
send2(diagSerial,input,args);
send(diagSerial,F(" *>"));
send(diagSerial,F(" *>\n"));
if (!LCDDisplay::lcdDisplay) return;
LCDDisplay::lcdDisplay->setRow(row);

View File

@ -29,7 +29,7 @@
// print all turnout states to stream
void Turnout::printAll(Print *stream){
for (Turnout *tt = Turnout::firstTurnout; tt != NULL; tt = tt->nextTurnout)
StringFormatter::send(stream, F("<H %d %d>"), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0);
StringFormatter::send(stream, F("<H %d %d>\n"), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0);
} // Turnout::printAll
bool Turnout::activate(int n,bool state){

View File

@ -3,8 +3,9 @@
#include "StringFormatter.h"
#define VERSION "3.0.8"
// 3.0.8 Includes <* > wraps around DIAGs for the benefit of JMRI.
#define VERSION "3.0.9"
// 3.0.9 rearranges serial newlines for the benefit of JMRI.
// 3.0.8 Includes <* *> wraps around DIAGs for the benefit of JMRI.
// 3.0.7 Includes merge from assortedBits (many changes) and ACK manager change for lazy decoders
// 3.0.6 Includes:
// Fix Bug that did not let us transmit 5 byte sized packets like PoM