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=INTERFACE.available();
45 if (DCCppConfig::Protocol == EthernetProtocol::HTTP) {
46 INTERFACE.println(
"HTTP/1.1 200 OK");
47 INTERFACE.println(
"Content-Type: text/html");
48 INTERFACE.println(
"Access-Control-Allow-Origin: *");
49 INTERFACE.println(
"Connection: close");
50 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 (INTERFACE.available()>0) {
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 INTERFACE.print(
"<a");
439 INTERFACE.print(
">");
440 #if !defined(USE_ETHERNET) 441 INTERFACE.println(
"");
462 if(digitalRead(DCCppConfig::SignalEnablePinProg)==LOW)
463 INTERFACE.print(
"<p0>");
465 INTERFACE.print(
"<p1>");
466 #if !defined(USE_ETHERNET) 467 INTERFACE.println(
"");
470 for(
int i=1;i<=MAX_MAIN_REGISTERS;i++){
471 if(DCCpp::mainRegs.speedTable[i]==0)
473 INTERFACE.print(
"<T");
474 INTERFACE.print(i); INTERFACE.print(
" ");
475 if(DCCpp::mainRegs.speedTable[i]>0){
476 INTERFACE.print(DCCpp::mainRegs.speedTable[i]);
477 INTERFACE.print(
" 1>");
479 INTERFACE.print(- DCCpp::mainRegs.speedTable[i]);
480 INTERFACE.print(
" 0>");
482 #if !defined(USE_ETHERNET) 483 INTERFACE.println(
"");
486 INTERFACE.print(
"<iDCCpp LIBRARY BASE STATION FOR ARDUINO ");
490 INTERFACE.print(
": V-");
491 INTERFACE.print(VERSION);
492 INTERFACE.print(
" / ");
493 INTERFACE.print(__DATE__);
494 INTERFACE.print(
" ");
495 INTERFACE.print(__TIME__);
496 INTERFACE.print(
">");
497 #if !defined(USE_ETHERNET) 498 INTERFACE.println(
"");
501 INTERFACE.print(
"<N ");
502 #if defined(USE_ETHERNET) 503 INTERFACE.print(
"ETHERNET :");
504 INTERFACE.print(Ethernet.localIP());
505 INTERFACE.print(
">");
506 #if !defined(USE_ETHERNET) 507 INTERFACE.println(
"");
510 INTERFACE.println(
"SERIAL>");
513 #ifdef DCCPP_PRINT_DCCPP 544 INTERFACE.print(
"<e ");
545 INTERFACE.print(EEStore::data.nTurnouts);
546 INTERFACE.print(
" ");
547 INTERFACE.print(EEStore::data.nSensors);
548 INTERFACE.print(
" ");
549 INTERFACE.print(EEStore::data.nOutputs);
550 INTERFACE.print(
">");
551 #if !defined(USE_ETHERNET) 552 INTERFACE.println(
"");
573 INTERFACE.print(
"<O>");
574 #if !defined(USE_ETHERNET) 575 INTERFACE.println(
"");
596 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 INTERFACE.print(
"<f");
721 INTERFACE.print((
int) &v - (__brkval == 0 ? (
int) &__heap_start : (
int) __brkval));
722 INTERFACE.print(
">");
723 #if !defined(USE_ETHERNET) 724 INTERFACE.println(
"");
744 INTERFACE.println(
"");
745 for(Register *p = DCCpp::mainRegs.reg; p <= DCCpp::mainRegs.maxLoadedReg;p++){
746 INTERFACE.print(
"M"); INTERFACE.print((
int)(p - DCCpp::mainRegs.reg)); INTERFACE.print(
":t");
747 INTERFACE.print((
int)p); INTERFACE.print(
"t");
748 INTERFACE.print((
int)(p->activePacket)); INTERFACE.print(
"t");
749 INTERFACE.print(p->activePacket->nBits); INTERFACE.print(
"t");
750 for(
int i=0;i<10;i++){
751 INTERFACE.print(p->activePacket->buf[i],HEX); INTERFACE.print(
"t");
753 INTERFACE.println(
"");
755 for(Register *p = DCCpp::progRegs.reg; p <= DCCpp::progRegs.maxLoadedReg;p++){
756 INTERFACE.print(
"P"); INTERFACE.print((
int)(p - DCCpp::progRegs.reg)); INTERFACE.print(
":t");
757 INTERFACE.print((
int)p); INTERFACE.print(
"t");
758 INTERFACE.print((
int)p->activePacket); INTERFACE.print(
"t");
759 INTERFACE.print(p->activePacket->nBits); INTERFACE.print(
"t");
760 for(
int i=0;i<10;i++){
761 INTERFACE.print(p->activePacket->buf[i],HEX); INTERFACE.print(
"t");
763 INTERFACE.println(
"");
765 INTERFACE.println(
"");
static float getCurrentMain()