1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

forgotten end of setup function

This commit is contained in:
Harald Barth 2020-10-28 21:16:41 +01:00
commit bf4190063a
2 changed files with 37 additions and 24 deletions

View File

@ -57,7 +57,7 @@ bool WifiInterface::setup(long serial_link_speed,
const __FlashStringHelper *hostname, const __FlashStringHelper *hostname,
const int port) { const int port) {
bool wifiUp = false; wifiSerialState wifiUp = WIFI_NOAT;
#if NUM_SERIAL == 0 #if NUM_SERIAL == 0
// no warning about unused parameters. // no warning about unused parameters.
@ -75,7 +75,7 @@ bool WifiInterface::setup(long serial_link_speed,
// Other serials are tried, depending on hardware. // Other serials are tried, depending on hardware.
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
if (!wifiUp) if (wifiUp == WIFI_NOAT)
{ {
Serial2.begin(serial_link_speed); Serial2.begin(serial_link_speed);
wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port); wifiUp = setup(Serial2, wifiESSID, wifiPassword, hostname, port);
@ -83,23 +83,29 @@ bool WifiInterface::setup(long serial_link_speed,
#endif #endif
#if NUM_SERIAL > 2 #if NUM_SERIAL > 2
if (!wifiUp) if (wifiUp == WIFI_NOAT)
{ {
Serial3.begin(serial_link_speed); Serial3.begin(serial_link_speed);
wifiUp = setup(Serial3, wifiESSID, wifiPassword, hostname, port); wifiUp = setup(Serial3, wifiESSID, wifiPassword, hostname, port);
} }
#endif #endif
DCCEXParser::setAtCommandCallback(ATCommand); if (wifiUp == WIFI_NOAT) // here and still not AT commands found
return false;
DCCEXParser::setAtCommandCallback(ATCommand);
// CAUTION... ONLY CALL THIS ONCE // CAUTION... ONLY CALL THIS ONCE
WifiInboundHandler::setup(wifiStream); WifiInboundHandler::setup(wifiStream);
if (wifiUp == WIFI_CONNECTED)
return wifiUp; connected = true;
else
connected = false;
return connected;
} }
bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password, wifiSerialState WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid, const __FlashStringHelper* password,
const __FlashStringHelper* hostname, int port) { const __FlashStringHelper* hostname, int port) {
wifiSerialState wifiState;
static uint8_t ntry = 0; static uint8_t ntry = 0;
ntry++; ntry++;
@ -107,19 +113,24 @@ bool WifiInterface::setup(Stream & setupStream, const __FlashStringHelper* SSid
DIAG(F("\n++ Wifi Setup Try %d ++\n"), ntry); DIAG(F("\n++ Wifi Setup Try %d ++\n"), ntry);
connected = setup2( SSid, password, hostname, port); wifiState = setup2( SSid, password, hostname, port);
if (connected) { if (wifiState == WIFI_NOAT) {
DIAG(F("\n++ Wifi Setup NO AT ++\n"));
return wifiState;
}
if (wifiState == WIFI_CONNECTED) {
StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo
checkForOK(200, OK_SEARCH, true); checkForOK(200, OK_SEARCH, true);
} }
DIAG(F("\n++ Wifi Setup %S ++\n"), connected ? F("OK") : F("FAILED")); DIAG(F("\n++ Wifi Setup %S ++\n"), wifiState == WIFI_CONNECTED ? F("CONNECTED") : F("DISCONNECTED"));
return connected; return wifiState;
} }
bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringHelper* password, wifiSerialState WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringHelper* password,
const __FlashStringHelper* hostname, int port) { const __FlashStringHelper* hostname, int port) {
bool ipOK = false; bool ipOK = false;
bool oldCmd = false; bool oldCmd = false;
@ -132,12 +143,12 @@ bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringH
if (checkForOK(200,IPD_SEARCH, true)) { if (checkForOK(200,IPD_SEARCH, true)) {
DIAG(F("\nPreconfigured Wifi already running with data waiting\n")); DIAG(F("\nPreconfigured Wifi already running with data waiting\n"));
// loopstate=4; // carry on from correct place... or not as the case may be // loopstate=4; // carry on from correct place... or not as the case may be
return true; return WIFI_CONNECTED;
} }
StringFormatter::send(wifiStream, F("AT\r\n")); // Is something here that understands AT? StringFormatter::send(wifiStream, F("AT\r\n")); // Is something here that understands AT?
if(!checkForOK(200, OK_SEARCH, true)) if(!checkForOK(200, OK_SEARCH, true))
return false; // No AT compatible WiFi module here return WIFI_NOAT; // No AT compatible WiFi module here
StringFormatter::send(wifiStream, F("ATE1\r\n")); // Turn on the echo, se we can see what's happening StringFormatter::send(wifiStream, F("ATE1\r\n")); // Turn on the echo, se we can see what's happening
checkForOK(2000, OK_SEARCH, true); // Makes this visible on the console checkForOK(2000, OK_SEARCH, true); // Makes this visible on the console
@ -241,16 +252,16 @@ bool WifiInterface::setup2(const __FlashStringHelper* SSid, const __FlashStringH
checkForOK(10000, OK_SEARCH, true); // ignore result in case it already was off checkForOK(10000, OK_SEARCH, true); // ignore result in case it already was off
StringFormatter::send(wifiStream, F("AT+CIPMUX=1\r\n")); // configure for multiple connections StringFormatter::send(wifiStream, F("AT+CIPMUX=1\r\n")); // configure for multiple connections
if (!checkForOK(10000, OK_SEARCH, true)) return false; if (!checkForOK(10000, OK_SEARCH, true)) return WIFI_DISCONNECTED;
StringFormatter::send(wifiStream, F("AT+CIPSERVER=1,%d\r\n"), port); // turn on server on port StringFormatter::send(wifiStream, F("AT+CIPSERVER=1,%d\r\n"), port); // turn on server on port
if (!checkForOK(10000, OK_SEARCH, true)) return false; if (!checkForOK(10000, OK_SEARCH, true)) return WIFI_DISCONNECTED;
StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG StringFormatter::send(wifiStream, F("AT+CIFSR\r\n")); // Display ip addresses to the DIAG
if (!checkForOK(10000, OK_SEARCH, true, false)) return false; if (!checkForOK(10000, OK_SEARCH, true, false)) return WIFI_DISCONNECTED;
DIAG(F("\nPORT=%d\n"),port); DIAG(F("\nPORT=%d\n"),port);
return true; return WIFI_CONNECTED;
} }

View File

@ -23,6 +23,8 @@
#include <Arduino.h> #include <Arduino.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
enum wifiSerialState { WIFI_NOAT, WIFI_DISCONNECTED, WIFI_CONNECTED };
class WifiInterface class WifiInterface
{ {
@ -36,11 +38,11 @@ public:
static void ATCommand(const byte *command); static void ATCommand(const byte *command);
private: private:
static bool setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password, static wifiSerialState setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
const __FlashStringHelper *hostname, int port); const __FlashStringHelper *hostname, int port);
static Stream *wifiStream; static Stream *wifiStream;
static DCCEXParser parser; static DCCEXParser parser;
static bool setup2(const __FlashStringHelper *SSSid, const __FlashStringHelper *password, static wifiSerialState setup2(const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
const __FlashStringHelper *hostname, int port); const __FlashStringHelper *hostname, int port);
static bool checkForOK(const unsigned int timeout, const char *waitfor, bool echo, bool escapeEcho = true); static bool checkForOK(const unsigned int timeout, const char *waitfor, bool echo, bool escapeEcho = true);
static bool connected; static bool connected;