From 98c0a9d7a2c7c3397be2c93cd952055fb9babd1a Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 30 Nov 2020 18:48:48 +0100 Subject: [PATCH] device configuration prepared --- cube/User/Inc/mbusComm.h | 2 ++ cube/User/Src/config.c | 23 +++++++++++++++-------- cube/User/Src/mbusComm.c | 23 ++++++++++++++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cube/User/Inc/mbusComm.h b/cube/User/Inc/mbusComm.h index 6834c93..bb59559 100644 --- a/cube/User/Inc/mbusComm.h +++ b/cube/User/Inc/mbusComm.h @@ -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_ diff --git a/cube/User/Src/config.c b/cube/User/Src/config.c index 4ec4568..1d72688 100644 --- a/cube/User/Src/config.c +++ b/cube/User/Src/config.c @@ -4,6 +4,8 @@ #include #include #include +#include + t_configBlock defaultConfigBlock = { .configMagic = CONFIG_MAGIC, @@ -85,13 +87,18 @@ void configInit() { for (uint8_t i = 0; i < mainConfigBlock.numOfDeviceBlocks; i++) { t_deviceBlock tmpDeviceBlock; eepromReadDeviceBlock(i, &tmpDeviceBlock); - 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); - coloredMsg(LOG_BLUE, false, " Considered Fields: %d %d %d %d", - tmpDeviceBlock.consideredField[0], - tmpDeviceBlock.consideredField[1], - tmpDeviceBlock.consideredField[2], - tmpDeviceBlock.consideredField[3]); + 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); + coloredMsg(LOG_BLUE, false, " Considered Fields: %d %d %d %d", + tmpDeviceBlock.consideredField[0], + tmpDeviceBlock.consideredField[1], + tmpDeviceBlock.consideredField[2], + tmpDeviceBlock.consideredField[3]); + mbusCommAddDevice(&tmpDeviceBlock); + } else { + coloredMsg(LOG_BLUE, false, " magic does not match, ignored"); + } } } \ No newline at end of file diff --git a/cube/User/Src/mbusComm.c b/cube/User/Src/mbusComm.c index 08f2af3..32769f5 100644 --- a/cube/User/Src/mbusComm.c +++ b/cube/User/Src/mbusComm.c @@ -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) {