47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <config.h>
|
|
#include <eeprom.h>
|
|
#include <logger.h>
|
|
|
|
t_configBlock defaultConfigBlock = {
|
|
.configMagic = CONFIG_MAGIC,
|
|
.deviceName = "MBGW3",
|
|
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0D },
|
|
.frontendThreshold = 240,
|
|
.brokerName = "mqttbroker",
|
|
.watchdogTopic = "IoT/Watchdog",
|
|
.startupTopic = "IoT/MBGW3/Startup",
|
|
.statusTopic = "IoT/MBGW3/Status",
|
|
.mbusDataTopic = "IoT/MBGW3/Measurement",
|
|
.syslogServerName = "syslogserver",
|
|
.filler = { 0, 0 }
|
|
};
|
|
|
|
|
|
t_configBlock mainConfigBlock;
|
|
|
|
|
|
|
|
t_configBlock* getConfig() {
|
|
return &defaultConfigBlock;
|
|
}
|
|
|
|
|
|
void configInit() {
|
|
bool configIsInvalid = false;
|
|
do {
|
|
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom");
|
|
eepromReadConfigBlock(0, &mainConfigBlock);
|
|
|
|
if (mainConfigBlock.configMagic != CONFIG_MAGIC) {
|
|
configIsValid = true;
|
|
|
|
coloredMsg(LOG_BLUE, false, "cfg ci Invalid configuration block read from eeprom");
|
|
|
|
eepromWriteConfigBlock(0, &defaultConfigBlock);
|
|
coloredMsg(LOG_BLUE, false, "cfg ci Default configuration block written to eeprom");
|
|
}
|
|
} while (configIsInvalid);
|
|
} |