14 #include "TextCommand.h" 15 #ifdef USE_TEXTCOMMAND 21 extern unsigned int __heap_start;
22 extern void *__brkval;
27 char TextCommand::commandString[MAX_COMMAND_LENGTH+1];
37 void TextCommand::process(){
40 #if defined(USE_ETHERNET) 42 EthernetClient client= DCCPP_INTERFACE.available();
46 if (DCCppConfig::Protocol == EthernetProtocol::HTTP) {
47 DCCPP_INTERFACE.println(
"HTTP/1.1 200 OK");
48 DCCPP_INTERFACE.println(
"Content-Type: text/html");
49 DCCPP_INTERFACE.println(
"Access-Control-Allow-Origin: *");
50 DCCPP_INTERFACE.println(
"Connection: close");
51 DCCPP_INTERFACE.println(
"");
54 while (client.connected() && client.available()) {
60 if (parse(commandString) ==
false)
62 #if defined(DCCPP_DEBUG_MODE) 63 Serial.println(
"invalid command !");
67 else if (strlen(commandString) < MAX_COMMAND_LENGTH)
68 sprintf(commandString,
"%s%c", commandString, c);
71 if (DCCppConfig::Protocol == EthernetProtocol::HTTP)
77 while (DCCPP_INTERFACE.available()>0) {
78 c = DCCPP_INTERFACE.read();
83 else if (strlen(commandString) < MAX_COMMAND_LENGTH)
84 sprintf(commandString,
"%s%c", commandString, c);
92 bool TextCommand::parse(
char *com){
95 #ifdef DCCPP_DEBUG_MODE 97 Serial.println(F(
" command"));
99 std::cout << com <<
" command received" << std::endl;
126 DCCpp::mainRegs.setThrottle(com+1);
177 DCCpp::mainRegs.setFunction(com+1);
216 DCCpp::mainRegs.setAccessory(com+1);
226 return Turnout::parse(com+1);
236 return Output::parse(com+1);
246 return Sensor::parse(com+1);
248 #ifdef DCCPP_PRINT_DCCPP 289 DCCpp::mainRegs.writeCVByteMain(com+1);
314 DCCpp::mainRegs.writeCVBitMain(com+1);
339 DCCpp::progRegs.writeCVByte(com+1);
365 DCCpp::progRegs.writeCVBit(com+1);
389 DCCpp::progRegs.readCV(com+1);
447 DCCPP_INTERFACE.print(
"<a");
449 DCCPP_INTERFACE.print(
">");
450 #if !defined(USE_ETHERNET) 451 DCCPP_INTERFACE.println(
"");
472 if (DCCppConfig::SignalEnablePinMain == UNDEFINED_PIN || digitalRead(DCCppConfig::SignalEnablePinMain) == HIGH)
473 DCCPP_INTERFACE.print(
"<p0>");
474 if (DCCppConfig::SignalEnablePinProg == UNDEFINED_PIN || digitalRead(DCCppConfig::SignalEnablePinProg) == HIGH)
475 DCCPP_INTERFACE.print(
"<p1>");
476 #if !defined(USE_ETHERNET) 477 DCCPP_INTERFACE.println(
"");
480 for(
int i=1;i<=MAX_MAIN_REGISTERS;i++){
481 if(DCCpp::mainRegs.speedTable[i]==0)
483 DCCPP_INTERFACE.print(
"<T");
484 DCCPP_INTERFACE.print(i); DCCPP_INTERFACE.print(
" ");
485 if(DCCpp::mainRegs.speedTable[i]>0){
486 DCCPP_INTERFACE.print(DCCpp::mainRegs.speedTable[i]);
487 DCCPP_INTERFACE.print(
" 1>");
489 DCCPP_INTERFACE.print(- DCCpp::mainRegs.speedTable[i]);
490 DCCPP_INTERFACE.print(
" 0>");
492 #if !defined(USE_ETHERNET) 493 DCCPP_INTERFACE.println(
"");
496 DCCPP_INTERFACE.print(
"<iDCCpp LIBRARY BASE STATION FOR ARDUINO ");
500 DCCPP_INTERFACE.print(
": V-");
501 DCCPP_INTERFACE.print(VERSION);
502 DCCPP_INTERFACE.print(
" / ");
503 DCCPP_INTERFACE.print(__DATE__);
504 DCCPP_INTERFACE.print(
" ");
505 DCCPP_INTERFACE.print(__TIME__);
506 DCCPP_INTERFACE.print(
">");
507 #if !defined(USE_ETHERNET) 508 DCCPP_INTERFACE.println(
"");
511 DCCPP_INTERFACE.print(
"<N ");
512 #if defined(USE_ETHERNET) 513 DCCPP_INTERFACE.print(
"ETHERNET :");
514 DCCPP_INTERFACE.print(Ethernet.localIP());
515 DCCPP_INTERFACE.print(
">");
516 #if !defined(USE_ETHERNET) 517 DCCPP_INTERFACE.println(
"");
520 DCCPP_INTERFACE.println(
"SERIAL>");
523 #ifdef DCCPP_PRINT_DCCPP 554 DCCPP_INTERFACE.print(
"<e ");
555 DCCPP_INTERFACE.print(EEStore::data.nTurnouts);
556 DCCPP_INTERFACE.print(
" ");
557 DCCPP_INTERFACE.print(EEStore::data.nSensors);
558 DCCPP_INTERFACE.print(
" ");
559 DCCPP_INTERFACE.print(EEStore::data.nOutputs);
560 DCCPP_INTERFACE.print(
">");
561 #if !defined(USE_ETHERNET) 562 DCCPP_INTERFACE.println(
"");
583 DCCPP_INTERFACE.print(
"<O>");
584 #if !defined(USE_ETHERNET) 585 DCCPP_INTERFACE.println(
"");
606 DCCPP_INTERFACE.println(
"");
629 Serial.println(
"\nEntering Diagnostic Mode...");
660 DCCpp::mainRegs.writeTextPacket(com+1);
687 DCCpp::progRegs.writeTextPacket(com+1);
711 DCCPP_INTERFACE.print(
"<f");
712 #ifdef ARDUINO_ARCH_AVR 713 DCCPP_INTERFACE.print((
int) &v - (__brkval == 0 ? (
int) &__heap_start : (
int) __brkval));
715 DCCPP_INTERFACE.print(
">");
716 #if !defined(USE_ETHERNET) 717 DCCPP_INTERFACE.println(
"");
737 DCCPP_INTERFACE.println(
"");
738 for(
Register *p = DCCpp::mainRegs.reg; p <= DCCpp::mainRegs.maxLoadedReg;p++){
739 DCCPP_INTERFACE.print(
"M"); DCCPP_INTERFACE.print((
int)(p - DCCpp::mainRegs.reg)); DCCPP_INTERFACE.print(
":\t");
740 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"\t");
741 DCCPP_INTERFACE.print((
int)(p->activePacket)); DCCPP_INTERFACE.print(
"\t");
742 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"\t");
743 for(
int i=0;i<10;i++){
744 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"\t");
746 DCCPP_INTERFACE.println(
"");
748 for(
Register *p = DCCpp::progRegs.reg; p <= DCCpp::progRegs.maxLoadedReg;p++){
749 DCCPP_INTERFACE.print(
"P"); DCCPP_INTERFACE.print((
int)(p - DCCpp::progRegs.reg)); DCCPP_INTERFACE.print(
":\t");
750 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"\t");
751 DCCPP_INTERFACE.print((
int)p->activePacket); DCCPP_INTERFACE.print(
"\t");
752 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"\t");
753 for(
int i=0;i<10;i++){
754 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"\t");
756 DCCPP_INTERFACE.println(
"");
758 DCCPP_INTERFACE.println(
"");
static void setDebugDccMode()
static float getCurrentMain()
static void powerOff(bool inMain=true, bool inProg=true)
static void powerOn(bool inMain=true, bool inProg=true)