1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-07 16:23:38 +03:00

code review

This commit is contained in:
Ivan Grokhotkov 2015-05-22 03:36:04 +03:00
parent 57a1bdc99f
commit 5bdb26ac29
3 changed files with 19 additions and 19 deletions

View File

@ -38,9 +38,9 @@ extern "C" void esp_schedule();
extern "C" void esp_yield(); extern "C" void esp_yield();
ESP8266WiFiClass::ESP8266WiFiClass() ESP8266WiFiClass::ESP8266WiFiClass()
: _useApMode(false)
, _useClientMode(false)
{ {
useApMode = false;
useClientMode = false;
} }
void ESP8266WiFiClass::mode(WiFiMode m) void ESP8266WiFiClass::mode(WiFiMode m)
@ -55,9 +55,9 @@ int ESP8266WiFiClass::begin(char* ssid, char *passphrase, int32_t channel, uint8
} }
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){ int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){
useClientMode = true; _useClientMode = true;
if(useApMode) { if(_useApMode) {
// turn on AP+STA mode // turn on AP+STA mode
mode(WIFI_AP_STA); mode(WIFI_AP_STA);
} else { } else {
@ -143,7 +143,7 @@ void ESP8266WiFiClass::softAP(const char* ssid)
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel) void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel)
{ {
if(useClientMode) { if(_useClientMode) {
// turn on AP+STA mode // turn on AP+STA mode
mode(WIFI_AP_STA); mode(WIFI_AP_STA);
} else { } else {
@ -371,18 +371,18 @@ bool ESP8266WiFiClass::isHidden(uint8_t i)
return (it->is_hidden != 0); return (it->is_hidden != 0);
} }
bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, const char** ssid, uint8_t * encType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden) bool ESP8266WiFiClass::getNetworkInfo(uint8_t i, String &ssid, uint8_t &encType, int32_t &rssi, uint8_t* &bssid, int32_t &channel, bool &isHidden)
{ {
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i)); struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
if (!it) if (!it)
return false; return false;
*ssid = (const char*) &it->ssid[0]; // move ptr ssid = (const char*)it->ssid;
*encType = encryptionType(i); encType = encryptionType(i);
*RSSI = it->rssi; rssi = it->rssi;
*BSSID = &it->bssid[0]; // move ptr bssid = it->bssid; // move ptr
*channel = it->channel; channel = it->channel;
*isHidden = (it->is_hidden != 0); isHidden = (it->is_hidden != 0);
return true; return true;
} }

View File

@ -238,7 +238,7 @@ public:
* @param isHidden bool * * @param isHidden bool *
* @return (true if ok) * @return (true if ok)
*/ */
bool getNetworkInfo(uint8_t networkItem, const char** ssid, uint8_t * encryptionType, int32_t * RSSI, uint8_t ** BSSID, int32_t * channel, bool * isHidden); bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
/* /*
@ -290,8 +290,8 @@ protected:
static void _smartConfigDone(void* result); static void _smartConfigDone(void* result);
bool _smartConfigStarted = false; bool _smartConfigStarted = false;
bool useApMode; bool _useApMode;
bool useClientMode; bool _useClientMode;
static size_t _scanCount; static size_t _scanCount;
static void* _scanResult; static void* _scanResult;

View File

@ -59,21 +59,21 @@ wl_status_t ESP8266WiFiMulti::run(void) {
DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", n); DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", n);
for(int8_t i = 0; i < n; ++i) { for(int8_t i = 0; i < n; ++i) {
const char * ssid_scan; String ssid_scan;
int32_t rssi_scan; int32_t rssi_scan;
uint8_t sec_scan; uint8_t sec_scan;
uint8_t* BSSID_scan; uint8_t* BSSID_scan;
int32_t chan_scan; int32_t chan_scan;
bool hidden_scan; bool hidden_scan;
WiFi.getNetworkInfo(i, &ssid_scan, &sec_scan, &rssi_scan, &BSSID_scan, &chan_scan, &hidden_scan); WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan);
bool known = false; bool known = false;
for(uint32_t x = 0; x < APlist.size(); x++) { for(uint32_t x = 0; x < APlist.size(); x++) {
WifiAPlist_t entry = APlist[x]; WifiAPlist_t entry = APlist[x];
if(strcmp(entry.ssid, ssid_scan) == 0) { // SSID match if(ssid_scan == entry.ssid) { // SSID match
known = true; known = true;
if(rssi_scan > bestNetworkDb) { // best network if(rssi_scan > bestNetworkDb) { // best network
if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan if(sec_scan == ENC_TYPE_NONE || entry.passphrase) { // check for passphrase if not open wlan