start refactoring

This commit is contained in:
Wolfgang Hottgenroth 2020-11-23 19:30:57 +01:00
parent b8513b2112
commit 491a60f515
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
3 changed files with 14 additions and 4 deletions

View File

@ -33,6 +33,7 @@ typedef struct {
// e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
void mbusCommInit();
void mbusCommExec();
void mbusCommEnable(bool enable);
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);

View File

@ -71,6 +71,8 @@ void my_loop() {
#ifndef LOGGER_OUTPUT_BY_INTERRUPT
logExec();
#endif //LOGGER_OUTPUT_BY_INTERRUPT
mbusCommExec();
}
void SYSTICK_Callback() {

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);
}