mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-31 06:01:57 +00:00
started adding auto update option
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#define CONFIG_UI_START 1720
|
||||
#define CONFIG_CLOUD_START 1742
|
||||
#define CONFIG_UPGRADE_INFO_START 1934
|
||||
#define CONFIG_UPGRADE_SETTINGS_START 1964
|
||||
#define CONFIG_ZC_START 2000
|
||||
|
||||
#define CONFIG_METER_START_103 32
|
||||
@@ -245,6 +246,12 @@ struct UpgradeInformation {
|
||||
int8_t errorCode;
|
||||
}; // 25
|
||||
|
||||
struct UpgradeConfig {
|
||||
bool autoUpgrade;
|
||||
uint8_t windowStartHour;
|
||||
uint8_t windowEndHour;
|
||||
}; // 3
|
||||
|
||||
struct CloudConfig {
|
||||
bool enabled;
|
||||
uint8_t interval;
|
||||
@@ -348,6 +355,12 @@ public:
|
||||
bool setUpgradeInformation(UpgradeInformation&);
|
||||
void clearUpgradeInformation(UpgradeInformation&);
|
||||
|
||||
bool getUpgradeConfig(UpgradeConfig&);
|
||||
bool setUpgradeConfig(UpgradeConfig&);
|
||||
void clearUpgradeConfig(UpgradeConfig&);
|
||||
bool isUpgradeConfigChanged();
|
||||
void ackUpgradeConfig();
|
||||
|
||||
bool getCloudConfig(CloudConfig&);
|
||||
bool setCloudConfig(CloudConfig&);
|
||||
void clearCloudConfig(CloudConfig&);
|
||||
@@ -368,7 +381,7 @@ protected:
|
||||
private:
|
||||
uint8_t configVersion = 0;
|
||||
|
||||
bool sysChanged = false, networkChanged = false, mqttChanged = false, webChanged = false, meterChanged = true, ntpChanged = true, priceChanged = false, energyAccountingChanged = true, cloudChanged = true, uiLanguageChanged = false, zcChanged = true;
|
||||
bool sysChanged = false, networkChanged = false, mqttChanged = false, webChanged = false, meterChanged = true, ntpChanged = true, priceChanged = false, energyAccountingChanged = true, cloudChanged = true, uiLanguageChanged = false, zcChanged = true, upgradeSettingsChanged = false;
|
||||
|
||||
bool relocateConfig103(); // 2.2.12, until, but not including 2.3
|
||||
|
||||
|
||||
@@ -885,6 +885,65 @@ void AmsConfiguration::clearUpgradeInformation(UpgradeInformation& upinfo) {
|
||||
upinfo.reboot_count = 0;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::setUpgradeConfig(UpgradeConfig& cfg) {
|
||||
UpgradeConfig existing;
|
||||
bool hadExisting = getUpgradeConfig(existing);
|
||||
if(!hadExisting) {
|
||||
clearUpgradeConfig(existing);
|
||||
}
|
||||
if(cfg.windowStartHour >= 24) cfg.windowStartHour %= 24;
|
||||
if(cfg.windowEndHour >= 24) cfg.windowEndHour %= 24;
|
||||
|
||||
if(cfg.autoUpgrade != existing.autoUpgrade ||
|
||||
cfg.windowStartHour != existing.windowStartHour ||
|
||||
cfg.windowEndHour != existing.windowEndHour) {
|
||||
upgradeSettingsChanged = true;
|
||||
}
|
||||
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.put(CONFIG_UPGRADE_SETTINGS_START, cfg);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::getUpgradeConfig(UpgradeConfig& cfg) {
|
||||
if(hasConfig()) {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_UPGRADE_SETTINGS_START, cfg);
|
||||
EEPROM.end();
|
||||
if(cfg.windowStartHour == 0xFF || cfg.windowEndHour == 0xFF) {
|
||||
clearUpgradeConfig(cfg);
|
||||
return false;
|
||||
}
|
||||
if(cfg.windowStartHour >= 24) cfg.windowStartHour %= 24;
|
||||
if(cfg.windowEndHour >= 24) cfg.windowEndHour %= 24;
|
||||
if(cfg.windowStartHour == 0 && cfg.windowEndHour == 0 && !cfg.autoUpgrade) {
|
||||
// Detect uninitialized area (all zeros)
|
||||
clearUpgradeConfig(cfg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
clearUpgradeConfig(cfg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AmsConfiguration::clearUpgradeConfig(UpgradeConfig& cfg) {
|
||||
cfg.autoUpgrade = false;
|
||||
cfg.windowStartHour = 2;
|
||||
cfg.windowEndHour = 3;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::isUpgradeConfigChanged() {
|
||||
return upgradeSettingsChanged;
|
||||
}
|
||||
|
||||
void AmsConfiguration::ackUpgradeConfig() {
|
||||
upgradeSettingsChanged = false;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::getCloudConfig(CloudConfig& config) {
|
||||
if(hasConfig()) {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
@@ -1059,6 +1118,10 @@ void AmsConfiguration::clear() {
|
||||
clearUpgradeInformation(upinfo);
|
||||
EEPROM.put(CONFIG_UPGRADE_INFO_START, upinfo);
|
||||
|
||||
UpgradeConfig upgradeCfg;
|
||||
clearUpgradeConfig(upgradeCfg);
|
||||
EEPROM.put(CONFIG_UPGRADE_SETTINGS_START, upgradeCfg);
|
||||
|
||||
CloudConfig cloud;
|
||||
clearCloudConfig(cloud);
|
||||
EEPROM.put(CONFIG_CLOUD_START, cloud);
|
||||
@@ -1180,6 +1243,9 @@ bool AmsConfiguration::relocateConfig103() {
|
||||
ui.darkMode = 2;
|
||||
|
||||
EEPROM.put(CONFIG_UPGRADE_INFO_START, upinfo);
|
||||
UpgradeConfig upgradeCfg;
|
||||
clearUpgradeConfig(upgradeCfg);
|
||||
EEPROM.put(CONFIG_UPGRADE_SETTINGS_START, upgradeCfg);
|
||||
EEPROM.put(CONFIG_NETWORK_START, wifi);
|
||||
EEPROM.put(CONFIG_METER_START, meter);
|
||||
EEPROM.put(CONFIG_GPIO_START, gpio);
|
||||
|
||||
Reference in New Issue
Block a user