From 002389231369d1f4af987b2068f337a3ebe40000 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 8 Oct 2018 15:25:08 +0300 Subject: [PATCH] Organize private members Organize private members and drop superfluous ESP8266Interface::_disable_default_softap() --- ESP8266Interface.cpp | 11 +++-------- ESP8266Interface.h | 29 ++++++++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/ESP8266Interface.cpp b/ESP8266Interface.cpp index 9c866d8..166742d 100644 --- a/ESP8266Interface.cpp +++ b/ESP8266Interface.cpp @@ -45,9 +45,9 @@ #if defined MBED_CONF_ESP8266_TX && defined MBED_CONF_ESP8266_RX ESP8266Interface::ESP8266Interface() : _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG, MBED_CONF_ESP8266_RTS, MBED_CONF_ESP8266_CTS), + _ap_sec(NSAPI_SECURITY_UNKNOWN), _initialized(false), _started(false), - _ap_sec(NSAPI_SECURITY_UNKNOWN), _conn_stat(NSAPI_STATUS_DISCONNECTED), _conn_stat_cb(NULL) { @@ -69,9 +69,9 @@ ESP8266Interface::ESP8266Interface() // ESP8266Interface implementation ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName rts, PinName cts) : _esp(tx, rx, debug, rts, cts), + _ap_sec(NSAPI_SECURITY_UNKNOWN), _initialized(false), _started(false), - _ap_sec(NSAPI_SECURITY_UNKNOWN), _conn_stat(NSAPI_STATUS_DISCONNECTED), _conn_stat_cb(NULL) { @@ -271,11 +271,6 @@ bool ESP8266Interface::_get_firmware_ok() return true; } -bool ESP8266Interface::_disable_default_softap() -{ - return _esp.set_default_wifi_mode(ESP8266::WIFIMODE_STATION); -} - nsapi_error_t ESP8266Interface::_init(void) { if (!_initialized) { @@ -294,7 +289,7 @@ nsapi_error_t ESP8266Interface::_init(void) if (!_get_firmware_ok()) { return NSAPI_ERROR_DEVICE_ERROR; } - if (!_disable_default_softap()) { + if (!_esp.set_default_wifi_mode(ESP8266::WIFIMODE_STATION)) { return NSAPI_ERROR_DEVICE_ERROR; } if (!_esp.cond_enable_tcp_passive_mode()) { diff --git a/ESP8266Interface.h b/ESP8266Interface.h index 9a5bf84..0e46bb4 100644 --- a/ESP8266Interface.h +++ b/ESP8266Interface.h @@ -318,11 +318,16 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface } private: + // AT layer + ESP8266 _esp; + + // Credentials static const int ESP8266_SSID_MAX_LENGTH = 32; /* 32 is what 802.11 defines as longest possible name */ + char ap_ssid[ESP8266_SSID_MAX_LENGTH + 1]; /* The longest possible name; +1 for the \0 */ static const int ESP8266_PASSPHRASE_MAX_LENGTH = 63; /* The longest allowed passphrase */ static const int ESP8266_PASSPHRASE_MIN_LENGTH = 8; /* The shortest allowed passphrase */ - - ESP8266 _esp; + char ap_pass[ESP8266_PASSPHRASE_MAX_LENGTH + 1]; /* The longest possible passphrase; +1 for the \0 */ + nsapi_security_t _ap_sec; // Drivers's socket info struct _sock_info { @@ -331,28 +336,26 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface }; struct _sock_info _sock_i[ESP8266_SOCKET_COUNT]; + // Driver's state int _initialized; - int _started; - - char ap_ssid[ESP8266_SSID_MAX_LENGTH + 1]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */ - nsapi_security_t _ap_sec; - char ap_pass[ESP8266_PASSPHRASE_MAX_LENGTH + 1]; - - bool _disable_default_softap(); - void event(); - void update_conn_state_cb(); bool _get_firmware_ok(); nsapi_error_t _init(void); + int _started; nsapi_error_t _startup(const int8_t wifi_mode); + //sigio struct { void (*callback)(void *); void *data; } _cbs[ESP8266_SOCKET_COUNT]; + void event(); - // Connection state reporting + // Connection state reporting to application nsapi_connection_status_t _conn_stat; - Callback _conn_stat_cb; // Application registered + Callback _conn_stat_cb; + + // Connection state from AT layer + void update_conn_state_cb(); }; #endif