[oe-commits] [meta-openembedded] 13/15: libmodbus: update version to 3.1.6

git at git.openembedded.org git at git.openembedded.org
Wed Aug 28 14:16:49 UTC 2019


This is an automated email from the git hooks/post-receive script.

khem pushed a commit to branch master-next
in repository meta-openembedded.

commit 08189261e3da669fce3035a9035ee5c4a0d21815
Author: Gianfranco Costamagna <gianfranco.costamagna at abinsula.com>
AuthorDate: Wed Aug 28 11:14:16 2019 +0200

    libmodbus: update version to 3.1.6
    
    cherry-pick upstream patch and two Debian patches. tweak configure step to force autogenerated files regeneration
    
    Signed-off-by: Khem Raj <raj.khem at gmail.com>
---
 ...float-endianness-issue-on-big-endian-arch.patch | 314 +++++++++++++++++++++
 .../libmodbus/libmodbus/Fix-typo.patch             |  52 ++++
 .../f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d.patch |  32 +++
 .../recipes-extended/libmodbus/libmodbus_3.1.4.bb  |   4 -
 .../recipes-extended/libmodbus/libmodbus_3.1.6.bb  |  12 +
 5 files changed, 410 insertions(+), 4 deletions(-)

diff --git a/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-float-endianness-issue-on-big-endian-arch.patch b/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-float-endianness-issue-on-big-endian-arch.patch
new file mode 100644
index 0000000..5372a23
--- /dev/null
+++ b/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-float-endianness-issue-on-big-endian-arch.patch
@@ -0,0 +1,314 @@
+From: =?utf-8?b?IlNaIExpbiAo5p6X5LiK5pm6KSI=?= <szlin at debian.org>
+Date: Wed, 19 Dec 2018 10:24:47 +0800
+Subject: Fix float endianness issue on big endian arch
+
+It converts float values depending on what order they come in.
+
+This patch was modified from rm5248 [1]
+
+[1] https://github.com/synexxus/libmodbus/commit/a511768e7fe7ec52d7bae1d9ae04e33f87a59627
+
+---
+ src/modbus-data.c        | 110 ++++++++++++++++++++++++++++++++++++++---------
+ tests/unit-test-client.c |  22 ++++++----
+ tests/unit-test.h.in     |  41 ++++++++++++++++--
+ 3 files changed, 141 insertions(+), 32 deletions(-)
+
+diff --git a/src/modbus-data.c b/src/modbus-data.c
+index 902b8c6..7a744fa 100644
+--- a/src/modbus-data.c
++++ b/src/modbus-data.c
+@@ -119,9 +119,18 @@ float modbus_get_float_abcd(const uint16_t *src)
+ {
+     float f;
+     uint32_t i;
++    uint8_t a, b, c, d;
+ 
+-    i = ntohl(((uint32_t)src[0] << 16) + src[1]);
+-    memcpy(&f, &i, sizeof(float));
++    a = (src[0] >> 8) & 0xFF;
++    b = (src[0] >> 0) & 0xFF;
++    c = (src[1] >> 8) & 0xFF;
++    d = (src[1] >> 0) & 0xFF;
++
++    i = (a << 24) |
++        (b << 16) |
++        (c << 8) |
++        (d << 0);
++    memcpy(&f, &i, 4);
+ 
+     return f;
+ }
+@@ -131,9 +140,18 @@ float modbus_get_float_dcba(const uint16_t *src)
+ {
+     float f;
+     uint32_t i;
++    uint8_t a, b, c, d;
+ 
+-    i = ntohl(bswap_32((((uint32_t)src[0]) << 16) + src[1]));
+-    memcpy(&f, &i, sizeof(float));
++    a = (src[0] >> 8) & 0xFF;
++    b = (src[0] >> 0) & 0xFF;
++    c = (src[1] >> 8) & 0xFF;
++    d = (src[1] >> 0) & 0xFF;
++
++    i = (d << 24) |
++        (c << 16) |
++        (b << 8) |
++        (a << 0);
++    memcpy(&f, &i, 4);
+ 
+     return f;
+ }
+@@ -143,9 +161,18 @@ float modbus_get_float_badc(const uint16_t *src)
+ {
+     float f;
+     uint32_t i;
++    uint8_t a, b, c, d;
+ 
+-    i = ntohl((uint32_t)(bswap_16(src[0]) << 16) + bswap_16(src[1]));
+-    memcpy(&f, &i, sizeof(float));
++    a = (src[0] >> 8) & 0xFF;
++    b = (src[0] >> 0) & 0xFF;
++    c = (src[1] >> 8) & 0xFF;
++    d = (src[1] >> 0) & 0xFF;
++
++    i = (b << 24) |
++        (a << 16) |
++        (d << 8) |
++        (c << 0);
++    memcpy(&f, &i, 4);
+ 
+     return f;
+ }
+@@ -155,9 +182,18 @@ float modbus_get_float_cdab(const uint16_t *src)
+ {
+     float f;
+     uint32_t i;
++    uint8_t a, b, c, d;
+ 
+-    i = ntohl((((uint32_t)src[1]) << 16) + src[0]);
+-    memcpy(&f, &i, sizeof(float));
++    a = (src[0] >> 8) & 0xFF;
++    b = (src[0] >> 0) & 0xFF;
++    c = (src[1] >> 8) & 0xFF;
++    d = (src[1] >> 0) & 0xFF;
++
++    i = (c << 24) |
++        (d << 16) |
++        (a << 8) |
++        (b << 0);
++    memcpy(&f, &i, 4);
+ 
+     return f;
+ }
+@@ -172,50 +208,84 @@ float modbus_get_float(const uint16_t *src)
+     memcpy(&f, &i, sizeof(float));
+ 
+     return f;
++
+ }
+ 
+ /* Set a float to 4 bytes for Modbus w/o any conversion (ABCD) */
+ void modbus_set_float_abcd(float f, uint16_t *dest)
+ {
+     uint32_t i;
++    uint8_t *out = (uint8_t*) dest;
++    uint8_t a, b, c, d;
+ 
+     memcpy(&i, &f, sizeof(uint32_t));
+-    i = htonl(i);
+-    dest[0] = (uint16_t)(i >> 16);
+-    dest[1] = (uint16_t)i;
++    a = (i >> 24) & 0xFF;
++    b = (i >> 16) & 0xFF;
++    c = (i >> 8) & 0xFF;
++    d = (i >> 0) & 0xFF;
++
++    out[0] = a;
++    out[1] = b;
++    out[2] = c;
++    out[3] = d;
+ }
+ 
+ /* Set a float to 4 bytes for Modbus with byte and word swap conversion (DCBA) */
+ void modbus_set_float_dcba(float f, uint16_t *dest)
+ {
+     uint32_t i;
++    uint8_t *out = (uint8_t*) dest;
++    uint8_t a, b, c, d;
+ 
+     memcpy(&i, &f, sizeof(uint32_t));
+-    i = bswap_32(htonl(i));
+-    dest[0] = (uint16_t)(i >> 16);
+-    dest[1] = (uint16_t)i;
++    a = (i >> 24) & 0xFF;
++    b = (i >> 16) & 0xFF;
++    c = (i >> 8) & 0xFF;
++    d = (i >> 0) & 0xFF;
++
++    out[0] = d;
++    out[1] = c;
++    out[2] = b;
++    out[3] = a;
++
+ }
+ 
+ /* Set a float to 4 bytes for Modbus with byte swap conversion (BADC) */
+ void modbus_set_float_badc(float f, uint16_t *dest)
+ {
+     uint32_t i;
++    uint8_t *out = (uint8_t*) dest;
++    uint8_t a, b, c, d;
+ 
+     memcpy(&i, &f, sizeof(uint32_t));
+-    i = htonl(i);
+-    dest[0] = (uint16_t)bswap_16(i >> 16);
+-    dest[1] = (uint16_t)bswap_16(i & 0xFFFF);
++    a = (i >> 24) & 0xFF;
++    b = (i >> 16) & 0xFF;
++    c = (i >> 8) & 0xFF;
++    d = (i >> 0) & 0xFF;
++
++    out[0] = b;
++    out[1] = a;
++    out[2] = d;
++    out[3] = c;
+ }
+ 
+ /* Set a float to 4 bytes for Modbus with word swap conversion (CDAB) */
+ void modbus_set_float_cdab(float f, uint16_t *dest)
+ {
+     uint32_t i;
++    uint8_t *out = (uint8_t*) dest;
++    uint8_t a, b, c, d;
+ 
+     memcpy(&i, &f, sizeof(uint32_t));
+-    i = htonl(i);
+-    dest[0] = (uint16_t)i;
+-    dest[1] = (uint16_t)(i >> 16);
++    a = (i >> 24) & 0xFF;
++    b = (i >> 16) & 0xFF;
++    c = (i >> 8) & 0xFF;
++    d = (i >> 0) & 0xFF;
++
++    out[0] = c;
++    out[1] = d;
++    out[2] = a;
++    out[3] = b;
+ }
+ 
+ /* DEPRECATED - Set a float to 4 bytes in a sort of Modbus format! */
+diff --git a/tests/unit-test-client.c b/tests/unit-test-client.c
+index 3e315f4..3fccf3e 100644
+--- a/tests/unit-test-client.c
++++ b/tests/unit-test-client.c
+@@ -27,6 +27,7 @@ int send_crafted_request(modbus_t *ctx, int function,
+                          uint16_t max_value, uint16_t bytes,
+                          int backend_length, int backend_offset);
+ int equal_dword(uint16_t *tab_reg, const uint32_t value);
++int is_memory_equal(const void *s1, const void *s2, size_t size);
+ 
+ #define BUG_REPORT(_cond, _format, _args ...) \
+     printf("\nLine %d: assertion error for '%s': " _format "\n", __LINE__, # _cond, ## _args)
+@@ -40,6 +41,11 @@ int equal_dword(uint16_t *tab_reg, const uint32_t value);
+     }                                             \
+ };
+ 
++int is_memory_equal(const void *s1, const void *s2, size_t size)
++{
++    return (memcmp(s1, s2, size) == 0);
++}
++
+ int equal_dword(uint16_t *tab_reg, const uint32_t value) {
+     return ((tab_reg[0] == (value >> 16)) && (tab_reg[1] == (value & 0xFFFF)));
+ }
+@@ -286,26 +292,26 @@ int main(int argc, char *argv[])
+     /** FLOAT **/
+     printf("1/4 Set/get float ABCD: ");
+     modbus_set_float_abcd(UT_REAL, tab_rp_registers);
+-    ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_ABCD), "FAILED Set float ABCD");
+-    real = modbus_get_float_abcd(tab_rp_registers);
++    ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_ABCD_SET, 4), "FAILED Set float ABCD");
++    real = modbus_get_float_abcd(UT_IREAL_ABCD_GET);
+     ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
+ 
+     printf("2/4 Set/get float DCBA: ");
+     modbus_set_float_dcba(UT_REAL, tab_rp_registers);
+-    ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_DCBA), "FAILED Set float DCBA");
+-    real = modbus_get_float_dcba(tab_rp_registers);
++    ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_DCBA_SET, 4), "FAILED Set float DCBA");
++    real = modbus_get_float_dcba(UT_IREAL_DCBA_GET);
+     ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
+ 
+     printf("3/4 Set/get float BADC: ");
+     modbus_set_float_badc(UT_REAL, tab_rp_registers);
+-    ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_BADC), "FAILED Set float BADC");
+-    real = modbus_get_float_badc(tab_rp_registers);
++    ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_BADC_SET, 4), "FAILED Set float BADC");
++    real = modbus_get_float_badc(UT_IREAL_BADC_GET);
+     ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
+ 
+     printf("4/4 Set/get float CDAB: ");
+     modbus_set_float_cdab(UT_REAL, tab_rp_registers);
+-    ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_CDAB), "FAILED Set float CDAB");
+-    real = modbus_get_float_cdab(tab_rp_registers);
++    ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_CDAB_SET, 4), "FAILED Set float CDAB");
++    real = modbus_get_float_cdab(UT_IREAL_CDAB_GET);
+     ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
+ 
+     printf("\nAt this point, error messages doesn't mean the test has failed\n");
+diff --git a/tests/unit-test.h.in b/tests/unit-test.h.in
+index dca826f..4ffa254 100644
+--- a/tests/unit-test.h.in
++++ b/tests/unit-test.h.in
+@@ -56,12 +56,45 @@ const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x108;
+ const uint16_t UT_INPUT_REGISTERS_NB = 0x1;
+ const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A };
+ 
++/*
++ * This float value is 0x47F12000 (in big-endian format).
++ * In Little-endian(intel) format, it will be stored in memory as follows:
++ * 0x00 0x20 0xF1 0x47
++ *
++ * You can check this with the following code:
++
++   float fl = UT_REAL;
++   uint8_t *inmem = (uint8_t*)&fl;
++   int x;
++   for(x = 0; x < 4; x++){
++       printf("0x%02X ", inmem[ x ]);
++   }
++   printf("\n");
++ */
+ const float UT_REAL = 123456.00;
+ 
+-const uint32_t UT_IREAL_ABCD = 0x0020F147;
+-const uint32_t UT_IREAL_DCBA = 0x47F12000;
+-const uint32_t UT_IREAL_BADC = 0x200047F1;
+-const uint32_t UT_IREAL_CDAB = 0xF1470020;
++/*
++ * The following arrays assume that 'A' is the MSB,
++ * and 'D' is the LSB.
++ * Thus, the following is the case:
++ * A = 0x47
++ * B = 0xF1
++ * C = 0x20
++ * D = 0x00
++ *
++ * There are two sets of arrays: one to test that the setting is correct,
++ * the other to test that the getting is correct.
++ * Note that the 'get' values must be constants in processor-endianness,
++ * as libmodbus will convert all words to processor-endianness as they come in.
++ */
++const uint8_t UT_IREAL_ABCD_SET[] = {0x47, 0xF1, 0x20, 0x00};
++const uint16_t UT_IREAL_ABCD_GET[] = {0x47F1, 0x2000};
++const uint8_t UT_IREAL_DCBA_SET[] = {0x00, 0x20, 0xF1, 0x47};
++const uint16_t UT_IREAL_DCBA_GET[] = {0x0020, 0xF147};
++const uint8_t UT_IREAL_BADC_SET[] = {0xF1, 0x47, 0x00, 0x20};
++const uint16_t UT_IREAL_BADC_GET[] = {0xF147, 0x0020};
++const uint8_t UT_IREAL_CDAB_SET[] = {0x20, 0x00, 0x47, 0xF1};
++const uint16_t UT_IREAL_CDAB_GET[] = {0x2000, 0x47F1};
+ 
+ /* const uint32_t UT_IREAL_ABCD = 0x47F12000);
+ const uint32_t UT_IREAL_DCBA = 0x0020F147;
diff --git a/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-typo.patch b/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-typo.patch
new file mode 100644
index 0000000..384a4a4
--- /dev/null
+++ b/meta-oe/recipes-extended/libmodbus/libmodbus/Fix-typo.patch
@@ -0,0 +1,52 @@
+From: =?utf-8?b?IlNaIExpbiAo5p6X5LiK5pm6KSI=?= <szlin at debian.org>
+Date: Thu, 27 Sep 2018 14:51:32 +0800
+Subject: Fix typo
+
+---
+ doc/modbus_mapping_new_start_address.txt | 4 ++--
+ doc/modbus_reply.txt                     | 2 +-
+ doc/modbus_reply_exception.txt           | 2 +-
+ 3 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/doc/modbus_mapping_new_start_address.txt b/doc/modbus_mapping_new_start_address.txt
+index 4fa196a..94a81fb 100644
+--- a/doc/modbus_mapping_new_start_address.txt
++++ b/doc/modbus_mapping_new_start_address.txt
+@@ -21,9 +21,9 @@ The _modbus_mapping_new_start_address()_ function shall allocate four arrays to
+ store bits, input bits, registers and inputs registers. The pointers are stored
+ in modbus_mapping_t structure. All values of the arrays are initialized to zero.
+ 
+-The different starting adresses make it possible to place the mapping at any
++The different starting addresses make it possible to place the mapping at any
+ address in each address space. This way, you can give access to values stored
+-at high adresses without allocating memory from the address zero, for eg. to
++at high addresses without allocating memory from the address zero, for eg. to
+ make available registers from 10000 to 10009, you can use:
+ 
+ [source,c]
+diff --git a/doc/modbus_reply.txt b/doc/modbus_reply.txt
+index 0b29d6f..6b71d11 100644
+--- a/doc/modbus_reply.txt
++++ b/doc/modbus_reply.txt
+@@ -3,7 +3,7 @@ modbus_reply(3)
+ 
+ NAME
+ ----
+-modbus_reply - send a reponse to the received request
++modbus_reply - send a response to the received request
+ 
+ 
+ SYNOPSIS
+diff --git a/doc/modbus_reply_exception.txt b/doc/modbus_reply_exception.txt
+index 7e6324f..b2170be 100644
+--- a/doc/modbus_reply_exception.txt
++++ b/doc/modbus_reply_exception.txt
+@@ -3,7 +3,7 @@ modbus_reply_exception(3)
+ 
+ NAME
+ ----
+-modbus_reply_exception - send an exception reponse
++modbus_reply_exception - send an exception response
+ 
+ 
+ SYNOPSIS
diff --git a/meta-oe/recipes-extended/libmodbus/libmodbus/f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d.patch b/meta-oe/recipes-extended/libmodbus/libmodbus/f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d.patch
new file mode 100644
index 0000000..7fae34e
--- /dev/null
+++ b/meta-oe/recipes-extended/libmodbus/libmodbus/f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d.patch
@@ -0,0 +1,32 @@
+From f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d Mon Sep 17 00:00:00 2001
+From: i-ky <gl.ivanovsky at gmail.com>
+Date: Tue, 10 Jul 2018 15:58:45 +0300
+Subject: [PATCH] Fixed MODBUS_GET_* macros in case of negative values
+
+In case resulting value should be negative it is incorrect to use '+' operator to construct it from pieces, because highest bytes will result in negative number after bitwise shift while others will stay positive. Replacing addition with '|' should solve the issue.
+---
+ src/modbus.h | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/src/modbus.h b/src/modbus.h
+index f6e9a5f5..c63f5ceb 100644
+--- a/src/modbus.h
++++ b/src/modbus.h
+@@ -245,12 +245,12 @@ MODBUS_API int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
+ #define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF)
+ #define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF)
+ #define MODBUS_GET_INT64_FROM_INT16(tab_int16, index) \
+-    (((int64_t)tab_int16[(index)    ] << 48) + \
+-     ((int64_t)tab_int16[(index) + 1] << 32) + \
+-     ((int64_t)tab_int16[(index) + 2] << 16) + \
++    (((int64_t)tab_int16[(index)    ] << 48) | \
++     ((int64_t)tab_int16[(index) + 1] << 32) | \
++     ((int64_t)tab_int16[(index) + 2] << 16) | \
+       (int64_t)tab_int16[(index) + 3])
+-#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])
+-#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])
++#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) | tab_int16[(index) + 1])
++#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) | tab_int8[(index) + 1])
+ #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \
+     do { \
+         tab_int8[(index)] = (value) >> 8;  \
diff --git a/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.4.bb b/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.4.bb
deleted file mode 100644
index cc45fa7..0000000
--- a/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.4.bb
+++ /dev/null
@@ -1,4 +0,0 @@
-require libmodbus.inc
-
-SRC_URI[md5sum] = "b1a8fd3a40d2db4de51fb0cbcb201806"
-SRC_URI[sha256sum] = "c8c862b0e9a7ba699a49bc98f62bdffdfafd53a5716c0e162696b4bf108d3637"
diff --git a/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.6.bb b/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.6.bb
new file mode 100644
index 0000000..075487a
--- /dev/null
+++ b/meta-oe/recipes-extended/libmodbus/libmodbus_3.1.6.bb
@@ -0,0 +1,12 @@
+require libmodbus.inc
+
+SRC_URI += "file://f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d.patch \
+	    file://Fix-float-endianness-issue-on-big-endian-arch.patch \
+	    file://Fix-typo.patch"
+SRC_URI[md5sum] = "15c84c1f7fb49502b3efaaa668cfd25e"
+SRC_URI[sha256sum] = "d7d9fa94a16edb094e5fdf5d87ae17a0dc3f3e3d687fead81835d9572cf87c16"
+
+# this file has been created one minute after the configure file, so it doesn't get recreated during configure step
+do_configure_prepend() {
+	rm -rf ${S}/tests/unit-test.h
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list