first use of libmbus
This commit is contained in:
parent
6ddc415a45
commit
98b6e37737
@ -3,7 +3,7 @@
|
||||
|
||||
#include <main.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MBUSFRAMEFIELD_LABELLENGTH 16
|
||||
typedef struct {
|
||||
@ -19,6 +19,9 @@ typedef struct {
|
||||
t_mbusFrameField consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
uint32_t requests;
|
||||
uint32_t failures;
|
||||
int32_t period;
|
||||
int32_t delay;
|
||||
bool waiting;
|
||||
} t_mbusDevice;
|
||||
|
||||
|
||||
|
@ -37,7 +37,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "", .index = 0 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Computer Power",
|
||||
@ -49,7 +52,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Dryer Power",
|
||||
@ -61,7 +67,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Laundry Power",
|
||||
@ -73,7 +82,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Dishwasher Power",
|
||||
@ -85,7 +97,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Light Power",
|
||||
@ -97,7 +112,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 15,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Freezer Power",
|
||||
@ -109,7 +127,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
},
|
||||
{
|
||||
.deviceName = "Fridge Power",
|
||||
@ -121,7 +142,10 @@ static t_mbusDevice devices[] = {
|
||||
{ .label = "current", .index = 3 }
|
||||
},
|
||||
.requests = 0,
|
||||
.failures = 0
|
||||
.failures = 0,
|
||||
.period = 60,
|
||||
.delay = 0,
|
||||
.waiting = false
|
||||
}
|
||||
};
|
||||
|
||||
@ -129,15 +153,29 @@ static t_mbusDevice devices[] = {
|
||||
void triggerMBusRequest(void *handle) {
|
||||
static uint8_t deviceIndex = 0;
|
||||
|
||||
e_mbusCommRequestResult r = mbusCommRequest(&(devices[deviceIndex]));
|
||||
if (r == MBCRR_TRIGGERED) {
|
||||
deviceIndex++;
|
||||
if (deviceIndex >= numOfDevices) {
|
||||
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++) {
|
||||
if (devices[i].delay <= 0) {
|
||||
devices[i].delay = devices[i].period;
|
||||
devices[i].waiting = true;
|
||||
logMsg("*** Scheduled: %s", devices[i].deviceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void my_setup_2() {
|
||||
show(LED_RED, OFF);
|
||||
@ -146,6 +184,7 @@ void my_setup_2() {
|
||||
frontendInit();
|
||||
frontendSetThreshold(240);
|
||||
|
||||
schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
||||
schAdd(triggerMBusRequest, NULL, 0, 1000);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user