From cd2c1d388aea33fa3513e93b2d2835f68793d593 Mon Sep 17 00:00:00 2001
From: blublup <blublup>
Date: Wed, 10 Feb 2021 23:18:00 +0100
Subject: [PATCH 1/2] Update dlt core for changes in new dlt 2.18.6

---
 dlt/core/core_2186.py | 83 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 dlt/core/core_2186.py

diff --git a/dlt/core/core_2186.py b/dlt/core/core_2186.py
new file mode 100644
index 0000000..51fc3ff
--- /dev/null
+++ b/dlt/core/core_2186.py
@@ -0,0 +1,83 @@
+# Copyright (C) 2019. BMW Car IT GmbH. All rights reserved.
+"""v2.18.6 specific class definitions"""
+import ctypes
+
+# DltClientMode from dlt_client.h
+DLT_CLIENT_MODE_UNDEFINED = -1
+DLT_CLIENT_MODE_TCP = 0
+DLT_CLIENT_MODE_SERIAL = 1
+DLT_CLIENT_MODE_UNIX = 2
+DLT_CLIENT_MODE_UDP_MULTICAST = 3
+
+# DltReceiverType from dlt_common.h
+# DltReceiverType is an enum type. These definitions could not be found in shared library (libdlt.so) so
+# the enum values are defined here.
+DLT_RECEIVE_SOCKET = 0
+DLT_RECEIVE_UDP_SOCKET = 1
+DLT_RECEIVE_FD = 2
+
+
+class sockaddr_in(ctypes.Structure):  # pylint: disable=invalid-name
+    """Auxiliary definition for cDltReceiver. Defined in netinet/in.h header"""
+    _fields_ = [("sa_family", ctypes.c_ushort),  # sin_family
+                ("sin_port", ctypes.c_ushort),
+                ("sin_addr", ctypes.c_byte * 4),
+                ("__pad", ctypes.c_byte * 8)]    # struct sockaddr_in is 16
+
+
+class cDltReceiver(ctypes.Structure):  # pylint: disable=invalid-name
+    """The structure is used to organise the receiving of data including buffer handling.
+    This structure is used by the corresponding functions.
+
+    typedef struct
+    {
+        int32_t lastBytesRcvd;    /**< bytes received in last receive call */
+        int32_t bytesRcvd;        /**< received bytes */
+        int32_t totalBytesRcvd;   /**< total number of received bytes */
+        char *buffer;             /**< pointer to receiver buffer */
+        char *buf;                /**< pointer to position within receiver buffer */
+        char *backup_buf;         /** pointer to the buffer with partial messages if any **/
+        int fd;                   /**< connection handle */
+        DltReceiverType  type;    /**< type of connection handle */
+        uint32_t buffersize;      /**< size of receiver buffer */
+        struct sockaddr_in addr;  /**< socket address information */
+    } DltReceiver;
+    """
+    _fields_ = [("lastBytesRcvd", ctypes.c_int32),
+                ("bytesRcvd", ctypes.c_int32),
+                ("totalBytesRcvd", ctypes.c_int32),
+                ("buffer", ctypes.POINTER(ctypes.c_char)),
+                ("buf", ctypes.POINTER(ctypes.c_char)),
+                ("backup_buf", ctypes.POINTER(ctypes.c_char)),
+                ("fd", ctypes.c_int),
+                ("type", ctypes.c_int),
+                ("buffersize", ctypes.c_uint32),
+                ("addr", sockaddr_in)]
+
+
+class cDltClient(ctypes.Structure):  # pylint: disable=invalid-name
+    """
+    typedef struct
+    {
+        DltReceiver receiver;  /**< receiver pointer to dlt receiver structure */
+        int sock;              /**< sock Connection handle/socket */
+        char *servIP;          /**< servIP IP adress/Hostname of TCP/IP interface */
+        char *hostip;          /**< IP multicast address of group */
+        int port;              /**< Port for TCP connections (optional) */
+        char *serialDevice;    /**< serialDevice Devicename of serial device */
+        char *socketPath;      /**< socketPath Unix socket path */
+        char ecuid[4];           /**< ECUiD */
+        speed_t baudrate;      /**< baudrate Baudrate of serial interface, as speed_t */
+        DltClientMode mode;    /**< mode DltClientMode */
+    } DltClient;
+    """
+    _fields_ = [("receiver", cDltReceiver),
+                ("sock", ctypes.c_int),
+                ("servIP", ctypes.c_char_p),
+                ("hostip", ctypes.c_char_p),
+                ("port", ctypes.c_int),
+                ("serialDevice", ctypes.c_char_p),
+                ("socketPath", ctypes.c_char_p),
+                ("ecuid", ctypes.c_char * 4),
+                ("baudrate", ctypes.c_uint),
+                ("mode", ctypes.c_int)]

From 939b48e1b82e68ac94ec1e67376a524be9f600a2 Mon Sep 17 00:00:00 2001
From: Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
Date: Wed, 10 Feb 2021 23:18:36 +0100
Subject: [PATCH 2/2] Update tests to cope with new dlt 2.18.6 version (Closes:
 #26)

---
 tests/dlt_core_unit_tests.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/dlt_core_unit_tests.py b/tests/dlt_core_unit_tests.py
index 9c648b8..4d9a1be 100644
--- a/tests/dlt_core_unit_tests.py
+++ b/tests/dlt_core_unit_tests.py
@@ -21,8 +21,8 @@ def setUp(self):
                          'cDltStandardHeaderExtra': 12,
                          'cDltExtendedHeader': 10,
                          'cDLTMessage': 120,
-                         'cDltReceiver': 64,
-                         'cDltClient': 128}
+                         'cDltReceiver': 72,
+                         'cDltClient': 136}
 
     def test_sizeof(self):
         for clsname, expected in self.size_map.items():
@@ -36,11 +36,11 @@ class TestImportSpecificVersion(unittest.TestCase):
 
     def setUp(self):
         self.original_api_version = dlt.core.API_VER
-        self.version_answer = b"2.18.5"
-        self.version_str = (b"DLT Package Version: 2.18.5 STABLE, Package Revision: v2.18.5_5_g33fbad1, "
-                            b"build on Sep  2 2020 11:55:50\n-SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM\n")
-        self.version_filename = "core_2185.py"
-        self.version_truncate_str = "2.18.5"
+        self.version_answer = b"2.18.6"
+        self.version_str = (b"DLT Package Version: 2.18.6 STABLE, Package Revision: v2.18.6_5_22715aec, "
+                            b"build on Jan  6 2021 11:55:50\n-SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM\n")
+        self.version_filename = "core_2186.py"
+        self.version_truncate_str = "2.18.6"
         self.version_truncate_filename = "core_2180.py"
 
         dlt.core.API_VER = None
