start refactoring

This commit is contained in:
2020-11-23 19:30:57 +01:00
parent b8513b2112
commit 491a60f515
3 changed files with 14 additions and 4 deletions

View File

@ -16,6 +16,8 @@
#include <mbusParserExt.h>
#include <mqttComm.h>
#include <oled.h>
#include <ringbuffer.h>
#include <mbus/mbus-protocol.h>
@ -87,6 +89,7 @@ typedef struct {
uint8_t receiveCnt;
uint8_t receivedOctet;
bool receiving;
ringbuffer_t *receiveBuffer;
e_mbusCommResult result;
t_longframe frame;
t_mbusDevice *device;
@ -247,10 +250,9 @@ static void parseAndPrintFrame(t_mbusCommHandle *localMbusCommHandle) {
static void handleRequestEngine(void *handle);
static void timeoutHandler(void *handle) {
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
// coloredMsg(LOG_RED, true, "mbc th [%d] timeout", localMbusCommHandle->requestId);
coloredMsg(LOG_RED, true, "mbc th [%d] timeout", localMbusCommHandle->requestId);
localMbusCommHandle->state = MBCS_TIMEOUT;
localMbusCommHandle->receiving = false;
handleRequestEngine(handle);
}
static void receiveNext(t_mbusCommHandle *localMbusCommHandle) {
@ -278,8 +280,8 @@ void mbusCommErrorCallback(UART_HandleTypeDef *huart) {
}
}
static void handleRequestEngine(void *handle) {
t_mbusCommHandle *localMbusCommHandle = (t_mbusCommHandle*) handle;
void mbusCommExec() {
t_mbusCommHandle *localMbusCommHandle = &mbusCommHandle;
static uint8_t userdataIdx = 0;
static uint8_t calculatedChksum = 0;
@ -702,5 +704,10 @@ static void mbusCommScheduler(void *handle) {
void mbusCommInit() {
coloredMsg(LOG_GREEN, true, "mbc mci initializing Meterbus communication");
ringbufferInit(&(mbusCommHandle.receiveBuffer), 256);
coloredMsg(LOG_GREEN, true, "mbc mci ringbuffer created");
HAL_StatusTypeDef recvRet = HAL_UART_Receive_IT(&mbusUart, &(mbusCommHandle.receivedOctet), 1);
coloredMsg(LOG_GREEN, true, "mbc mci enable receiver, retCode: 0x%02x", recvRet);
schAdd(mbusCommScheduler, NULL, 0, 1000);
}