11 #ifdef ARDUINO_ARCH_AVR 14 #include "TextCommand.h" 15 #ifdef USE_TEXTCOMMAND 20 extern unsigned int __heap_start;
21 extern void *__brkval;
26 char TextCommand::commandString[MAX_COMMAND_LENGTH+1];
30 void TextCommand::init(
volatile RegisterList *_mRegs,
volatile RegisterList *_pRegs, CurrentMonitor *_mMonitor){
36 void TextCommand::process(){
39 #if defined(USE_ETHERNET) 41 EthernetClient client= DCCPP_INTERFACE.available();
45 if (DCCppConfig::Protocol == EthernetProtocol::HTTP) {
46 DCCPP_INTERFACE.println(
"HTTP/1.1 200 OK");
47 DCCPP_INTERFACE.println(
"Content-Type: text/html");
48 DCCPP_INTERFACE.println(
"Access-Control-Allow-Origin: *");
49 DCCPP_INTERFACE.println(
"Connection: close");
50 DCCPP_INTERFACE.println(
"");
53 while (client.connected() && client.available()) {
59 else if (strlen(commandString) < MAX_COMMAND_LENGTH)
60 sprintf(commandString,
"%s%c", commandString, c);
63 if (DCCppConfig::Protocol == EthernetProtocol::HTTP)
69 while (DCCPP_INTERFACE.available()>0) {
70 c = DCCPP_INTERFACE.read();
75 else if (strlen(commandString) < MAX_COMMAND_LENGTH)
76 sprintf(commandString,
"%s%c", commandString, c);
85 void TextCommand::parse(
char *com){
88 #ifdef DCCPP_DEBUG_MODE 90 Serial.println(F(
" command"));
116 DCCpp::mainRegs.setThrottle(com+1);
164 DCCpp::mainRegs.setFunction(com+1);
203 DCCpp::mainRegs.setAccessory(com+1);
213 Turnout::parse(com+1);
224 Output::parse(com+1);
235 Sensor::parse(com+1);
238 #ifdef DCCPP_PRINT_DCCPP 279 DCCpp::mainRegs.writeCVByteMain(com+1);
304 DCCpp::mainRegs.writeCVBitMain(com+1);
329 DCCpp::progRegs.writeCVByte(com+1);
355 DCCpp::progRegs.writeCVBit(com+1);
379 DCCpp::progRegs.readCV(com+1);
437 DCCPP_INTERFACE.print(
"<a");
439 DCCPP_INTERFACE.print(
">");
440 #if !defined(USE_ETHERNET) 441 DCCPP_INTERFACE.println(
"");
462 if(digitalRead(DCCppConfig::SignalEnablePinProg)==LOW)
463 DCCPP_INTERFACE.print(
"<p0>");
465 DCCPP_INTERFACE.print(
"<p1>");
466 #if !defined(USE_ETHERNET) 467 DCCPP_INTERFACE.println(
"");
470 for(
int i=1;i<=MAX_MAIN_REGISTERS;i++){
471 if(DCCpp::mainRegs.speedTable[i]==0)
473 DCCPP_INTERFACE.print(
"<T");
474 DCCPP_INTERFACE.print(i); DCCPP_INTERFACE.print(
" ");
475 if(DCCpp::mainRegs.speedTable[i]>0){
476 DCCPP_INTERFACE.print(DCCpp::mainRegs.speedTable[i]);
477 DCCPP_INTERFACE.print(
" 1>");
479 DCCPP_INTERFACE.print(- DCCpp::mainRegs.speedTable[i]);
480 DCCPP_INTERFACE.print(
" 0>");
482 #if !defined(USE_ETHERNET) 483 DCCPP_INTERFACE.println(
"");
486 DCCPP_INTERFACE.print(
"<iDCCpp LIBRARY BASE STATION FOR ARDUINO ");
490 DCCPP_INTERFACE.print(
": V-");
491 DCCPP_INTERFACE.print(VERSION);
492 DCCPP_INTERFACE.print(
" / ");
493 DCCPP_INTERFACE.print(__DATE__);
494 DCCPP_INTERFACE.print(
" ");
495 DCCPP_INTERFACE.print(__TIME__);
496 DCCPP_INTERFACE.print(
">");
497 #if !defined(USE_ETHERNET) 498 DCCPP_INTERFACE.println(
"");
501 DCCPP_INTERFACE.print(
"<N ");
502 #if defined(USE_ETHERNET) 503 DCCPP_INTERFACE.print(
"ETHERNET :");
504 DCCPP_INTERFACE.print(Ethernet.localIP());
505 DCCPP_INTERFACE.print(
">");
506 #if !defined(USE_ETHERNET) 507 DCCPP_INTERFACE.println(
"");
510 DCCPP_INTERFACE.println(
"SERIAL>");
513 #ifdef DCCPP_PRINT_DCCPP 544 DCCPP_INTERFACE.print(
"<e ");
545 DCCPP_INTERFACE.print(EEStore::data.nTurnouts);
546 DCCPP_INTERFACE.print(
" ");
547 DCCPP_INTERFACE.print(EEStore::data.nSensors);
548 DCCPP_INTERFACE.print(
" ");
549 DCCPP_INTERFACE.print(EEStore::data.nOutputs);
550 DCCPP_INTERFACE.print(
">");
551 #if !defined(USE_ETHERNET) 552 DCCPP_INTERFACE.println(
"");
573 DCCPP_INTERFACE.print(
"<O>");
574 #if !defined(USE_ETHERNET) 575 DCCPP_INTERFACE.println(
"");
596 DCCPP_INTERFACE.println(
"");
619 Serial.println(
"nEntering Diagnostic Mode...");
622 bitClear(TCCR1B,CS12);
624 bitClear(TCCR1B,CS10);
626 #if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) // Configuration for UNO 629 bitClear(TCCR0B,CS01);
630 bitClear(TCCR0B,CS00);
632 #else // Configuration for MEGA 634 bitClear(TCCR3B,CS32);
636 bitClear(TCCR3B,CS30);
669 DCCpp::mainRegs.writeTextPacket(com+1);
696 DCCpp::progRegs.writeTextPacket(com+1);
720 DCCPP_INTERFACE.print(
"<f");
721 DCCPP_INTERFACE.print((
int) &v - (__brkval == 0 ? (
int) &__heap_start : (
int) __brkval));
722 DCCPP_INTERFACE.print(
">");
723 #if !defined(USE_ETHERNET) 724 DCCPP_INTERFACE.println(
"");
744 DCCPP_INTERFACE.println(
"");
745 for(Register *p = DCCpp::mainRegs.reg; p <= DCCpp::mainRegs.maxLoadedReg;p++){
746 DCCPP_INTERFACE.print(
"M"); DCCPP_INTERFACE.print((
int)(p - DCCpp::mainRegs.reg)); DCCPP_INTERFACE.print(
":t");
747 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"t");
748 DCCPP_INTERFACE.print((
int)(p->activePacket)); DCCPP_INTERFACE.print(
"t");
749 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"t");
750 for(
int i=0;i<10;i++){
751 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"t");
753 DCCPP_INTERFACE.println(
"");
755 for(Register *p = DCCpp::progRegs.reg; p <= DCCpp::progRegs.maxLoadedReg;p++){
756 DCCPP_INTERFACE.print(
"P"); DCCPP_INTERFACE.print((
int)(p - DCCpp::progRegs.reg)); DCCPP_INTERFACE.print(
":t");
757 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"t");
758 DCCPP_INTERFACE.print((
int)p->activePacket); DCCPP_INTERFACE.print(
"t");
759 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"t");
760 for(
int i=0;i<10;i++){
761 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"t");
763 DCCPP_INTERFACE.println(
"");
765 DCCPP_INTERFACE.println(
"");
static float getCurrentMain()
static void powerOff(bool inMain = true, bool inProg = true)
static void powerOn(bool inMain = true, bool inProg = true)