From d62a4ec59d0a1ae3e6b62d798a39a3dc0320116b Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Tue, 14 Jun 2022 09:40:00 +0300 Subject: [PATCH] fix bug with bad data from modbus: add 15 tries --- BTA_modbusmeteo/bta_meteo_modbus.c | 3 ++- BTA_modbusmeteo/main.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/BTA_modbusmeteo/bta_meteo_modbus.c b/BTA_modbusmeteo/bta_meteo_modbus.c index 4d17cd5..9f4bbdd 100644 --- a/BTA_modbusmeteo/bta_meteo_modbus.c +++ b/BTA_modbusmeteo/bta_meteo_modbus.c @@ -155,7 +155,8 @@ params_ans check_meteo_params(){ struct timeval timeout; fd_set set; time_t tstart = time(NULL); - while(n_bytes){ + int ctr = 15; // max 15 tries + while(ctr--) while(n_bytes){ FD_ZERO(&set); FD_SET(portfd, &set); timeout.tv_sec = 0; diff --git a/BTA_modbusmeteo/main.c b/BTA_modbusmeteo/main.c index 59c9444..0fcbf2b 100644 --- a/BTA_modbusmeteo/main.c +++ b/BTA_modbusmeteo/main.c @@ -116,6 +116,7 @@ int main(int argc, char *argv[]){ params_ans a = check_meteo_params(); if(a == ANS_LOSTCONN){ LOG("Lost connection with device, reconnect!"); + clear_flags(); return 1; } if(a == ANS_OK){