From 97ffecb17234d6807a78b3549f128e3f3b0e8e08 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Sun, 24 Apr 2022 14:59:42 +0200 Subject: [PATCH] source and destination not yet working --- ESPFirewall/lib/Firewall/src/Storage.cpp | 40 +++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/ESPFirewall/lib/Firewall/src/Storage.cpp b/ESPFirewall/lib/Firewall/src/Storage.cpp index 7d95e48..ae4d412 100644 --- a/ESPFirewall/lib/Firewall/src/Storage.cpp +++ b/ESPFirewall/lib/Firewall/src/Storage.cpp @@ -68,9 +68,9 @@ namespace fw uint8_t security_number = EEPROM.read(this->eeprom_settings_head); uint8_t amount_of_rules = EEPROM.read(this->eeprom_amout_of_rules_head); - if (amount_of_rules < 50 || security_number != this->security_number) - return amount_of_rules; - return 0; + if (amount_of_rules > 50 || security_number != this->security_number) + return 0; + return amount_of_rules; } return 0; #endif @@ -109,10 +109,23 @@ namespace fw #elif defined(ESP8266) uint16_t eespom_position = eeprom_rule_position(key); - strncpy(rule_ptr->source, "test", sizeof(rule_ptr->source)); + String source; + + 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)); eespom_position += sizeof(rule_ptr->source); - strncpy(rule_ptr->destination, "test de", sizeof(rule_ptr->destination)); + + 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)); 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)); @@ -146,9 +159,22 @@ namespace fw this->memory.end(); #elif defined(ESP8266) uint16_t eespom_position = eeprom_rule_position(rule_ptr->key); - EEPROM.write(this->eeprom_rules_head, rule_ptr->protocol); + + for (uint8_t i = 0; i < strlen(rule_ptr->source); i++) + { + EEPROM.write(eespom_position + i, rule_ptr->source[i]); + } + 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]); + } + eespom_position += sizeof(rule_ptr->destination); + + EEPROM.write(eespom_position, rule_ptr->protocol); eespom_position += sizeof(rule_ptr->protocol); - EEPROM.write(this->eeprom_rules_head, rule_ptr->target); + EEPROM.write(eespom_position, rule_ptr->target); EEPROM.commit(); #endif }