Work in Progress on storage
This commit is contained in:
parent
265e0562f8
commit
6461b71799
2 changed files with 17 additions and 17 deletions
|
@ -4,36 +4,35 @@ namespace fw
|
||||||
{
|
{
|
||||||
Storage::Storage()
|
Storage::Storage()
|
||||||
{
|
{
|
||||||
#ifdef ESP8266
|
#ifdef ESP32
|
||||||
|
#elif defined(ESP8266)
|
||||||
this->setup_eeprom();
|
this->setup_eeprom();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::~Storage()
|
Storage::~Storage()
|
||||||
{
|
{
|
||||||
|
#ifdef ESP32
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Storage::setup_eeprom()
|
void Storage::setup_eeprom()
|
||||||
{
|
{
|
||||||
#ifdef ESP8266
|
#ifdef ESP32
|
||||||
|
#elif defined(ESP8266)
|
||||||
EEPROM.begin(this->eeprom_size);
|
EEPROM.begin(this->eeprom_size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Storage::eeprom_rule_position(uint8_t key)
|
uint16_t Storage::eeprom_rule_position(uint8_t key)
|
||||||
{
|
{
|
||||||
#ifdef ESP8266
|
#ifdef ESP32
|
||||||
firewall_rule_t rule;
|
|
||||||
uint8_t total_space_needed = 0;
|
|
||||||
total_space_needed += sizeof(rule.ip);
|
|
||||||
total_space_needed += sizeof(rule.port_from);
|
|
||||||
total_space_needed += sizeof(rule.port_to);
|
|
||||||
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;
|
|
||||||
#elif defined(ESP32)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
uint8_t total_space_needed = sizeof(firewall_rule_t);
|
||||||
|
// key will be in range 1-255, but we need 1 less for multiplication to work
|
||||||
|
return eeprom_rules_head + (key - 1) * total_space_needed;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ namespace fw
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
if (strncmp("amount_of_rules", key, 16) == 0)
|
if (strncmp(amount, key, sizeof(amount)) == 0)
|
||||||
{
|
{
|
||||||
uint8_t security_number = EEPROM.read(this->eeprom_settings_head);
|
uint8_t security_number = EEPROM.read(this->eeprom_settings_head);
|
||||||
uint8_t amount_of_rules = EEPROM.read(this->eeprom_amout_of_rules_head);
|
uint8_t amount_of_rules = EEPROM.read(this->eeprom_amout_of_rules_head);
|
||||||
|
|
|
@ -21,13 +21,14 @@ namespace fw
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
Preferences memory;
|
Preferences memory;
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
// Storage per firewall rule is 42 Byte
|
// Space for 15 Rules plus 10 byte for settings
|
||||||
// Space for 15 Rules is 630 Byte plus 10 byte for settings
|
const uint16_t eeprom_size = 15 * sizeof(firewall_rule_t) + 10;
|
||||||
const uint16_t eeprom_size = 640;
|
// Ramdon security number to check if settings have been written by this
|
||||||
const uint8_t security_number = 93;
|
const uint8_t security_number = 93;
|
||||||
const uint16_t eeprom_settings_head = 0;
|
const uint16_t eeprom_settings_head = 0;
|
||||||
const uint16_t eeprom_amout_of_rules_head = eeprom_settings_head + 1;
|
const uint16_t eeprom_amout_of_rules_head = eeprom_settings_head + 1;
|
||||||
const uint16_t eeprom_rules_head = 10;
|
const uint16_t eeprom_rules_head = 10;
|
||||||
|
const char *amount = "amount_of_rules";
|
||||||
#endif
|
#endif
|
||||||
void setup_eeprom();
|
void setup_eeprom();
|
||||||
uint16_t eeprom_rule_position(uint8_t key);
|
uint16_t eeprom_rule_position(uint8_t key);
|
||||||
|
|
Reference in a new issue