logging
This commit is contained in:
parent
8e5ece822c
commit
e3c16ef712
@ -6,6 +6,8 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Disabling this option is preferred. However, when debugging system hangs
|
||||||
|
// this option needs to be enabled.
|
||||||
// #define LOGGER_OUTPUT_BY_INTERRUPT
|
// #define LOGGER_OUTPUT_BY_INTERRUPT
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -35,7 +35,8 @@ typedef struct {
|
|||||||
uint32_t errorCnt;
|
uint32_t errorCnt;
|
||||||
} t_mbusCommStats;
|
} t_mbusCommStats;
|
||||||
|
|
||||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
|
// e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||||
|
void mbusCommInit();
|
||||||
void mbusCommEnable(bool enable);
|
void mbusCommEnable(bool enable);
|
||||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
||||||
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
||||||
|
@ -32,159 +32,6 @@ void my_errorHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint8_t numOfDevices = 8;
|
|
||||||
static t_mbusDevice devices[] = {
|
|
||||||
{
|
|
||||||
.deviceName = "Total Power",
|
|
||||||
.address = 80,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 17 },
|
|
||||||
{ .label = "", .index = 0 },
|
|
||||||
{ .label = "", .index = 0 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Computer Power",
|
|
||||||
.address = 85,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Dryer Power",
|
|
||||||
.address = 81,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Laundry Power",
|
|
||||||
.address = 82,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Dishwasher Power",
|
|
||||||
.address = 83,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Light Power",
|
|
||||||
.address = 84,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 15,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Freezer Power",
|
|
||||||
.address = 86,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.deviceName = "Fridge Power",
|
|
||||||
.address = 87,
|
|
||||||
.consideredField = {
|
|
||||||
{ .label = "energy", .index = 0 },
|
|
||||||
{ .label = "power", .index = 4 },
|
|
||||||
{ .label = "voltage", .index = 2 },
|
|
||||||
{ .label = "current", .index = 3 }
|
|
||||||
},
|
|
||||||
.requests = 0,
|
|
||||||
.failures = 0,
|
|
||||||
.period = 60,
|
|
||||||
.delay = 0,
|
|
||||||
.waiting = false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void triggerMBusRequest(void *handle) {
|
|
||||||
static uint8_t deviceIndex = 0;
|
|
||||||
|
|
||||||
if (devices[deviceIndex].waiting) {
|
|
||||||
e_mbusCommRequestResult r = mbusCommRequest(&(devices[deviceIndex]));
|
|
||||||
if (r == MBCRR_TRIGGERED) {
|
|
||||||
devices[deviceIndex].waiting = false;
|
|
||||||
deviceIndex++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
deviceIndex++;
|
|
||||||
}
|
|
||||||
if (deviceIndex >= numOfDevices) {
|
|
||||||
deviceIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void scheduleMBusRequest(void *handle) {
|
|
||||||
for (uint8_t i = 0; i < numOfDevices; i++) {
|
|
||||||
devices[i].delay -= 1;
|
|
||||||
if (devices[i].delay <= 0) {
|
|
||||||
devices[i].delay = devices[i].period;
|
|
||||||
devices[i].waiting = true;
|
|
||||||
coloredMsg(LOG_GREEN, false, "*** Scheduled: %s", devices[i].deviceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void my_setup_2() {
|
void my_setup_2() {
|
||||||
show(LED_RED, OFF);
|
show(LED_RED, OFF);
|
||||||
show(LED_GREEN, BLINK);
|
show(LED_GREEN, BLINK);
|
||||||
@ -200,8 +47,7 @@ void my_setup_2() {
|
|||||||
frontendInit();
|
frontendInit();
|
||||||
frontendSetThreshold(240);
|
frontendSetThreshold(240);
|
||||||
|
|
||||||
schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
mbusCommInit();
|
||||||
schAdd(triggerMBusRequest, NULL, 0, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <show.h>
|
#include <show.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
#include <frontend.h>
|
#include <frontend.h>
|
||||||
|
#include <wizHelper.h>
|
||||||
|
|
||||||
#include <mbus/mbus-protocol.h>
|
#include <mbus/mbus-protocol.h>
|
||||||
|
|
||||||
@ -424,7 +425,7 @@ void mbusCommEnable(bool enable) {
|
|||||||
mbusCommEnabled = enable;
|
mbusCommEnabled = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
static e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||||
e_mbusCommRequestResult res = MBCRR_BUSY;
|
e_mbusCommRequestResult res = MBCRR_BUSY;
|
||||||
|
|
||||||
if (mbusCommEnabled) {
|
if (mbusCommEnabled) {
|
||||||
@ -457,3 +458,195 @@ e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t numOfDevices = 8;
|
||||||
|
static t_mbusDevice devices[] = {
|
||||||
|
{
|
||||||
|
.deviceName = "Total Power",
|
||||||
|
.address = 80,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 17 },
|
||||||
|
{ .label = "", .index = 0 },
|
||||||
|
{ .label = "", .index = 0 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Computer Power",
|
||||||
|
.address = 85,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Dryer Power",
|
||||||
|
.address = 81,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Laundry Power",
|
||||||
|
.address = 82,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Dishwasher Power",
|
||||||
|
.address = 83,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Light Power",
|
||||||
|
.address = 84,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 15,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Freezer Power",
|
||||||
|
.address = 86,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.deviceName = "Fridge Power",
|
||||||
|
.address = 87,
|
||||||
|
.consideredField = {
|
||||||
|
{ .label = "energy", .index = 0 },
|
||||||
|
{ .label = "power", .index = 4 },
|
||||||
|
{ .label = "voltage", .index = 2 },
|
||||||
|
{ .label = "current", .index = 3 }
|
||||||
|
},
|
||||||
|
.requests = 0,
|
||||||
|
.failures = 0,
|
||||||
|
.period = 60,
|
||||||
|
.delay = 0,
|
||||||
|
.waiting = false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void triggerMBusRequest(void *handle) {
|
||||||
|
static uint8_t deviceIndex = 0;
|
||||||
|
|
||||||
|
if (devices[deviceIndex].waiting) {
|
||||||
|
e_mbusCommRequestResult r = mbusCommRequest(&(devices[deviceIndex]));
|
||||||
|
if (r == MBCRR_TRIGGERED) {
|
||||||
|
devices[deviceIndex].waiting = false;
|
||||||
|
deviceIndex++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deviceIndex++;
|
||||||
|
}
|
||||||
|
if (deviceIndex >= numOfDevices) {
|
||||||
|
deviceIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void mbusCommScheduler(void *handle) {
|
||||||
|
static uint8_t state = 0;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
if (isNetworkAvailable()) {
|
||||||
|
coloredMsg(LOG_GREEN, true, "mbc mcs activate scheduler by network");
|
||||||
|
schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
if (! isNetworkAvailable()) {
|
||||||
|
coloredMsg(LOG_GREEN, true, "mbc mcs deactivate scheduler by network");
|
||||||
|
schDel(triggerMBusRequest, NULL);
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
|
if (! mbusCommEnabled) {
|
||||||
|
coloredMsg(LOG_GREEN, true, "mbc mcs deactivate scheduler by request");
|
||||||
|
schDel(triggerMBusRequest, NULL);
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
|
for (uint8_t i = 0; i < numOfDevices; i++) {
|
||||||
|
devices[i].delay -= 1;
|
||||||
|
if (devices[i].delay <= 0) {
|
||||||
|
devices[i].delay = devices[i].period;
|
||||||
|
devices[i].waiting = true;
|
||||||
|
coloredMsg(LOG_GREEN, false, "*** Scheduled: %s", devices[i].deviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (mbusCommEnabled) {
|
||||||
|
coloredMsg(LOG_GREEN, true, "mbc mcs activate scheduler by request");
|
||||||
|
schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mbusCommInit() {
|
||||||
|
coloredMsg(LOG_GREEN, true, "mbc mci initializing Meterbus communication");
|
||||||
|
schAdd(mbusCommScheduler, NULL, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user