From d8d71642ad7b1209e2aa8d3fb227d37051076248 Mon Sep 17 00:00:00 2001 From: Reinhard Russinger Date: Fri, 22 Jun 2018 10:41:45 +0200 Subject: [PATCH] GfA empty input queue on CRC error --- .../003-GfA-empty-input-queue-on-CRC-error.patch | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch diff --git a/package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch b/package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch new file mode 100644 index 0000000..79a7ae3 --- /dev/null +++ b/package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch @@ -0,0 +1,39 @@ +diff '--exclude=.libs*' '--exclude=*.la' '--exclude=*.lo' '--exclude=Makefile*' -Naurp libmodbus-3.0.6/src/modbus-rtu.c b/src/modbus-rtu.c +--- libmodbus-3.0.6/src/modbus-rtu.c 2018-06-22 10:34:55.987233891 +0200 ++++ b/src/modbus-rtu.c 2018-06-18 19:47:12.682614777 +0200 +@@ -323,6 +323,35 @@ int _modbus_rtu_check_integrity(modbus_t + if (crc_calculated == crc_received) { + return msg_length; + } else { ++ modbus_rtu_t *ctx_rtu = ctx->backend_data; ++ ++ if(ctx_rtu->echohw) {/* on active echomode empty receiver on crc error */ ++ int rc; ++ fd_set rfds; ++ struct timeval tv; ++ ++ /* Add a file descriptor to the set */ ++ FD_ZERO(&rfds); ++ FD_SET(ctx->s, &rfds); ++ ++ if (ctx->debug) { ++ fprintf(stderr, "ERROR CRC received on ECHOHW empty input tv.tv_sec=%d tv.tv_usec=%d\n", ++ (int)ctx->response_timeout.tv_sec, ++ (int)ctx->response_timeout.tv_usec); ++ fflush(stderr); ++ } ++ ++ do { ++ unsigned char cc[256]; /* dummy buffer für cleaning input */ ++ ++ tv.tv_sec = ctx->response_timeout.tv_sec; ++ tv.tv_usec = ctx->response_timeout.tv_usec; ++ ++ rc = ctx->backend->select(ctx, &rfds, &tv, sizeof(cc)); ++ if(rc > 0) ctx->backend->recv(ctx, msg + msg_length, rc); ++ } while(rc > 0); /* read until transfer empty */ ++ } ++ + if (ctx->debug) { + fprintf(stderr, "ERROR CRC received %0X != CRC calculated %0X\n", + crc_received, crc_calculated); -- 2.7.4