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:
parent
a9690e0862
commit
ac487727df
1 changed files with 3 additions and 6 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue