0005-GfA-empty-input-queue-on-CRC-error.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From d8d71642ad7b1209e2aa8d3fb227d37051076248 Mon Sep 17 00:00:00 2001
  2. From: Reinhard Russinger <reinhard@russinger.at>
  3. Date: Fri, 22 Jun 2018 10:41:45 +0200
  4. Subject: [PATCH] GfA empty input queue on CRC error
  5. ---
  6. .../003-GfA-empty-input-queue-on-CRC-error.patch | 39 ++++++++++++++++++++++
  7. 1 file changed, 39 insertions(+)
  8. create mode 100644 package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch
  9. 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
  10. new file mode 100644
  11. index 0000000..79a7ae3
  12. --- /dev/null
  13. +++ b/package/libmodbus/003-GfA-empty-input-queue-on-CRC-error.patch
  14. @@ -0,0 +1,39 @@
  15. +diff '--exclude=.libs*' '--exclude=*.la' '--exclude=*.lo' '--exclude=Makefile*' -Naurp libmodbus-3.0.6/src/modbus-rtu.c b/src/modbus-rtu.c
  16. +--- libmodbus-3.0.6/src/modbus-rtu.c 2018-06-22 10:34:55.987233891 +0200
  17. ++++ b/src/modbus-rtu.c 2018-06-18 19:47:12.682614777 +0200
  18. +@@ -323,6 +323,35 @@ int _modbus_rtu_check_integrity(modbus_t
  19. + if (crc_calculated == crc_received) {
  20. + return msg_length;
  21. + } else {
  22. ++ modbus_rtu_t *ctx_rtu = ctx->backend_data;
  23. ++
  24. ++ if(ctx_rtu->echohw) {/* on active echomode empty receiver on crc error */
  25. ++ int rc;
  26. ++ fd_set rfds;
  27. ++ struct timeval tv;
  28. ++
  29. ++ /* Add a file descriptor to the set */
  30. ++ FD_ZERO(&rfds);
  31. ++ FD_SET(ctx->s, &rfds);
  32. ++
  33. ++ if (ctx->debug) {
  34. ++ fprintf(stderr, "ERROR CRC received on ECHOHW empty input tv.tv_sec=%d tv.tv_usec=%d\n",
  35. ++ (int)ctx->response_timeout.tv_sec,
  36. ++ (int)ctx->response_timeout.tv_usec);
  37. ++ fflush(stderr);
  38. ++ }
  39. ++
  40. ++ do {
  41. ++ unsigned char cc[256]; /* dummy buffer für cleaning input */
  42. ++
  43. ++ tv.tv_sec = ctx->response_timeout.tv_sec;
  44. ++ tv.tv_usec = ctx->response_timeout.tv_usec;
  45. ++
  46. ++ rc = ctx->backend->select(ctx, &rfds, &tv, sizeof(cc));
  47. ++ if(rc > 0) ctx->backend->recv(ctx, msg + msg_length, rc);
  48. ++ } while(rc > 0); /* read until transfer empty */
  49. ++ }
  50. ++
  51. + if (ctx->debug) {
  52. + fprintf(stderr, "ERROR CRC received %0X != CRC calculated %0X\n",
  53. + crc_received, crc_calculated);
  54. --
  55. 2.7.4