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