fix logger (lost first two chars) and setting meterbus uart (8bit data plus parity, so 9bit incl. parity)
This commit is contained in:
parent
6ccf85abdb
commit
877dd0fca3
@ -51,7 +51,7 @@ void MX_UART5_Init(void)
|
||||
|
||||
huart5.Instance = UART5;
|
||||
huart5.Init.BaudRate = 2400;
|
||||
huart5.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart5.Init.WordLength = UART_WORDLENGTH_9B;
|
||||
huart5.Init.StopBits = UART_STOPBITS_1;
|
||||
huart5.Init.Parity = UART_PARITY_EVEN;
|
||||
huart5.Init.Mode = UART_MODE_TX_RX;
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Processed by ../tools/insertMyCode.sh
|
||||
# Processed by ../tools/insertMyCode.sh
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 27 22:02:19 CET 2020]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
@ -36,36 +36,36 @@ BUILD_DIR = build
|
||||
# source
|
||||
######################################
|
||||
# C sources
|
||||
C_SOURCES = \
|
||||
User/Src/ringbuffer.c User/Src/logger.c User/Src/mbusComm.c User/Src/led.c User/Src/loopCtrl.c User/Src/main2.c hottislib/PontCoopScheduler.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
Core/Src/spi.c \
|
||||
Core/Src/usart.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
C_SOURCES = \
|
||||
User/Src/led.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/ringbuffer.c hottislib/PontCoopScheduler.c \
|
||||
Core/Src/main.c \
|
||||
Core/Src/gpio.c \
|
||||
Core/Src/adc.c \
|
||||
Core/Src/spi.c \
|
||||
Core/Src/usart.c \
|
||||
Core/Src/stm32f1xx_it.c \
|
||||
Core/Src/stm32f1xx_hal_msp.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
|
||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||
Core/Src/system_stm32f1xx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
ASM_SOURCES = \
|
||||
startup_stm32f103xe.s
|
||||
|
||||
|
||||
@ -109,8 +109,8 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
AS_DEFS =
|
||||
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32F103xE
|
||||
|
||||
|
||||
@ -118,14 +118,14 @@ C_DEFS = \
|
||||
AS_INCLUDES =
|
||||
|
||||
# C includes
|
||||
C_INCLUDES = \
|
||||
-Ihottislib \
|
||||
-IUser/Inc \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
C_INCLUDES = \
|
||||
-Ihottislib \
|
||||
-IUser/Inc \
|
||||
-ICore/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc \
|
||||
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
|
||||
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
|
||||
-IDrivers/CMSIS/Include \
|
||||
-IDrivers/CMSIS/Include
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Tue Oct 27 22:02:19 CET 2020]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.10.0-B14] date: [Thu Oct 29 22:51:14 CET 2020]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
@ -66,11 +66,11 @@ int logMsg(const char *format, ...) {
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, format);
|
||||
int vcnt = vsnprintf(msgBuffer-2, MSGBUFFER_SIZE, format, vl);
|
||||
int vcnt = vsnprintf(msgBuffer, MSGBUFFER_SIZE-2, format, vl);
|
||||
va_end(vl);
|
||||
|
||||
if (vcnt < MSGBUFFER_SIZE) {
|
||||
strcat(msgBuffer, "\n\r");
|
||||
strcat(msgBuffer, "\r\n");
|
||||
|
||||
if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) {
|
||||
#ifndef TEST
|
||||
|
@ -25,6 +25,9 @@ void my_errorHandler() {
|
||||
|
||||
void helloMeterbus(void *handle) {
|
||||
mbusCommRequest(0x5b, 80);
|
||||
// static char msg[] = "Hello";
|
||||
// HAL_UART_Transmit_IT(&mbusUart, &msg, strlen(msg));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +35,7 @@ void my_setup_2() {
|
||||
led(RED, OFF);
|
||||
led(GREEN, ON);
|
||||
|
||||
schAdd(helloMeterbus, NULL, 0, 10000);
|
||||
schAdd(helloMeterbus, NULL, 0, 2000);
|
||||
}
|
||||
|
||||
void my_loop() {
|
||||
|
@ -30,11 +30,11 @@ static void handleRequestEngine(void *handle) {
|
||||
|
||||
switch (localMbusCommHandle->state) {
|
||||
case IDLE:
|
||||
logMsg("mc state IDLE\n");
|
||||
logMsg("hre state IDLE");
|
||||
break;
|
||||
|
||||
case SEND:
|
||||
logMsg("mc state SEND\n");
|
||||
logMsg("hre state SEND");
|
||||
localMbusCommHandle->sendBuf[0] = 0x10;
|
||||
localMbusCommHandle->sendBuf[1] = localMbusCommHandle->cmd;
|
||||
localMbusCommHandle->sendBuf[2] = localMbusCommHandle->addr;
|
||||
@ -44,26 +44,28 @@ static void handleRequestEngine(void *handle) {
|
||||
// no break !!
|
||||
|
||||
case SEND_CONT:
|
||||
logMsg("mc state SEND_CONT\n");
|
||||
logMsg("hre state SEND_CONT");
|
||||
led(RED, OFF);
|
||||
if (! loopActive) {
|
||||
logMsg("hre enabling loop, try %d", localMbusCommHandle->retryCnt);
|
||||
localMbusCommHandle->retryCnt++;
|
||||
loopEnable();
|
||||
schAdd(handleRequestEngine, handle, 10, 0); // give 10ms to settled the loop
|
||||
} else {
|
||||
// write(fd, sendBuf, 5);
|
||||
localMbusCommHandle->retryCnt = 0;
|
||||
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
|
||||
localMbusCommHandle->state = SENDING;
|
||||
schAdd(handleRequestEngine, handle, 1, 0); // ask me again in 1ms in the next state ...
|
||||
schAdd(handleRequestEngine, handle, 5, 0); // ask me again in 1ms in the next state ...
|
||||
}
|
||||
break;
|
||||
|
||||
case SENDING:
|
||||
logMsg("mc state SENDING\n");
|
||||
logMsg("hre state SENDING");
|
||||
if (HAL_UART_GetState(&mbusUart) == HAL_UART_STATE_READY) { // ... whether I'm done
|
||||
localMbusCommHandle->state = IDLE;
|
||||
} else {
|
||||
schAdd(handleRequestEngine, handle, 1, 0); // not yet done, ask me again in 1ms
|
||||
schAdd(handleRequestEngine, handle, 5, 0); // not yet done, ask me again in 1ms
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -200,9 +200,10 @@ SPI3.VirtualType=VM_MASTER
|
||||
UART4.IPParameters=VirtualMode
|
||||
UART4.VirtualMode=Asynchronous
|
||||
UART5.BaudRate=2400
|
||||
UART5.IPParameters=VirtualMode,BaudRate,Parity
|
||||
UART5.IPParameters=VirtualMode,BaudRate,Parity,WordLength
|
||||
UART5.Parity=PARITY_EVEN
|
||||
UART5.VirtualMode=Asynchronous
|
||||
UART5.WordLength=WORDLENGTH_9B
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
board=custom
|
||||
|
40
tests/test.c
40
tests/test.c
@ -834,8 +834,9 @@ void testLogger0() {
|
||||
#ifdef DEBUG
|
||||
printf("\nLog a message\n");
|
||||
#endif
|
||||
char goldValue1[] = "Wolfgang\n";
|
||||
logMsg(goldValue1);
|
||||
char msg[] = "Wolfgang";
|
||||
char goldValue[] = "Wolfgang\r\n";
|
||||
logMsg(msg);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("\nRead all chars from logging\n");
|
||||
@ -850,7 +851,8 @@ void testLogger0() {
|
||||
buffer[i] = (uint8_t) c;
|
||||
i++;
|
||||
}
|
||||
CU_ASSERT(strcmp(goldValue1, buffer) == 0);
|
||||
// printf(buffer);
|
||||
CU_ASSERT(strcmp(goldValue, buffer) == 0);
|
||||
}
|
||||
|
||||
void testLogger1() {
|
||||
@ -859,18 +861,18 @@ void testLogger1() {
|
||||
#endif
|
||||
char goldValueFull[128];
|
||||
memset(goldValueFull, 0, 128);
|
||||
char goldValue1[] = "Wolfgang\n"; // 9
|
||||
char goldValue1[] = "Wolfgang"; // 9
|
||||
strcat(goldValueFull, goldValue1);
|
||||
strcat(goldValueFull, "\r\n");
|
||||
logMsg(goldValue1);
|
||||
char goldValue2[] = "Andreas\n"; // +8 = 17
|
||||
char goldValue2[] = "Andreas"; // +8 = 17
|
||||
strcat(goldValueFull, goldValue2);
|
||||
strcat(goldValueFull, "\r\n");
|
||||
logMsg(goldValue2);
|
||||
char goldValue3[] = "Frank\n"; // +6 = 23
|
||||
char goldValue3[] = "Frank"; // +6 = 23
|
||||
strcat(goldValueFull, goldValue3);
|
||||
strcat(goldValueFull, "\r\n");
|
||||
logMsg(goldValue3);
|
||||
char goldValue4[] = "Thomas\n"; // +7 = 30
|
||||
strcat(goldValueFull, goldValue4);
|
||||
logMsg(goldValue4);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("\nRead all chars from logging\n");
|
||||
@ -898,27 +900,33 @@ void testLogger2() {
|
||||
memset(goldValueFullNotOk, 0, 128);
|
||||
char goldValueFullOk[128];
|
||||
memset(goldValueFullOk, 0, 128);
|
||||
char goldValue1[] = "Wolfgang\n"; // 9
|
||||
char goldValue1[] = "Wolfgang"; // 9
|
||||
strcat(goldValueFullNotOk, goldValue1);
|
||||
strcat(goldValueFullOk, goldValue1);
|
||||
strcat(goldValueFullNotOk, "\r\n");
|
||||
strcat(goldValueFullOk, "\r\n");
|
||||
int r = logMsg(goldValue1);
|
||||
CU_ASSERT(r == 0);
|
||||
char goldValue2[] = "Andreas\n"; // +8 = 17
|
||||
char goldValue2[] = "Andreas"; // +8 = 17
|
||||
strcat(goldValueFullNotOk, goldValue2);
|
||||
strcat(goldValueFullOk, goldValue2);
|
||||
strcat(goldValueFullNotOk, "\r\n");
|
||||
strcat(goldValueFullOk, "\r\n");
|
||||
r = logMsg(goldValue2);
|
||||
CU_ASSERT(r == 0);
|
||||
char goldValue3[] = "Frank\n"; // +6 = 23
|
||||
char goldValue3[] = "Frank"; // +6 = 23
|
||||
strcat(goldValueFullNotOk, goldValue3);
|
||||
strcat(goldValueFullOk, goldValue3);
|
||||
strcat(goldValueFullNotOk, "\r\n");
|
||||
strcat(goldValueFullOk, "\r\n");
|
||||
r = logMsg(goldValue3);
|
||||
CU_ASSERT(r == 0);
|
||||
char goldValue4[] = "Thomas\n"; // +7 = 30
|
||||
char goldValue4[] = "Thomas"; // +7 = 30
|
||||
strcat(goldValueFullNotOk, goldValue4);
|
||||
strcat(goldValueFullOk, goldValue4);
|
||||
strcat(goldValueFullNotOk, "\r\n");
|
||||
r = logMsg(goldValue4);
|
||||
CU_ASSERT(r == 0);
|
||||
char goldValue5[] = "Barbara\n"; // +8 = 38, too much
|
||||
CU_ASSERT(r == -1);
|
||||
char goldValue5[] = "Barbara"; // +8 = 38, too much
|
||||
strcat(goldValueFullNotOk, goldValue5);
|
||||
r = logMsg(goldValue5);
|
||||
CU_ASSERT(r == -1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user