modbus: reset buffer after reception

Reset buffer after reception, even if an error occurs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-02-10 15:00:44 +01:00 committed by Carles Cufí
commit ac487727df

View file

@ -182,9 +182,6 @@ static int mb_rx_ascii_frame(struct mb_rtu_context *ctx)
calc_lrc = mb_ascii_get_lrc(&ctx->uart_buf[1],
(ctx->uart_buf_ctr - 5) / 2);
ctx->uart_buf_ctr = 0;
ctx->uart_buf_ptr = &ctx->uart_buf[0];
if (calc_lrc != frame_lrc) {
LOG_ERR("Calculated LRC does not match received LRC");
return -EIO;
@ -322,9 +319,6 @@ static int mb_rx_rtu_frame(struct mb_rtu_context *ctx)
calc_crc = mb_rtu_crc16(&ctx->uart_buf[0],
ctx->uart_buf_ctr - sizeof(ctx->rx_frame.crc));
ctx->uart_buf_ctr = 0;
ctx->uart_buf_ptr = &ctx->uart_buf[0];
if (ctx->rx_frame.crc != calc_crc) {
LOG_WRN("Calculated CRC does not match received CRC");
return -EIO;
@ -473,6 +467,9 @@ static void mb_rx_handler(struct k_work *item)
ctx->rx_frame_err = mb_rx_rtu_frame(ctx);
}
ctx->uart_buf_ctr = 0;
ctx->uart_buf_ptr = &ctx->uart_buf[0];
if (ctx->client == true) {
k_sem_give(&ctx->client_wait_sem);
} else if (IS_ENABLED(CONFIG_MODBUS_RTU_SERVER)) {