From 36e6c3cd48ad24a46d6bd54976d07d938622797c Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 26 Sep 2020 10:54:11 +0100 Subject: [PATCH] Decouple WifiInterface from Parser This removes the need for WifiInterfrace <+> command processing to be included in the link. so parser does not need to see the config settings for wifi. If Wifi doesnt set the At command callback, parser will return for a <+> command --- DCCEXParser.cpp | 19 ++++++++++++------- DCCEXParser.h | 3 +++ WifiInterface.cpp | 2 ++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 7433576..82cd9d9 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -17,13 +17,10 @@ * You should have received a copy of the GNU General Public License * along with CommandStation. If not, see . */ -#include "config.h" -#include "defines.h" #include "StringFormatter.h" #include "DCCEXParser.h" #include "DCC.h" #include "DCCWaveform.h" -#include "WifiInterface.h" #include "Turnouts.h" #include "Outputs.h" #include "Sensors.h" @@ -157,10 +154,15 @@ int DCCEXParser::splitValues(int result[MAX_PARAMS], const byte *cmd) } FILTER_CALLBACK DCCEXParser::filterCallback = 0; +AT_COMMAND_CALLBACK DCCEXParser::atCommandCallback = 0; void DCCEXParser::setFilter(FILTER_CALLBACK filter) { filterCallback = filter; } +void DCCEXParser::setAtCommandCallback(AT_COMMAND_CALLBACK callback) +{ + atCommandCallback = callback; +} // See documentation on DCC class for info on this section void DCCEXParser::parse(Print *stream, byte *com, bool blocking) @@ -392,11 +394,14 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking) 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; -#ifdef WIFI_ON + case '+': // Complex Wifi interface command (not usual parse) - WifiInterface::ATCommand(com); - return; -#endif + if (atCommandCallback) { + atCommandCallback(com); + return; + } + break; + default: //anything else will diagnose and drop out to DIAG(F("\nOpcode=%c params=%d\n"), opcode, params); for (int i = 0; i < params; i++) diff --git a/DCCEXParser.h b/DCCEXParser.h index e154ff9..5721f6c 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -21,6 +21,7 @@ #include typedef void (*FILTER_CALLBACK)(Print * stream, byte & opcode, byte & paramCount, int p[]); +typedef void (*AT_COMMAND_CALLBACK)(const byte * command); struct DCCEXParser { @@ -29,6 +30,7 @@ struct DCCEXParser void parse(Print * stream, byte * command, bool blocking); void flush(); static void setFilter(FILTER_CALLBACK filter); + static void setAtCommandCallback(AT_COMMAND_CALLBACK filter); static const int MAX_PARAMS=10; // Must not exceed this private: @@ -59,6 +61,7 @@ struct DCCEXParser static void callback_Vbit(int result); static void callback_Vbyte(int result); static FILTER_CALLBACK filterCallback; + static AT_COMMAND_CALLBACK atCommandCallback; static void funcmap(int cab, byte value, byte fstart, byte fstop); }; diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 4d9a7e3..f027ea0 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -60,6 +60,8 @@ bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid checkForOK(200, OK_SEARCH, true); } streamer=new MemStream(buffer, MAX_WIFI_BUFFER); + parser.setAtCommandCallback(ATCommand); + DIAG(F("\n++ Wifi Setup %S ++\n"), connected ? F("OK") : F("FAILED")); return connected; }