first use of libmbus
This commit is contained in:
parent
43fe49f90d
commit
b1e2277ef5
@ -11,7 +11,7 @@ typedef struct {
|
||||
uint8_t index;
|
||||
} t_mbusFrameField;
|
||||
|
||||
#define MBUSDEVICE_NAMELENGTH 16
|
||||
#define MBUSDEVICE_NAMELENGTH 24
|
||||
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
|
||||
typedef struct {
|
||||
char deviceName[MBUSDEVICE_NAMELENGTH];
|
||||
@ -19,7 +19,13 @@ typedef struct {
|
||||
t_mbusFrameField consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
} t_mbusDevice;
|
||||
|
||||
void mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||
|
||||
typedef enum {
|
||||
MBCRR_TRIGGERED = 0,
|
||||
MBCRR_BUSY = 1
|
||||
} e_mbusCommRequestResult;
|
||||
|
||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
||||
|
||||
|
@ -24,8 +24,10 @@ void my_errorHandler() {
|
||||
show(LED_RED, ON);
|
||||
}
|
||||
|
||||
void helloMeterbus(void *handle) {
|
||||
static t_mbusDevice device = {
|
||||
|
||||
static uint8_t numOfDevices = 8;
|
||||
static t_mbusDevice devices[] = {
|
||||
{
|
||||
.deviceName = "Total Power",
|
||||
.address = 80,
|
||||
.consideredField = {
|
||||
@ -34,15 +36,93 @@ void helloMeterbus(void *handle) {
|
||||
{ .label = "", .index = 0 },
|
||||
{ .label = "", .index = 0 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Computer Power",
|
||||
.address = 85,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Dryer Power",
|
||||
.address = 81,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Laundry Power",
|
||||
.address = 82,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Dishwasher Power",
|
||||
.address = 83,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Light Power",
|
||||
.address = 84,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Freezer Power",
|
||||
.address = 86,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
.deviceName = "Fridge Power",
|
||||
.address = 87,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 4 },
|
||||
{ .label = "voltage", .index = 2 },
|
||||
{ .label = "current", .index = 3 }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static uint32_t cnt = 0;
|
||||
logMsg("*** NEW REQUEST %d ***", cnt);
|
||||
cnt++;
|
||||
mbusCommRequest(&device);
|
||||
// static char msg[] = "Hello";
|
||||
// HAL_UART_Transmit_IT(&mbusUart, &msg, strlen(msg));
|
||||
|
||||
void triggerMBusRequest(void *handle) {
|
||||
static uint8_t deviceIndex = 0;
|
||||
static uint32_t cnt = 0;
|
||||
|
||||
logMsg("");
|
||||
logMsg("*** NEW REQUEST %s %d %d ***", devices[deviceIndex].deviceName, deviceIndex, cnt);
|
||||
mbusCommRequest(&(devices[deviceIndex]));
|
||||
|
||||
cnt++;
|
||||
deviceIndex++;
|
||||
if (deviceIndex >= numOfDevices) {
|
||||
deviceIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +133,7 @@ void my_setup_2() {
|
||||
frontendInit();
|
||||
frontendSetThreshold(240);
|
||||
|
||||
schAdd(helloMeterbus, NULL, 0, 10000);
|
||||
schAdd(triggerMBusRequest, NULL, 0, 10000);
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
|
@ -33,7 +33,7 @@ typedef enum {
|
||||
MBCR_ERROR_STATE_ENGINE__STOP,
|
||||
MBCR_ERROR_STATE_ENGINE__ILLEGAL_STATE,
|
||||
MBCR_ERROR_STATE_ENGINE__UNKNOWN
|
||||
} t_mbusCommResult;
|
||||
} e_mbusCommResult;
|
||||
|
||||
typedef enum {
|
||||
MBCS_IDLE,
|
||||
@ -80,7 +80,7 @@ typedef struct {
|
||||
uint8_t receiveCnt;
|
||||
uint8_t receivedOctet;
|
||||
bool receiving;
|
||||
t_mbusCommResult result;
|
||||
e_mbusCommResult result;
|
||||
t_longframe frame;
|
||||
t_mbusDevice *device;
|
||||
} t_mbusCommHandle;
|
||||
@ -389,7 +389,9 @@ void mbusCommRxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
}
|
||||
}
|
||||
|
||||
void mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
e_mbusCommRequestResult res = MBCRR_BUSY;
|
||||
|
||||
if (mbusCommHandle.state == MBCS_IDLE) {
|
||||
mbusCommHandle.state = MBCS_SEND;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
@ -397,8 +399,9 @@ void mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
mbusCommHandle.addr = mbusDevice->address;
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
} else {
|
||||
// busy
|
||||
}
|
||||
res = MBCRR_TRIGGERED;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user