From c8822d79b53122321d68e5f112006eee37a81acd Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Sun, 24 Apr 2022 16:46:19 +0200 Subject: [PATCH] eeprom position was wrong, use put to store --- ESPFirewall/lib/Firewall/src/Storage.cpp | 39 +++++++++--------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/ESPFirewall/lib/Firewall/src/Storage.cpp b/ESPFirewall/lib/Firewall/src/Storage.cpp index ae4d412..4b6024b 100644 --- a/ESPFirewall/lib/Firewall/src/Storage.cpp +++ b/ESPFirewall/lib/Firewall/src/Storage.cpp @@ -49,7 +49,7 @@ namespace fw total_space_needed += sizeof(rule.target); total_space_needed += sizeof(rule.protocol); // key-1 because key will be in range 1-255, but we need 1 less for multiplication - return eeprom_rules_head + key - 1 * total_space_needed; + return eeprom_rules_head + (key - 1) * total_space_needed; } uint8_t Storage::retrieve_settings_value(const char *key) @@ -109,25 +109,20 @@ namespace fw #elif defined(ESP8266) uint16_t eespom_position = eeprom_rule_position(key); - String source; + const char source[IPV4ADDRESS_LENGTH] = ""; + const char destination[IPV4ADDRESS_LENGTH] = ""; - for (uint8_t i = 0; i < sizeof(rule_ptr->source); i++) - { - source += EEPROM.read(eespom_position + i); - } - strncpy(rule_ptr->source, source.c_str(), sizeof(rule_ptr->source)); + EEPROM.get(eespom_position, source); + strncpy(rule_ptr->source, source, sizeof(rule_ptr->source)); eespom_position += sizeof(rule_ptr->source); - String destination; - for (uint8_t i = 0; i < sizeof(rule_ptr->destination); i++) - { - destination += EEPROM.read(eespom_position + i); - } - strncpy(rule_ptr->destination, destination.c_str(), sizeof(rule_ptr->destination)); + EEPROM.get(eespom_position, destination); + strncpy(rule_ptr->destination, destination, sizeof(rule_ptr->destination)); eespom_position += sizeof(rule_ptr->destination); rule_ptr->protocol = static_cast(EEPROM.read(eespom_position)); eespom_position += sizeof(rule_ptr->protocol); + rule_ptr->target = static_cast(EEPROM.read(eespom_position)); #endif return rule_ptr; @@ -156,25 +151,19 @@ namespace fw this->memory.putString("destination", rule_ptr->destination); this->memory.putUChar("protocol", rule_ptr->protocol); this->memory.putUChar("target", rule_ptr->target); + this->memory.end(); #elif defined(ESP8266) uint16_t eespom_position = eeprom_rule_position(rule_ptr->key); - for (uint8_t i = 0; i < strlen(rule_ptr->source); i++) - { - EEPROM.write(eespom_position + i, rule_ptr->source[i]); - } + EEPROM.put(eespom_position, rule_ptr->source); eespom_position += sizeof(rule_ptr->source); - - for (uint8_t i = 0; i < strlen(rule_ptr->destination); i++) - { - EEPROM.write(eespom_position + i, rule_ptr->destination[i]); - } + EEPROM.put(eespom_position, rule_ptr->destination); eespom_position += sizeof(rule_ptr->destination); - - EEPROM.write(eespom_position, rule_ptr->protocol); + EEPROM.put(eespom_position, rule_ptr->protocol); eespom_position += sizeof(rule_ptr->protocol); - EEPROM.write(eespom_position, rule_ptr->target); + EEPROM.put(eespom_position, rule_ptr->target); + EEPROM.commit(); #endif }