Sensor::status(stream);
break;
case 's': //
StringFormatter::send(stream,F(""),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON );
StringFormatter::send(stream,F(""), BOARD_NAME, VERSION, __DATE__, __TIME__ );
// TODO Send stats of speed reminders table
// TODO send status of turnouts etc etc
return;
case 'E': // STORE EPROM
EEStore::store();
StringFormatter::send(stream,F(""), EEStore::eeStore->data.nTurnouts, EEStore::eeStore->data.nSensors, EEStore::eeStore->data.nOutputs);
return;
case 'e': // CLEAR EPROM
EEStore::clear();
StringFormatter::send(stream, F(""));
return;
case ' ': // < >
StringFormatter::send(stream,F("\n"));
return;
case 'D': // < >
DCC::setDebug(p[0]==1);
DIAG(F("\nDCC DEBUG MODE %d"),p[0]==1);
return;
default: //anything else will drop out to
break;
} // end of opcode switch
// Any fallout here sends an
StringFormatter::send(stream, F(""));
}
bool DCCEXParser::parseZ( Print & stream,int params, int p[]){
switch (params) {
case 2: //
{
Output * o=Output::get(p[0]);
if(o==NULL) return false;
o->activate(p[1]);
StringFormatter::send(stream,F(""), p[0],p[1]);
}
return true;
case 3: //
Output::create(p[0],p[1],p[2],1);
return true;
case 1: //
return Output::remove(p[0]);
case 0: //
return Output::showAll(stream);
default:
return false;
}
}
//===================================
bool DCCEXParser::parsef(Print & stream, int params, int p[]) {
// JMRI sends this info in DCC message format but it's not exactly
// convenient for other processing
if (params==2) {
byte groupcode=p[1] & 0xE0;
if (groupcode == 0x80) {
byte normalized= (p[1]<<1 & 0x1e ) | (p[1]>>4 & 0x01);
funcmap(p[0],normalized,0,4);
}
else if (groupcode == 0xC0) {
funcmap(p[0],p[1],5,8);
}
else if (groupcode == 0xA0) {
funcmap(p[0],p[1],9,12);
}
}
if (params==3) {
if (p[1]==222) funcmap(p[0],p[2],13,20);
else if (p[1]==223) funcmap(p[0],p[2],21,28);
}
(void)stream;// NO RESPONSE
return true;
}
void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) {
for (int i=fstart;i<=fstop;i++) {
DCC::setFn(cab, i, value & 1);
value>>=1;
}
}
//===================================
bool DCCEXParser::parseT(Print & stream, int params, int p[]) {
switch(params){
case 0: //
return (Turnout::showAll(stream)); break;
case 1: //
if (!Turnout::remove(p[0])) return false;
StringFormatter::send(stream,F(""));
return true;
case 2: //
if (!Turnout::activate(p[0],p[1])) return false;
Turnout::show(stream,p[0]);
return true;
case 3: //
if (!Turnout::create(p[0],p[1],p[2])) return false;
StringFormatter::send(stream,F(""));
return true;
default:
return false; // will
}
}
bool DCCEXParser::parseS( Print & stream,int params, int p[]) {
switch(params){
case 3: // argument is string with id number of sensor followed by a pin number and pullUp indicator (0=LOW/1=HIGH)
Sensor::create(p[0],p[1],p[2]);
return true;
case 1: // argument is a string with id number only
if (Sensor::remove(p[0])) return true;
break;
case -1: // no arguments
Sensor::show(stream);
return true;
default: // invalid number of arguments
break;
}
return false;
}
// CALLBACKS must be static
bool DCCEXParser::stashCallback(Print & stream,int p[MAX_PARAMS]) {
if (stashBusy || asyncBanned) return false;
stashBusy=true;
stashStream=stream;
memcpy(stashP,p,MAX_PARAMS*sizeof(p[0]));
return true;
}
void DCCEXParser::callback_W(int result) {
StringFormatter::send(stashStream,F(""), stashP[2], stashP[3],stashP[0],result==1?stashP[1]:-1);
stashBusy=false;
}
void DCCEXParser::callback_B(int result) {
StringFormatter::send(stashStream,F(""), stashP[3],stashP[4], stashP[0],stashP[1],result==1?stashP[2]:-1);
stashBusy=false;
}
void DCCEXParser::callback_R(int result) {
StringFormatter::send(stashStream,F(""),stashP[1],stashP[2],stashP[0],result);
stashBusy=false;
}