Browse Source

GfA libmodbus patches for RS485

Reinhard Russinger 7 năm trước cách đây
mục cha
commit
7bbe4417a8

+ 2 - 0
Make-bb-kernel_Qt5.7.sh

@@ -26,6 +26,8 @@ cd buildroot57
 git checkout 63a20d5dfebe83e2b2bd683dc78ebdf787dff100 -b gfawrk
 patch -p1 < ../GfA/patches/0001-GfA-wrk-changes-and-setup.patch
 patch -p1 < ../GfA/patches/0003-add-SW_IO1-to-SW_IO4-to-headers-and-evtest.patch
+patch -p1 < ../GfA/patches/0004-libmodbus-GfA-fflush-for-debug.patch
+patch -p2 < ../GfA/patches/0005-GfA-empty-input-queue-on-CRC-error.patch
 #
 chmod a+x *.sh
 cp ../GfA/configs/* ./configs

+ 66 - 0
patches/0004-libmodbus-GfA-fflush-for-debug.patch

@@ -0,0 +1,66 @@
+From 4e7a6c3d241f1da3da89d384e84c0c1547d17451 Mon Sep 17 00:00:00 2001
+From: Reinhard Russinger <reinhard@russinger.at>
+Date: Mon, 18 Jun 2018 18:39:18 +0200
+Subject: [PATCH] libmodbus GfA fflush for debug
+
+---
+ package/libmodbus/002-GfA-fflush-for-debug.patch | 47 ++++++++++++++++++++++++
+ 1 file changed, 47 insertions(+)
+ create mode 100644 package/libmodbus/002-GfA-fflush-for-debug.patch
+
+diff --git a/package/libmodbus/002-GfA-fflush-for-debug.patch b/package/libmodbus/002-GfA-fflush-for-debug.patch
+new file mode 100644
+index 0000000..93eaa9a
+--- /dev/null
++++ b/package/libmodbus/002-GfA-fflush-for-debug.patch
+@@ -0,0 +1,47 @@
++diff '--exclude=.libs*' -Naurp libmodbus-3.0.6/src/modbus.c b/src/modbus.c
++--- libmodbus-3.0.6/src/modbus.c	2014-04-02 23:34:00.000000000 +0200
+++++ b/src/modbus.c	2018-06-15 08:36:32.657047324 +0200
++@@ -170,6 +170,7 @@ static int send_msg(modbus_t *ctx, uint8
++         for (i = 0; i < msg_length; i++)
++             printf("[%.2X]", msg[i]);
++         printf("\n");
+++        fflush(stdout);
++     }
++ 
++     /* In recovery mode, the write command will be issued until to be
++@@ -407,6 +408,7 @@ static int receive_msg(modbus_t *ctx, ui
++             int i;
++             for (i=0; i < rc; i++)
++                 printf("<%.2X>", msg[msg_length + i]);
+++            fflush(stdout);
++         }
++ 
++         /* Sums bytes received */
++diff '--exclude=.libs*' -Naurp libmodbus-3.0.6/src/modbus-rtu.c b/src/modbus-rtu.c
++--- libmodbus-3.0.6/src/modbus-rtu.c	2018-06-16 17:44:19.011371930 +0200
+++++ b/src/modbus-rtu.c	2018-06-15 08:34:34.544888427 +0200
++@@ -260,7 +260,7 @@ static int win32_ser_read(struct win32_s
++ 
++ ssize_t _modbus_rtu_write_n_read(modbus_t *ctx, const uint8_t *req, int req_length) {
++  ssize_t w, r, i;
++- uint8_t rb[req_length];
+++ uint8_t rb[512];
++ 
++  // Transmit
++  w = write(ctx->s, req, req_length);
++@@ -273,6 +273,7 @@ ssize_t _modbus_rtu_write_n_read(modbus_
++   for (i = 0; i < r; ++i)
++   fprintf(stderr, "|%02X|", rb[i]);
++   fprintf(stderr, "\n");
+++  fflush(stderr);
++  }
++ 
++  return w;
++@@ -325,6 +326,7 @@ int _modbus_rtu_check_integrity(modbus_t
++         if (ctx->debug) {
++             fprintf(stderr, "ERROR CRC received %0X != CRC calculated %0X\n",
++                     crc_received, crc_calculated);
+++            fflush(stderr);                    
++         }
++         if (ctx->error_recovery & MODBUS_ERROR_RECOVERY_PROTOCOL) {
++             _modbus_rtu_flush(ctx);
+-- 
+2.7.4
+

+ 58 - 0
patches/0005-GfA-empty-input-queue-on-CRC-error.patch

@@ -0,0 +1,58 @@
+From d8d71642ad7b1209e2aa8d3fb227d37051076248 Mon Sep 17 00:00:00 2001
+From: Reinhard Russinger <reinhard@russinger.at>
+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
+