mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-27 04:33:04 +00:00
Zmartcharge support (#1007)
* ZC initial implementation * ZmartCharge * Fixed zc bug * Adjustments to ZmartCharge connection
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#define EEPROM_CHECK_SUM 104 // Used to check if config is stored. Change if structure changes
|
||||
#define EEPROM_CLEARED_INDICATOR 0xFC
|
||||
#define EEPROM_CONFIG_ADDRESS 0
|
||||
#define EEPROM_TEMP_CONFIG_ADDRESS 2048
|
||||
|
||||
#define CONFIG_SYSTEM_START 8
|
||||
#define CONFIG_NETWORK_START 40
|
||||
@@ -30,6 +29,7 @@
|
||||
#define CONFIG_UI_START 1720
|
||||
#define CONFIG_CLOUD_START 1742
|
||||
#define CONFIG_UPGRADE_INFO_START 1934
|
||||
#define CONFIG_ZC_START 2000
|
||||
|
||||
#define CONFIG_METER_START_103 32
|
||||
#define CONFIG_UPGRADE_INFO_START_103 216
|
||||
@@ -254,6 +254,12 @@ struct CloudConfig {
|
||||
uint8_t proto;
|
||||
}; // 88
|
||||
|
||||
struct ZmartChargeConfig {
|
||||
bool enabled;
|
||||
char token[21];
|
||||
char baseUrl[64];
|
||||
}; // 86
|
||||
|
||||
class AmsConfiguration {
|
||||
public:
|
||||
bool hasConfig();
|
||||
@@ -347,6 +353,13 @@ public:
|
||||
void clearCloudConfig(CloudConfig&);
|
||||
bool isCloudChanged();
|
||||
void ackCloudConfig();
|
||||
|
||||
bool getZmartChargeConfig(ZmartChargeConfig&);
|
||||
bool setZmartChargeConfig(ZmartChargeConfig&);
|
||||
void clearZmartChargeConfig(ZmartChargeConfig&);
|
||||
bool isZmartChargeConfigChanged();
|
||||
void ackZmartChargeConfig();
|
||||
|
||||
|
||||
void clear();
|
||||
|
||||
@@ -355,7 +368,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;
|
||||
bool sysChanged = false, networkChanged = false, mqttChanged = false, webChanged = false, meterChanged = true, ntpChanged = true, priceChanged = false, energyAccountingChanged = true, cloudChanged = true, uiLanguageChanged = false, zcChanged = true;
|
||||
|
||||
bool relocateConfig103(); // 2.2.12, until, but not including 2.3
|
||||
|
||||
|
||||
@@ -896,6 +896,65 @@ void AmsConfiguration::ackCloudConfig() {
|
||||
cloudChanged = false;
|
||||
}
|
||||
|
||||
bool AmsConfiguration::getZmartChargeConfig(ZmartChargeConfig& config) {
|
||||
if(hasConfig()) {
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.get(CONFIG_ZC_START, config);
|
||||
EEPROM.end();
|
||||
stripNonAscii((uint8_t*) config.token, 21);
|
||||
stripNonAscii((uint8_t*) config.baseUrl, 64);
|
||||
if(strncmp_P(config.token, PSTR(" "), 1) == 0) {
|
||||
config.enabled = false;
|
||||
memset(config.token, 0, 64);
|
||||
memset(config.baseUrl, 0, 64);
|
||||
}
|
||||
if(strncmp_P(config.baseUrl, PSTR("https"), 5) != 0) {
|
||||
memset(config.baseUrl, 0, 64);
|
||||
snprintf_P(config.baseUrl, 64, PSTR("https://main.zmartcharge.com/api"));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
clearZmartChargeConfig(config);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool AmsConfiguration::setZmartChargeConfig(ZmartChargeConfig& config) {
|
||||
ZmartChargeConfig existing;
|
||||
if(getZmartChargeConfig(existing)) {
|
||||
zcChanged |= config.enabled != existing.enabled;
|
||||
zcChanged |= memcmp(config.token, existing.token, 21) != 0;
|
||||
zcChanged |= memcmp(config.token, existing.baseUrl, 64) != 0;
|
||||
} else {
|
||||
zcChanged = true;
|
||||
}
|
||||
|
||||
stripNonAscii((uint8_t*) config.token, 21);
|
||||
stripNonAscii((uint8_t*) config.baseUrl, 64);
|
||||
if(strncmp_P(config.baseUrl, PSTR("https"), 5) != 0) {
|
||||
memset(config.baseUrl, 0, 64);
|
||||
}
|
||||
|
||||
EEPROM.begin(EEPROM_SIZE);
|
||||
EEPROM.put(CONFIG_ZC_START, config);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AmsConfiguration::clearZmartChargeConfig(ZmartChargeConfig& config) {
|
||||
config.enabled = false;
|
||||
memset(config.token, 0, 21);
|
||||
}
|
||||
|
||||
bool AmsConfiguration::isZmartChargeConfigChanged() {
|
||||
return zcChanged;
|
||||
}
|
||||
|
||||
void AmsConfiguration::ackZmartChargeConfig() {
|
||||
zcChanged = false;
|
||||
}
|
||||
|
||||
void AmsConfiguration::setUiLanguageChanged() {
|
||||
uiLanguageChanged = true;
|
||||
}
|
||||
@@ -1097,6 +1156,10 @@ bool AmsConfiguration::relocateConfig103() {
|
||||
clearCloudConfig(cloud);
|
||||
EEPROM.put(CONFIG_CLOUD_START, cloud);
|
||||
|
||||
ZmartChargeConfig zcc;
|
||||
clearZmartChargeConfig(zcc);
|
||||
EEPROM.put(CONFIG_ZC_START, zcc);
|
||||
|
||||
EEPROM.put(EEPROM_CONFIG_ADDRESS, 104);
|
||||
bool ret = EEPROM.commit();
|
||||
EEPROM.end();
|
||||
|
||||
Reference in New Issue
Block a user