first use of libmbus

This commit is contained in:
2020-11-03 14:00:54 +01:00
parent 54233f4a99
commit a928e15e74
3 changed files with 63 additions and 33 deletions

View File

@@ -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