fixed bta_meteo_modbus?

This commit is contained in:
Edward Emelianov 2022-07-04 14:48:59 +03:00
parent d62a4ec59d
commit a00200af3c
2 changed files with 5 additions and 3 deletions

View File

@ -155,8 +155,8 @@ params_ans check_meteo_params(){
struct timeval timeout;
fd_set set;
time_t tstart = time(NULL);
int ctr = 15; // max 15 tries
while(ctr--) while(n_bytes){
int ctr = 50; // max 50 tries
while(ctr--){
FD_ZERO(&set);
FD_SET(portfd, &set);
timeout.tv_sec = 0;
@ -174,7 +174,8 @@ params_ans check_meteo_params(){
size += n_bytes;
if(n_bytes) continue;
}
if(size > 0 && (res == 0 || size >= MODBUS_MAX_PACKET_SIZE || n_bytes == 0)) {
// read all or end of packet
if(size > 0 && res == 0 && (size == REQ_LEN || size == ANS_LEN)){
if(crc_check(buffer, size)){
if(size == REQ_LEN){
lastpar = buffer[2] << 8 | buffer[3];

View File

@ -114,6 +114,7 @@ int main(int argc, char *argv[]){
return 1;
}
params_ans a = check_meteo_params();
DBG("chk_meteo: %d", a);
if(a == ANS_LOSTCONN){
LOG("Lost connection with device, reconnect!");
clear_flags();