make it clearer to read
This commit is contained in:
parent
fee5aec4d1
commit
912165d9ee
2 changed files with 23 additions and 8 deletions
|
@ -40,6 +40,12 @@ namespace fw
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t Storage::eeprom_rule_position(uint8_t key)
|
||||||
|
{
|
||||||
|
// key-1 because key will be in range 1-255, but we need 1 less for multiplication
|
||||||
|
return eeprom_rules_head + key - 1 * sizeof(firewall_rule_t);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t Storage::retrieve_settings_value(const char *key)
|
uint8_t Storage::retrieve_settings_value(const char *key)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
|
@ -82,10 +88,9 @@ namespace fw
|
||||||
|
|
||||||
firewall_rule_t *Storage::retrieve_firewall_rule(const uint8_t key)
|
firewall_rule_t *Storage::retrieve_firewall_rule(const uint8_t key)
|
||||||
{
|
{
|
||||||
#ifdef ESP32
|
|
||||||
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
||||||
rule_ptr->key = key;
|
rule_ptr->key = key;
|
||||||
|
#ifdef ESP32
|
||||||
char rulename[9]; // fwRule99\n
|
char rulename[9]; // fwRule99\n
|
||||||
sprintf(rulename, "fwRule%i", key);
|
sprintf(rulename, "fwRule%i", key);
|
||||||
|
|
||||||
|
@ -96,10 +101,13 @@ namespace fw
|
||||||
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", TARGET_REJECT));
|
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", TARGET_REJECT));
|
||||||
this->memory.end();
|
this->memory.end();
|
||||||
|
|
||||||
return rule_ptr;
|
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
return NULL;
|
uint16_t eespom_position = eeprom_rule_position(key);
|
||||||
|
rule_ptr->protocol = static_cast<firewall_protocol_t>(EEPROM.read(eespom_position));
|
||||||
|
eespom_position += sizeof(firewall_protocol_t);
|
||||||
|
rule_ptr->target = static_cast<firewall_target_t>(EEPROM.read(eespom_position));
|
||||||
#endif
|
#endif
|
||||||
|
return rule_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Storage::store_all_firewall_rules(firewall_rule_t *head)
|
void Storage::store_all_firewall_rules(firewall_rule_t *head)
|
||||||
|
@ -126,6 +134,12 @@ namespace fw
|
||||||
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)
|
||||||
|
uint16_t eespom_position = eeprom_rule_position(rule_ptr->key);
|
||||||
|
EEPROM.write(this->eeprom_rules_head, rule_ptr->protocol);
|
||||||
|
eespom_position += sizeof(firewall_protocol_t);
|
||||||
|
EEPROM.write(this->eeprom_rules_head, rule_ptr->target);
|
||||||
|
EEPROM.commit();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,14 @@ namespace fw
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
Preferences memory;
|
Preferences memory;
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
uint16_t eeprom_size = 1000;
|
const uint16_t eeprom_size = 1000;
|
||||||
uint8_t security_number = 93;
|
const uint8_t security_number = 93;
|
||||||
uint16_t eeprom_settings_head = 0;
|
const uint16_t eeprom_settings_head = 0;
|
||||||
uint16_t eeprom_rules_head = 10;
|
const uint16_t eeprom_rules_head = 10;
|
||||||
#endif
|
#endif
|
||||||
ok_t mount_spiffs();
|
ok_t mount_spiffs();
|
||||||
void setup_eeprom();
|
void setup_eeprom();
|
||||||
|
uint16_t eeprom_rule_position(uint8_t);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t retrieve_settings_value(const char *);
|
uint8_t retrieve_settings_value(const char *);
|
||||||
|
|
Reference in a new issue