device configuration prepared

This commit is contained in:
Wolfgang Hottgenroth 2020-11-30 18:48:48 +01:00
parent f22c821ca3
commit 98c0a9d7a2
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 39 additions and 9 deletions

View File

@ -44,5 +44,7 @@ void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
void mbusCommErrorCallback(UART_HandleTypeDef *huart);
void mbusCommSetStats(t_mbusCommStats stats);
t_mbusCommStats *mbusCommGetStats();
void mbusCommAddDevice(t_deviceBlock *deviceBlock);
#endif // _MBUSCOMM_H_

View File

@ -4,6 +4,8 @@
#include <config.h>
#include <eeprom.h>
#include <logger.h>
#include <mbusComm.h>
t_configBlock defaultConfigBlock = {
.configMagic = CONFIG_MAGIC,
@ -85,6 +87,7 @@ void configInit() {
for (uint8_t i = 0; i < mainConfigBlock.numOfDeviceBlocks; i++) {
t_deviceBlock tmpDeviceBlock;
eepromReadDeviceBlock(i, &tmpDeviceBlock);
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
coloredMsg(LOG_BLUE, false, "cfg ci device %d: ", i);
coloredMsg(LOG_BLUE, false, " Name: %s, Address: %d, Period: %d",
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
@ -93,5 +96,9 @@ void configInit() {
tmpDeviceBlock.consideredField[1],
tmpDeviceBlock.consideredField[2],
tmpDeviceBlock.consideredField[3]);
mbusCommAddDevice(&tmpDeviceBlock);
} else {
coloredMsg(LOG_BLUE, false, " magic does not match, ignored");
}
}
}

View File

@ -607,7 +607,25 @@ static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
#define PERIOD 10
static uint8_t numOfDevices = 8;
static uint8_t numOfDevices = 0;
static t_mbusDevice *devices = NULL;
void mbusCommAddDevice(t_deviceBlock *deviceBlock) {
devices = (t_mbusDevice*) realloc((void*) devices, (numOfDevices + 1) * sizeof(t_mbusDevice));
strcpy(devices[numOfDevices].deviceName, deviceBlock->deviceName);
devices[numOfDevices].address = deviceBlock->address;
memcpy(devices[numOfDevices].consideredField, deviceBlock->consideredField, sizeof(deviceBlock->consideredField));
devices[numOfDevices].period = deviceBlock->period;
devices[numOfDevices].requests = 0;
devices[numOfDevices].failures = 0;
devices[numOfDevices].delay = 0;
devices[numOfDevices].waiting = false;
devices[numOfDevices].active = true;
coloredMsg(LOG_YELLOW, true, "mbc mbcad device added %d %s %d", numOfDevices, devices[numOfDevices].deviceName, devices[numOfDevices].address);
numOfDevices += 1;
}
/*
static t_mbusDevice devices[] = {
{
.deviceName = "Total",
@ -698,6 +716,9 @@ static t_mbusDevice devices[] = {
.active = true
}
};
*/
static void triggerMBusRequest(void *handle) {