configuration
This commit is contained in:
parent
cb5dd5f79a
commit
6d7119c0e2
@ -15,6 +15,7 @@ typedef struct __attribute__((__packed__)) s_configBlock {
|
|||||||
char statusTopic[64];
|
char statusTopic[64];
|
||||||
char mbusDataTopic[64];
|
char mbusDataTopic[64];
|
||||||
char syslogServerName[64];
|
char syslogServerName[64];
|
||||||
|
uint8_t filler[3];
|
||||||
} t_configBlock;
|
} t_configBlock;
|
||||||
|
|
||||||
void configInit();
|
void configInit();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <spi.h>
|
#include <spi.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct __attribute__((__packed__)) s_deviceStats {
|
typedef struct __attribute__((__packed__)) s_deviceStats {
|
||||||
@ -17,5 +18,7 @@ void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
|||||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||||
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
|
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||||
t_deviceStats* getGlobalDeviceStats();
|
t_deviceStats* getGlobalDeviceStats();
|
||||||
|
void eepromReadConfigBlock(uint8_t blockNum, t_configBlock *destConfigBlock);
|
||||||
|
|
||||||
|
|
||||||
#endif /* EEPROM_H_ */
|
#endif /* EEPROM_H_ */
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <config.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <eeprom.h>
|
||||||
|
|
||||||
|
|
||||||
t_configBlock defaultConfigBlock = {
|
t_configBlock defaultConfigBlock = {
|
||||||
@ -12,9 +14,19 @@ t_configBlock defaultConfigBlock = {
|
|||||||
.statusTopic = "IoT/MBGW3/Status",
|
.statusTopic = "IoT/MBGW3/Status",
|
||||||
.mbusDataTopic = "IoT/MBGW3/Measurement",
|
.mbusDataTopic = "IoT/MBGW3/Measurement",
|
||||||
.syslogServerName = "syslogserver",
|
.syslogServerName = "syslogserver",
|
||||||
|
.filler = { 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
t_configBlock mainConfigBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
t_configBlock* getConfig() {
|
t_configBlock* getConfig() {
|
||||||
return &defaultConfigBlock;
|
return &defaultConfigBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void configInit() {
|
||||||
|
eepromReadConfigBlock(0, &mainConfigBlock);
|
||||||
|
}
|
@ -48,6 +48,8 @@ static t_deviceStatsBlock deviceStats;
|
|||||||
static const uint8_t NUM_OF_BLOCKS = 2;
|
static const uint8_t NUM_OF_BLOCKS = 2;
|
||||||
static const uint16_t BLOCK_ADDR[] = { 64, 4128 };
|
static const uint16_t BLOCK_ADDR[] = { 64, 4128 };
|
||||||
|
|
||||||
|
static const uint8_t EEPROM_WRITE_BLOCK_SIZE = 32;
|
||||||
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct __attribute__((__packed__)) s_spiMsg {
|
struct __attribute__((__packed__)) s_spiMsg {
|
||||||
@ -58,7 +60,6 @@ typedef union {
|
|||||||
uint8_t b[sizeof(struct s_spiMsg)];
|
uint8_t b[sizeof(struct s_spiMsg)];
|
||||||
} t_spiMsg;
|
} t_spiMsg;
|
||||||
|
|
||||||
|
|
||||||
t_deviceStats* getGlobalDeviceStats() {
|
t_deviceStats* getGlobalDeviceStats() {
|
||||||
return &(deviceStats.s);
|
return &(deviceStats.s);
|
||||||
}
|
}
|
||||||
@ -126,6 +127,15 @@ static void eepromHourlyUpdateDeviceStats(void *handle) {
|
|||||||
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eepromReadConfigBlock(uint8_t blockNum, t_configBlock *destConfigBlock) {
|
||||||
|
uint8_t configBlockSizeMod = sizeof(*destConfigBlock) % EEPROM_WRITE_BLOCK_SIZE;
|
||||||
|
if (configBlockSizeMod != 0) {
|
||||||
|
coloredMsg(LOG_RED, false, "eeRCB, config block size must be dividable by 32");
|
||||||
|
coloredMsg(LOG_RED, false, "eeRCB, current size is %d", sizeof(*destConfigBlock));
|
||||||
|
coloredMsg(LOG_RED, false, "eeRCB, append %d filler octets", configBlockSizeMod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// active waiting, use only during initialization!
|
// active waiting, use only during initialization!
|
||||||
static void eepromActiveDelay(uint8_t delay_ms) {
|
static void eepromActiveDelay(uint8_t delay_ms) {
|
||||||
activeDelay(delay_ms);
|
activeDelay(delay_ms);
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
#include <mqttComm.h>
|
#include <mqttComm.h>
|
||||||
#include <cmdHandler.h>
|
#include <cmdHandler.h>
|
||||||
#include <oled.h>
|
#include <oled.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
void my_setup_1() {
|
void my_setup_1() {
|
||||||
schInit();
|
schInit();
|
||||||
logInit();
|
logInit();
|
||||||
|
configInit();
|
||||||
showInit();
|
showInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user