From 9044cce2a33283831a281ec48e33221df5096289 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 1 Aug 2020 16:32:16 +0100 Subject: [PATCH] Change Stream refernces to pointers I misunderstood that references can never be changed. --- CVReader.ino | 4 +-- DCCEXParser.cpp | 24 +++++++++------- DCCEXParser.h | 20 ++++++------- Outputs.cpp | 4 +-- Outputs.h | 4 +-- Sensors.cpp | 6 ++-- Sensors.h | 6 ++-- StringFormatter.cpp | 52 ++++++++++++++++++--------------- StringFormatter.h | 10 +++---- Turnouts.cpp | 4 +-- Turnouts.h | 4 +-- WifiInterface.cpp | 70 +++++++++++++++++++++++++++------------------ WifiInterface.h | 12 ++++---- 13 files changed, 123 insertions(+), 97 deletions(-) diff --git a/CVReader.ino b/CVReader.ino index 267b833..bbb8189 100644 --- a/CVReader.ino +++ b/CVReader.ino @@ -35,7 +35,7 @@ // // The filter must be enabled by calling the DCC EXParser::setFilter method, see use in setup(). -void myFilter(Print & stream, byte & opcode, byte & paramCount, int p[]) { +void myFilter(Print * stream, byte & opcode, byte & paramCount, int p[]) { (void)stream; // avoid compiler warning if we don't access this parameter switch (opcode) { case '!': // Create a bespoke new command to clear all loco reminders or specific locos e.g @@ -116,7 +116,7 @@ void loop() { // Responsibility 3: Optionally handle any incoming WiFi traffic #ifdef WIFI - WifiInterface::loop(Serial1); + WifiInterface::loop(); #endif // Your additional code diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 2ec10ad..0ff5d0e 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -20,6 +20,7 @@ #include "DCCEXParser.h" #include "DCC.h" #include "DCCWaveform.h" +#include "WifiInterface.h" #include "Turnouts.h" #include "Outputs.h" #include "Sensors.h" @@ -39,7 +40,7 @@ const int HASH_KEYWORD_JOIN=-30750; int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; - Print & DCCEXParser::stashStream=DIAGSERIAL; // keep compiler happy but ovevride in constructor + Print * DCCEXParser::stashStream=NULL; // This is a JMRI command parser, one instance per incoming stream // It doesnt know how the string got here, nor how it gets back. @@ -67,7 +68,7 @@ void DCCEXParser::loop(Stream & stream) { } else if (ch == '>') { buffer[bufferLength]='\0'; - parse( stream, buffer, false); // Parse this allowing async responses + parse( & stream, buffer, false); // Parse this allowing async responses inCommandPayload = false; break; } else if(inCommandPayload) { @@ -131,7 +132,7 @@ void DCCEXParser::setFilter(FILTER_CALLBACK filter) { } // See documentation on DCC class for info on this section -void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) { +void DCCEXParser::parse(Print * stream, byte *com, bool blocking) { DIAG(F("\nPARSING:%s\n"),com); (void) EEPROM; // tell compiler not to warn thi is unused int p[MAX_PARAMS]; @@ -280,8 +281,11 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) { case 'F': // New command to call the new Loco Function API DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF")); DCC::setFn(p[0],p[1],p[2]==1); - return; - + return; + + case '+' : // Complex Wifi interface command (not usual parse) + WifiInterface::ATCommand(com); + break; default: //anything else will diagnose and drop out to DIAG(F("\nOpcode=%c params=%d\n"),opcode,params); @@ -294,7 +298,7 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) { StringFormatter::send(stream, F("")); } -bool DCCEXParser::parseZ( Print & stream,int params, int p[]){ +bool DCCEXParser::parseZ( Print * stream,int params, int p[]){ switch (params) { @@ -324,7 +328,7 @@ bool DCCEXParser::parseZ( Print & stream,int params, int p[]){ } //=================================== -bool DCCEXParser::parsef(Print & stream, int params, int p[]) { +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) { @@ -356,7 +360,7 @@ void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) { } //=================================== -bool DCCEXParser::parseT(Print & stream, int params, int p[]) { +bool DCCEXParser::parseT(Print * stream, int params, int p[]) { switch(params){ case 0: // return (Turnout::showAll(stream)); break; @@ -381,7 +385,7 @@ bool DCCEXParser::parseT(Print & stream, int params, int p[]) { } } -bool DCCEXParser::parseS( Print & stream,int params, int p[]) { +bool DCCEXParser::parseS( Print * stream,int params, int p[]) { switch(params){ @@ -405,7 +409,7 @@ bool DCCEXParser::parseS( Print & stream,int params, int p[]) { // CALLBACKS must be static -bool DCCEXParser::stashCallback(Print & stream,int p[MAX_PARAMS]) { +bool DCCEXParser::stashCallback(Print * stream,int p[MAX_PARAMS]) { if (stashBusy || asyncBanned) return false; stashBusy=true; stashStream=stream; diff --git a/DCCEXParser.h b/DCCEXParser.h index 423df76..4968f18 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -20,13 +20,13 @@ #define DCCEXParser_h #include -typedef void (*FILTER_CALLBACK)(Print & stream, byte & opcode, byte & paramCount, int p[]); +typedef void (*FILTER_CALLBACK)(Print * stream, byte & opcode, byte & paramCount, int p[]); struct DCCEXParser { DCCEXParser(); - void loop(Stream & pstream); - void parse(Print & stream, const byte * command, bool blocking); + void loop(Stream & stream); + void parse(Print * stream, byte * command, bool blocking); void flush(); static void setFilter(FILTER_CALLBACK filter); static const int MAX_PARAMS=10; // Must not exceed this @@ -40,23 +40,23 @@ struct DCCEXParser byte buffer[MAX_BUFFER+2]; int splitValues( int result[MAX_PARAMS], const byte * command); - bool parseT(Print & stream, int params, int p[]); - bool parseZ(Print & stream, int params, int p[]); - bool parseS(Print & stream, int params, int p[]); - bool parsef(Print & stream, int params, int p[]); + bool parseT(Print * stream, int params, int p[]); + bool parseZ(Print * stream, int params, int p[]); + bool parseS(Print * stream, int params, int p[]); + bool parsef(Print * stream, int params, int p[]); static bool stashBusy; - static Print & stashStream; + static Print * stashStream; static int stashP[MAX_PARAMS]; - bool stashCallback(Print & stream, int p[MAX_PARAMS]); + bool stashCallback(Print * stream, int p[MAX_PARAMS]); static void callback_W(int result); static void callback_B(int result); static void callback_R(int result); static FILTER_CALLBACK filterCallback; static void funcmap(int cab, byte value, byte fstart, byte fstop); - + }; #define BOARD_NAME F("not yet configured") diff --git a/Outputs.cpp b/Outputs.cpp index 3d14fa7..d608cd9 100644 --- a/Outputs.cpp +++ b/Outputs.cpp @@ -121,7 +121,7 @@ bool Output::remove(int n){ /////////////////////////////////////////////////////////////////////////////// -bool Output::showAll(Print & stream){ +bool Output::showAll(Print * stream){ bool gotone=false; for(Output * tt=firstOutput;tt!=NULL;tt=tt->nextOutput){ gotone=true; @@ -130,7 +130,7 @@ bool Output::showAll(Print & stream){ return gotone; } -void Output::show(Print & stream){ +void Output::show(Print * stream){ for(Output * tt=firstOutput;tt!=NULL;tt=tt->nextOutput){ StringFormatter::send(stream,F(""), tt->data.id, tt->data.oStatus); } diff --git a/Outputs.h b/Outputs.h index f46c34e..736123f 100644 --- a/Outputs.h +++ b/Outputs.h @@ -36,8 +36,8 @@ class Output{ static void load(); static void store(); static Output *create(int, int, int, int=0); - static void show(Print & stream); - static bool showAll(Print & stream); + static void show(Print * stream); + static bool showAll(Print * stream); private: static Output *firstOutput; diff --git a/Sensors.cpp b/Sensors.cpp index fd206c1..320813e 100644 --- a/Sensors.cpp +++ b/Sensors.cpp @@ -73,7 +73,7 @@ decide to ignore the return and only react to triggers. /////////////////////////////////////////////////////////////////////////////// -void Sensor::check(Print & stream){ +void Sensor::check(Print * stream){ Sensor *tt; for(tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ @@ -148,7 +148,7 @@ bool Sensor::remove(int n){ /////////////////////////////////////////////////////////////////////////////// -void Sensor::show(Print & stream){ +void Sensor::show(Print * stream){ for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ StringFormatter::send(stream, F(""), tt->data.snum, tt->data.pin, tt->data.pullUp); } @@ -156,7 +156,7 @@ void Sensor::show(Print & stream){ /////////////////////////////////////////////////////////////////////////////// -void Sensor::status(Print & stream){ +void Sensor::status(Print * stream){ for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ StringFormatter::send(stream,F("<%c %d>"), tt->active?'Q':'q', tt->data.snum); } diff --git a/Sensors.h b/Sensors.h index 8bb44fc..3f37df3 100644 --- a/Sensors.h +++ b/Sensors.h @@ -40,9 +40,9 @@ struct Sensor{ static Sensor *create(int, int, int); static Sensor* get(int); static bool remove(int); - static void show(Print & stream); - static void status(Print & stream); - static void check(Print & stream); + static void show(Print * stream); + static void status(Print * stream); + static void check(Print * stream); }; // Sensor #endif diff --git a/StringFormatter.cpp b/StringFormatter.cpp index f7e7f25..3c4cbf1 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -22,16 +22,22 @@ void StringFormatter::print( const __FlashStringHelper* input...) { va_list args; va_start(args, input); - send2(DIAGSERIAL,input,args); + send(& DIAGSERIAL,input,args); } void StringFormatter::send(Print & stream, const __FlashStringHelper* input...) { va_list args; va_start(args, input); - send2(stream,input,args); + send(& stream,input,args); +} +void StringFormatter::send(Print * stream, const __FlashStringHelper* input...) { + va_list args; + va_start(args, input); + send(stream,input,args); } -void StringFormatter::send2(Print & stream,const __FlashStringHelper* format, va_list args) { + +void StringFormatter::send(Print * stream,const __FlashStringHelper* format, va_list args) { // thanks to Jan TuroĊˆ https://arduino.stackexchange.com/questions/56517/formatting-strings-in-arduino-for-output @@ -39,35 +45,35 @@ void StringFormatter::send2(Print & stream,const __FlashStringHelper* format, va for(int i=0; ; ++i) { char c=pgm_read_byte_near(flash+i); if (c=='\0') return; - if(c!='%') { stream.print(c); continue; } + if(c!='%') { stream->print(c); continue; } i++; c=pgm_read_byte_near(flash+i); switch(c) { - case '%': stream.print('%'); break; - case 'c': stream.print((char) va_arg(args, int)); break; - case 's': stream.print(va_arg(args, char*)); break; + case '%': stream->print('%'); break; + case 'c': stream->print((char) va_arg(args, int)); break; + case 's': stream->print(va_arg(args, char*)); break; case 'e': printEscapes(stream,va_arg(args, char*)); break; case 'E': printEscapes(stream,(const __FlashStringHelper*)va_arg(args, char*)); break; - case 'S': stream.print((const __FlashStringHelper*)va_arg(args, char*)); break; - case 'd': stream.print(va_arg(args, int), DEC); break; - case 'l': stream.print(va_arg(args, long), DEC); break; - case 'b': stream.print(va_arg(args, int), BIN); break; - case 'o': stream.print(va_arg(args, int), OCT); break; - case 'x': stream.print(va_arg(args, int), HEX); break; - case 'f': stream.print(va_arg(args, double), 2); break; + case 'S': stream->print((const __FlashStringHelper*)va_arg(args, char*)); break; + case 'd': stream->print(va_arg(args, int), DEC); break; + case 'l': stream->print(va_arg(args, long), DEC); break; + case 'b': stream->print(va_arg(args, int), BIN); break; + case 'o': stream->print(va_arg(args, int), OCT); break; + case 'x': stream->print(va_arg(args, int), HEX); break; + case 'f': stream->print(va_arg(args, double), 2); break; } } va_end(args); } -void StringFormatter::printEscapes(Print & stream, char * input) { +void StringFormatter::printEscapes(Print * stream, char * input) { for(int i=0; ; ++i) { char c=input[i]; printEscape(stream,c); if (c=='\0') return; } } -void StringFormatter::printEscapes(Print & stream, const __FlashStringHelper* input) { +void StringFormatter::printEscapes(Print * stream, const __FlashStringHelper* input) { char* flash=(char*)input; for(int i=0; ; ++i) { char c=pgm_read_byte_near(flash+i); @@ -75,14 +81,14 @@ void StringFormatter::printEscapes(Print & stream, const __FlashStringHelper* in if (c=='\0') return; } } -void StringFormatter::printEscape(Print & stream, char c) { +void StringFormatter::printEscape(Print * stream, char c) { switch(c) { - case '\n': stream.print(F("\\n")); break; - case '\r': stream.print(F("\\r")); break; - case '\0': stream.print(F("\\0")); return; - case '\t': stream.print(F("\\t")); break; - case '\\': stream.print(F("\\")); break; - default: stream.print(c); + case '\n': stream->print(F("\\n")); break; + case '\r': stream->print(F("\\r")); break; + case '\0': stream->print(F("\\0")); return; + case '\t': stream->print(F("\\t")); break; + case '\\': stream->print(F("\\")); break; + default: stream->print(c); } } diff --git a/StringFormatter.h b/StringFormatter.h index 7b25329..a93dcc2 100644 --- a/StringFormatter.h +++ b/StringFormatter.h @@ -33,11 +33,11 @@ class StringFormatter public: static void print( const __FlashStringHelper* input...); static void send(Print & serial, const __FlashStringHelper* input...); - static void printEscapes(Print & stream, char * input); - static void printEscapes(Print & stream, const __FlashStringHelper* input); - static void printEscape(Print & stream, char c); - private: - static void send2(Print & serial, const __FlashStringHelper* input,va_list args); + static void send(Print * serial, const __FlashStringHelper* input...); + static void printEscapes(Print * stream, char * input); + static void printEscapes(Print * stream, const __FlashStringHelper* input); + static void printEscape(Print * stream, char c); + static void send(Print * serial, const __FlashStringHelper* input,va_list args); }; #endif diff --git a/Turnouts.cpp b/Turnouts.cpp index f30abdd..a2d9f14 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -73,7 +73,7 @@ bool Turnout::remove(int n){ /////////////////////////////////////////////////////////////////////////////// -void Turnout::show(Print & stream, int n){ +void Turnout::show(Print * stream, int n){ for(Turnout *tt=firstTurnout;tt!=NULL;tt=tt->nextTurnout){ if (tt->data.id==n) { StringFormatter::send(stream,F(""), tt->data.id, tt->data.tStatus & STATUS_ACTIVE); @@ -82,7 +82,7 @@ void Turnout::show(Print & stream, int n){ } } -bool Turnout::showAll(Print & stream){ +bool Turnout::showAll(Print * stream){ bool gotOne=false; for(Turnout * tt=firstTurnout;tt!=NULL;tt=tt->nextTurnout){ StringFormatter::send(stream,F(""), tt->data.id, tt->data.address, tt->data.subAddress, (tt->data.tStatus & STATUS_ACTIVE)!=0); diff --git a/Turnouts.h b/Turnouts.h index e7ae0e1..3287d76 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -47,8 +47,8 @@ class Turnout { static Turnout *create(int id , int address , int subAddress); static Turnout *create(int id , byte pin , int activeAngle, int inactiveAngle); static Turnout *create(int id); - static void show(Print & stream, int n); - static bool showAll(Print & stream); + static void show(Print * stream, int n); + static bool showAll(Print * stream); void activate(bool state); }; // Turnout diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 460630a..19446dd 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -37,75 +37,89 @@ int WifiInterface::datalength=0; int WifiInterface::connectionId; byte WifiInterface::buffer[MAX_WIFI_BUFFER]; MemStream WifiInterface::streamer(buffer,sizeof(buffer)); +Stream * WifiInterface::wifiStream=NULL; -void WifiInterface::setup(Stream & wifiStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password, +void WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password, const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port) { + wifiStream=&setupStream; + DIAG(F("\n++++++ Wifi Setup In Progress ++++++++\n")); - connected=setup2(wifiStream, SSid, password,hostname, servername,port); + connected=setup2( SSid, password,hostname, servername,port); // TODO calloc the buffer and streamer and parser etc DIAG(F("\n++++++ Wifi Setup %S ++++++++\n"), connected?F("OK"):F("FAILED")); } -bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password, +bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringHelper* password, const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port) { - + delay(1000); StringFormatter::send(wifiStream,F("AT+RST\r\n")); // reset module - checkForOK(wifiStream,5000,READY_SEARCH,false); // generally not interesting to DCC + checkForOK(5000,READY_SEARCH,false); // generally not interesting to DCC StringFormatter::send(wifiStream,F("AT+GMR\r\n")); // request AT version - checkForOK(wifiStream,2000,OK_SEARCH,true); // Makes this visible on the console + checkForOK(2000,OK_SEARCH,true); // Makes this visible on the console StringFormatter::send(wifiStream,F("AT+CWMODE=3\r\n")); // configure as server or access point - checkForOK(wifiStream,1000,OK_SEARCH,true); // Not always OK, sometimes "no change" + checkForOK(1000,OK_SEARCH,true); // Not always OK, sometimes "no change" // Older ES versions have AT+CWJAP, newer ones have AT+CWJAP_CUR and AT+CWHOSTNAME StringFormatter::send(wifiStream,F("AT+CWJAP?\r\n")); - if (checkForOK(wifiStream,2000,OK_SEARCH,true)) { + if (checkForOK(2000,OK_SEARCH,true)) { // early version supports CWJAP - StringFormatter::send(wifiStream,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),SSid,password); - checkForOK(wifiStream,20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok + if (SSid!=NULL && password!=NULL) { + // Only connect to router if we are given a SSId and password, + // otherwise assume that the ES8266 has already got these from a previous call + // USER can pass these in with a command which will re-call this setup + StringFormatter::send(wifiStream,F("AT+CWJAP=\"%S\",\"%S\"\r\n"),SSid,password); + checkForOK(20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok + } } else { // later version supports CWJAP_CUR StringFormatter::send(wifiStream, F("AT+CWHOSTNAME=\"%S\"\r\n"), hostname); // Set Host name for Wifi Client - checkForOK(wifiStream,2000, OK_SEARCH, true); // dont care if not supported + checkForOK(2000, OK_SEARCH, true); // dont care if not supported - StringFormatter::send(wifiStream,F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"),SSid,password); - checkForOK(wifiStream,20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok + if (SSid!=NULL && password!=NULL) { + StringFormatter::send(wifiStream,F("AT+CWJAP_CUR=\"%S\",\"%S\"\r\n"),SSid,password); + checkForOK(20000,OK_SEARCH,true); // can ignore failure as AP mode may still be ok + } StringFormatter::send(wifiStream,F("AT+CIPRECVMODE=0\r\n"),port); // make sure transfer mode is correct - checkForOK(wifiStream,2000,OK_SEARCH,true); + checkForOK(2000,OK_SEARCH,true); // StringFormatter::send(wifiStream, F("AT+MDNS=1,\"%S.local\",\"%S.local\",%d\r\n"), hostname, servername, port); // Setup mDNS for Server - // if (!checkForOK(wifiStream,5000, OK_SEARCH, true)) return false; + // if (!checkForOK(5000, OK_SEARCH, true)) return false; (void)servername; // avoid compiler warning from commented out AT_MDNS above } StringFormatter::send(wifiStream,F("AT+CIFSR\r\n")); // get ip address //192.168.4.1 - if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; + if (!checkForOK(10000,OK_SEARCH,true)) return false; StringFormatter::send(wifiStream,F("AT+CIPMUX=1\r\n")); // configure for multiple connections - if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; + if (!checkForOK(10000,OK_SEARCH,true)) return false; StringFormatter::send(wifiStream,F("AT+CIPSERVER=1,%d\r\n"),port); // turn on server on port - if (!checkForOK(wifiStream,10000,OK_SEARCH,true)) return false; + if (!checkForOK(10000,OK_SEARCH,true)) return false; return true; } +void WifiInterface::ATCommand(const byte * command) { + StringFormatter:: send(wifiStream,F("AT+%s\r\n"), command+1); + checkForOK(10000,OK_SEARCH,true); +} -bool WifiInterface::checkForOK(Stream & wifiStream, const unsigned int timeout, const char * waitfor, bool echo) { +bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor, bool echo) { unsigned long startTime = millis(); char const *locator=waitfor; DIAG(F("\nWifi Check: [%E]"),waitfor); while( millis()-startTime < timeout) { - while(wifiStream.available()) { - int ch=wifiStream.read(); - if (echo) StringFormatter::printEscape(DIAGSERIAL,ch); /// THIS IS A DIAG IN DISGUISE + while(wifiStream->available()) { + int ch=wifiStream->read(); + if (echo) StringFormatter::printEscape(&DIAGSERIAL,ch); /// THIS IS A DIAG IN DISGUISE if (ch!=pgm_read_byte_near(locator)) locator=waitfor; if (ch==pgm_read_byte_near(locator)) { locator++; @@ -141,17 +155,17 @@ bool WifiInterface::isHTML() { } } -void WifiInterface::loop(Stream & wifiStream) { +void WifiInterface::loop() { if (!connected) return; WiThrottle::loop(); // check heartbeats // read anything into a buffer, collecting info on the way - while (loopstate!=99 && wifiStream.available()) { - int ch=wifiStream.read(); + while (loopstate!=99 && wifiStream->available()) { + int ch=wifiStream->read(); // echo the char to the diagnostic stream in escaped format - StringFormatter::printEscape(DIAGSERIAL,ch); // DIAG in disguise + StringFormatter::printEscape(&DIAGSERIAL,ch); // DIAG in disguise switch (loopstate) { case 0: // looking for +IPD @@ -193,7 +207,7 @@ void WifiInterface::loop(Stream & wifiStream) { } if (ch=='>'){ DIAG(F("\n> [%e]\n"),buffer); - wifiStream.print((char *) buffer); + wifiStream->print((char *) buffer); loopTimeoutStart=millis(); loopstate=closeAfter?11:0; } @@ -228,7 +242,7 @@ void WifiInterface::loop(Stream & wifiStream) { HTTPParser::parse(streamer,buffer); closeAfter=true; } - else if (buffer[0]=='<') parser.parse(streamer,buffer, true); // tell JMRI parser that ACKS are blocking because we can't handle the async + else if (buffer[0]=='<') parser.parse(&streamer,buffer, true); // tell JMRI parser that ACKS are blocking because we can't handle the async else WiThrottle::getThrottle(connectionId)->parse(streamer, buffer); diff --git a/WifiInterface.h b/WifiInterface.h index 7a54035..2101826 100644 --- a/WifiInterface.h +++ b/WifiInterface.h @@ -27,16 +27,18 @@ class WifiInterface { public: - static void setup(Stream & wifiStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password, + static void setup(Stream & setupStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password, const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port); - static void loop(Stream & wifiStream); + static void loop(); + static void ATCommand(const byte * command); + private: - + static Stream * wifiStream; static DCCEXParser parser; - static bool setup2(Stream & wifiStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password, + static bool setup2( const __FlashStringHelper* SSSid, const __FlashStringHelper* password, const __FlashStringHelper* hostname, const __FlashStringHelper* servername, int port); - static bool checkForOK(Stream & wifiStream, const unsigned int timeout, const char* waitfor, bool echo); + static bool checkForOK(const unsigned int timeout, const char* waitfor, bool echo); static bool isHTML(); static bool connected; static bool closeAfter;