From cb2a8f4972bda5cdf1db87412a40ec2ba652399a Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Tue, 15 Oct 2019 14:34:14 +0900 Subject: [PATCH] Change station_config_dhcp enum --- examples/Credential/Credential.ino | 2 +- examples/CreditMigrate/CreditMigrate.ino | 13 ++++++++++++- src/AutoConnectCredential.h | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/Credential/Credential.ino b/examples/Credential/Credential.ino index 4759c87..ed1e0bc 100644 --- a/examples/Credential/Credential.ino +++ b/examples/Credential/Credential.ino @@ -103,7 +103,7 @@ PageBuilder delPage("/del", { elmDel }); // with the
  • tag. String viewCredential(PageArgument& args) { AutoConnectCredential ac(CREDENTIAL_OFFSET); - struct station_config entry; + station_config_t entry; String content = ""; uint8_t count = ac.entries(); // Get number of entries. diff --git a/examples/CreditMigrate/CreditMigrate.ino b/examples/CreditMigrate/CreditMigrate.ino index 214c87f..118dc8f 100644 --- a/examples/CreditMigrate/CreditMigrate.ino +++ b/examples/CreditMigrate/CreditMigrate.ino @@ -75,7 +75,7 @@ void convert(const uint8_t* eeprom, const size_t size) { break; // Obtain each entry and store to Preferences - struct station_config config; + station_config_t config; Serial.printf("[%d] ", ec); uint8_t ei = 0; do { @@ -91,6 +91,17 @@ void convert(const uint8_t* eeprom, const size_t size) { config.bssid[ei] = *dp++; Serial.printf(":%02x", config.bssid[ei]); } + config.dhcp = *dp++; + if (config.dhcp == STA_STATIC) { + for (uint8_t e = 0; e < sizeof(station_config_t::_config::addr) / sizeof(uint32_t); e++) { + uint32_t* ip = &config.config.addr[e]; + *ip = 0; + for (uint8_t b = 0; b < sizeof(uint32_t); b++) { + *ip <<= 8; + *ip += *dp++; + } + } + } bool rc = credential.save(&config); Serial.println(rc ? " transferred" : " failed to save Preferences"); } diff --git a/src/AutoConnectCredential.h b/src/AutoConnectCredential.h index de75003..1a22fc9 100644 --- a/src/AutoConnectCredential.h +++ b/src/AutoConnectCredential.h @@ -53,7 +53,7 @@ extern "C" { #endif typedef enum { - STA_DHCP, + STA_DHCP = 0, STA_STATIC } station_config_dhcp; @@ -61,7 +61,7 @@ typedef struct { uint8_t ssid[32]; uint8_t password[64]; uint8_t bssid[6]; - uint8_t dhcp; /**< 1:DHCP, 2:Static IP */ + uint8_t dhcp; /**< 0:DHCP, 1:Static IP */ union _config { uint32_t addr[5]; struct _sta {