first use of libmbus
This commit is contained in:
parent
54233f4a99
commit
a928e15e74
@ -5,38 +5,21 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define MBUSFRAMEFIELD_LABELLENGTH 16
|
||||
typedef struct {
|
||||
uint8_t start1;
|
||||
uint8_t length1;
|
||||
uint8_t length2;
|
||||
uint8_t start2;
|
||||
uint8_t l;
|
||||
uint8_t c;
|
||||
uint8_t a;
|
||||
uint8_t ci;
|
||||
uint8_t *userdata;
|
||||
uint8_t chksum;
|
||||
uint8_t stop;
|
||||
} t_longframe;
|
||||
char label[MBUSFRAMEFIELD_LABELLENGTH];
|
||||
uint8_t index;
|
||||
} t_mbusFrameField;
|
||||
|
||||
typedef enum {
|
||||
MBCR_SUCCESS = 0,
|
||||
MBCR_ERROR_TIMEOUT,
|
||||
MBCR_ERROR_LOOP_FAILURE,
|
||||
MBCR_ERROR_TX_REG_UNACCESSIBLE,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__FRAME,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__USERDATA,
|
||||
MBCR_ERROR_STATE_ENGINE__START1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH2,
|
||||
MBCR_ERROR_STATE_ENGINE__START2,
|
||||
MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM,
|
||||
MBCR_ERROR_STATE_ENGINE__STOP,
|
||||
MBCR_ERROR_STATE_ENGINE__ILLEGAL_STATE,
|
||||
MBCR_ERROR_STATE_ENGINE__UNKNOWN
|
||||
} t_mbusCommResult;
|
||||
#define MBUSDEVICE_NAMELENGTH 16
|
||||
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
|
||||
typedef struct {
|
||||
char deviceName[MBUSDEVICE_NAMELENGTH];
|
||||
uint8_t address;
|
||||
t_mbusFrameField consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
|
||||
} t_mbusDevice;
|
||||
|
||||
void mbusCommRequest(uint8_t cmd, uint8_t addr);
|
||||
void mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
||||
|
||||
|
@ -25,10 +25,19 @@ void my_errorHandler() {
|
||||
}
|
||||
|
||||
void helloMeterbus(void *handle) {
|
||||
static t_mbusDevice device = {
|
||||
.deviceName = "Total Power",
|
||||
.address = 80,
|
||||
.consideredField = {
|
||||
{ .label = "energy", .index = 0 },
|
||||
{ .label = "power", .index = 17 }
|
||||
}
|
||||
};
|
||||
|
||||
static uint32_t cnt = 0;
|
||||
logMsg("*** NEW REQUEST %d ***", cnt);
|
||||
cnt++;
|
||||
mbusCommRequest(0x5b, 80);
|
||||
mbusCommRequest(&device);
|
||||
// static char msg[] = "Hello";
|
||||
// HAL_UART_Transmit_IT(&mbusUart, &msg, strlen(msg));
|
||||
|
||||
|
@ -14,6 +14,27 @@
|
||||
|
||||
#include <mbus/mbus-protocol.h>
|
||||
|
||||
|
||||
|
||||
static const uint8_t MBUS_QUERY_CMD = 0x5b;
|
||||
|
||||
typedef enum {
|
||||
MBCR_SUCCESS = 0,
|
||||
MBCR_ERROR_TIMEOUT,
|
||||
MBCR_ERROR_LOOP_FAILURE,
|
||||
MBCR_ERROR_TX_REG_UNACCESSIBLE,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__FRAME,
|
||||
MBCR_ERROR_OUT_OF_MEMORY__USERDATA,
|
||||
MBCR_ERROR_STATE_ENGINE__START1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH1,
|
||||
MBCR_ERROR_STATE_ENGINE__LENGTH2,
|
||||
MBCR_ERROR_STATE_ENGINE__START2,
|
||||
MBCR_ERROR_STATE_ENGINE__INVALID_CHKSUM,
|
||||
MBCR_ERROR_STATE_ENGINE__STOP,
|
||||
MBCR_ERROR_STATE_ENGINE__ILLEGAL_STATE,
|
||||
MBCR_ERROR_STATE_ENGINE__UNKNOWN
|
||||
} t_mbusCommResult;
|
||||
|
||||
typedef enum {
|
||||
MBCS_IDLE,
|
||||
MBCS_SEND,
|
||||
@ -36,6 +57,20 @@ typedef enum {
|
||||
MBCS_ERROR
|
||||
} e_mbusCommState;
|
||||
|
||||
typedef struct {
|
||||
uint8_t start1;
|
||||
uint8_t length1;
|
||||
uint8_t length2;
|
||||
uint8_t start2;
|
||||
uint8_t l;
|
||||
uint8_t c;
|
||||
uint8_t a;
|
||||
uint8_t ci;
|
||||
uint8_t *userdata;
|
||||
uint8_t chksum;
|
||||
uint8_t stop;
|
||||
} t_longframe;
|
||||
|
||||
typedef struct {
|
||||
e_mbusCommState state;
|
||||
uint8_t retryCnt;
|
||||
@ -47,8 +82,10 @@ typedef struct {
|
||||
bool receiving;
|
||||
t_mbusCommResult result;
|
||||
t_longframe frame;
|
||||
t_mbusDevice *device;
|
||||
} t_mbusCommHandle;
|
||||
|
||||
|
||||
static t_mbusCommHandle mbusCommHandle = { .state = MBCS_IDLE, .retryCnt = 0, .cmd = 0, .addr = 0, .receiveCnt = 0, .receivedOctet = 0, .receiving = false };
|
||||
|
||||
|
||||
@ -355,12 +392,13 @@ void mbusCommRxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
}
|
||||
}
|
||||
|
||||
void mbusCommRequest(uint8_t cmd, uint8_t addr) {
|
||||
void mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
if (mbusCommHandle.state == MBCS_IDLE) {
|
||||
mbusCommHandle.state = MBCS_SEND;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
mbusCommHandle.cmd = cmd;
|
||||
mbusCommHandle.addr = addr;
|
||||
mbusCommHandle.cmd = MBUS_QUERY_CMD;
|
||||
mbusCommHandle.addr = mbusDevice->address;
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
} else {
|
||||
// busy
|
||||
|
Loading…
x
Reference in New Issue
Block a user