eeprom position was wrong, use put to store

This commit is contained in:
Florian Hoss 2022-04-24 16:46:19 +02:00
parent 97ffecb172
commit c8822d79b5

View file

@ -49,7 +49,7 @@ namespace fw
total_space_needed += sizeof(rule.target); total_space_needed += sizeof(rule.target);
total_space_needed += sizeof(rule.protocol); total_space_needed += sizeof(rule.protocol);
// key-1 because key will be in range 1-255, but we need 1 less for multiplication // 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) uint8_t Storage::retrieve_settings_value(const char *key)
@ -109,25 +109,20 @@ namespace fw
#elif defined(ESP8266) #elif defined(ESP8266)
uint16_t eespom_position = eeprom_rule_position(key); 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++) EEPROM.get(eespom_position, source);
{ strncpy(rule_ptr->source, source, sizeof(rule_ptr->source));
source += EEPROM.read(eespom_position + i);
}
strncpy(rule_ptr->source, source.c_str(), sizeof(rule_ptr->source));
eespom_position += sizeof(rule_ptr->source); eespom_position += sizeof(rule_ptr->source);
String destination; EEPROM.get(eespom_position, destination);
for (uint8_t i = 0; i < sizeof(rule_ptr->destination); i++) strncpy(rule_ptr->destination, destination, sizeof(rule_ptr->destination));
{
destination += EEPROM.read(eespom_position + i);
}
strncpy(rule_ptr->destination, destination.c_str(), sizeof(rule_ptr->destination));
eespom_position += sizeof(rule_ptr->destination); eespom_position += sizeof(rule_ptr->destination);
rule_ptr->protocol = static_cast<firewall_protocol_t>(EEPROM.read(eespom_position)); rule_ptr->protocol = static_cast<firewall_protocol_t>(EEPROM.read(eespom_position));
eespom_position += sizeof(rule_ptr->protocol); eespom_position += sizeof(rule_ptr->protocol);
rule_ptr->target = static_cast<firewall_target_t>(EEPROM.read(eespom_position)); rule_ptr->target = static_cast<firewall_target_t>(EEPROM.read(eespom_position));
#endif #endif
return rule_ptr; return rule_ptr;
@ -156,25 +151,19 @@ namespace fw
this->memory.putString("destination", rule_ptr->destination); this->memory.putString("destination", rule_ptr->destination);
this->memory.putUChar("protocol", rule_ptr->protocol); this->memory.putUChar("protocol", rule_ptr->protocol);
this->memory.putUChar("target", rule_ptr->target); this->memory.putUChar("target", rule_ptr->target);
this->memory.end(); this->memory.end();
#elif defined(ESP8266) #elif defined(ESP8266)
uint16_t eespom_position = eeprom_rule_position(rule_ptr->key); uint16_t eespom_position = eeprom_rule_position(rule_ptr->key);
for (uint8_t i = 0; i < strlen(rule_ptr->source); i++) EEPROM.put(eespom_position, rule_ptr->source);
{
EEPROM.write(eespom_position + i, rule_ptr->source[i]);
}
eespom_position += sizeof(rule_ptr->source); eespom_position += sizeof(rule_ptr->source);
EEPROM.put(eespom_position, rule_ptr->destination);
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); eespom_position += sizeof(rule_ptr->destination);
EEPROM.put(eespom_position, rule_ptr->protocol);
EEPROM.write(eespom_position, rule_ptr->protocol);
eespom_position += sizeof(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(); EEPROM.commit();
#endif #endif
} }