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];
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);
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);
236 return Output::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);
413 DCCpp::mainRegs.readCV(com + 1);
471 DCCPP_INTERFACE.print(
"<a");
473 DCCPP_INTERFACE.print(
">");
474 #if !defined(USE_ETHERNET) 475 DCCPP_INTERFACE.println(
"");
496 if (DCCppConfig::SignalEnablePinMain == UNDEFINED_PIN || digitalRead(DCCppConfig::SignalEnablePinMain) == HIGH)
497 DCCPP_INTERFACE.print(
"<p0>");
498 if (DCCppConfig::SignalEnablePinProg == UNDEFINED_PIN || digitalRead(DCCppConfig::SignalEnablePinProg) == HIGH)
499 DCCPP_INTERFACE.print(
"<p1>");
500 #if !defined(USE_ETHERNET) 501 DCCPP_INTERFACE.println(
"");
504 for(
int i=1;i<=MAX_MAIN_REGISTERS;i++){
505 if(DCCpp::mainRegs.speedTable[i]==0)
507 DCCPP_INTERFACE.print(
"<T");
508 DCCPP_INTERFACE.print(i); DCCPP_INTERFACE.print(
" ");
509 if(DCCpp::mainRegs.speedTable[i]>0){
510 DCCPP_INTERFACE.print(DCCpp::mainRegs.speedTable[i]);
511 DCCPP_INTERFACE.print(
" 1>");
513 DCCPP_INTERFACE.print(- DCCpp::mainRegs.speedTable[i]);
514 DCCPP_INTERFACE.print(
" 0>");
516 #if !defined(USE_ETHERNET) 517 DCCPP_INTERFACE.println(
"");
520 DCCPP_INTERFACE.print(
"<iDCCpp LIBRARY BASE STATION FOR ARDUINO ");
524 DCCPP_INTERFACE.print(
": V-");
525 DCCPP_INTERFACE.print(VERSION);
526 DCCPP_INTERFACE.print(
" / ");
527 DCCPP_INTERFACE.print(__DATE__);
528 DCCPP_INTERFACE.print(
" ");
529 DCCPP_INTERFACE.print(__TIME__);
530 DCCPP_INTERFACE.print(
">");
531 #if !defined(USE_ETHERNET) 532 DCCPP_INTERFACE.println(
"");
535 DCCPP_INTERFACE.print(
"<N ");
536 #if defined(USE_ETHERNET) 537 DCCPP_INTERFACE.print(
"ETHERNET :");
538 DCCPP_INTERFACE.print(Ethernet.localIP());
539 DCCPP_INTERFACE.print(
">");
540 #if !defined(USE_ETHERNET) 541 DCCPP_INTERFACE.println(
"");
544 DCCPP_INTERFACE.println(
"SERIAL>");
547 #ifdef DCCPP_PRINT_DCCPP 578 DCCPP_INTERFACE.print(
"<e ");
580 DCCPP_INTERFACE.print(
" ");
582 DCCPP_INTERFACE.print(
" ");
584 DCCPP_INTERFACE.print(
">");
585 #if !defined(USE_ETHERNET) 586 DCCPP_INTERFACE.println(
"");
607 DCCPP_INTERFACE.print(
"<O>");
608 #if !defined(USE_ETHERNET) 609 DCCPP_INTERFACE.println(
"");
630 DCCPP_INTERFACE.println(
"");
653 Serial.println(
"\nEntering Diagnostic Mode...");
684 DCCpp::mainRegs.writeTextPacket(com+1);
711 DCCpp::progRegs.writeTextPacket(com+1);
735 DCCPP_INTERFACE.print(
"<f");
736 #ifdef ARDUINO_ARCH_AVR 737 DCCPP_INTERFACE.print((
int) &v - (__brkval == 0 ? (
int) &__heap_start : (
int) __brkval));
739 DCCPP_INTERFACE.print(
">");
740 #if !defined(USE_ETHERNET) 741 DCCPP_INTERFACE.println(
"");
762 DCCPP_INTERFACE.println(
"");
763 for(
Register *p = DCCpp::mainRegs.reg; p <= DCCpp::mainRegs.maxLoadedReg;p++){
764 DCCPP_INTERFACE.print(
"M"); DCCPP_INTERFACE.print((
int)(p - DCCpp::mainRegs.reg)); DCCPP_INTERFACE.print(
":\t");
765 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"\t");
766 DCCPP_INTERFACE.print((
int)(p->activePacket)); DCCPP_INTERFACE.print(
"\t");
767 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"\t");
768 for(
int i=0;i<10;i++){
769 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"\t");
771 DCCPP_INTERFACE.println(
"");
773 for(
Register *p = DCCpp::progRegs.reg; p <= DCCpp::progRegs.maxLoadedReg;p++){
774 DCCPP_INTERFACE.print(
"P"); DCCPP_INTERFACE.print((
int)(p - DCCpp::progRegs.reg)); DCCPP_INTERFACE.print(
":\t");
775 DCCPP_INTERFACE.print((
int)p); DCCPP_INTERFACE.print(
"\t");
776 DCCPP_INTERFACE.print((
int)p->activePacket); DCCPP_INTERFACE.print(
"\t");
777 DCCPP_INTERFACE.print(p->activePacket->nBits); DCCPP_INTERFACE.print(
"\t");
778 for(
int i=0;i<10;i++){
779 DCCPP_INTERFACE.print(p->activePacket->buf[i],HEX); DCCPP_INTERFACE.print(
"\t");
781 DCCPP_INTERFACE.println(
"");
783 DCCPP_INTERFACE.println(
"");
static void setDebugDccMode()
static void powerOff(bool inMain=true, bool inProg=true)
static void powerOn(bool inMain=true, bool inProg=true)
static bool parse(char *c)
static bool parse(char *c)
static bool parse(char *com)
static float getCurrentMain()