浏览代码

Merge branch 'feature/mess_around_with_transport_layer' of shimatta/shellmatta into develop

shimatta 9 月之前
父节点
当前提交
2873e4d355

+ 4 - 1
.gitignore

@@ -1,2 +1,5 @@
 output
-output
+**__pycache__**
+.cache
+compile_commands.json
+python_driver/shellmatta_transport.py

+ 21 - 0
.vscode/launch.json

@@ -87,6 +87,27 @@
             ],
             "preLaunchTask": "make integrationtest_auth",
             "miDebuggerPath": "/usr/bin/gdb"
+        },
+        {
+            "name": "debug integrationtest_transport",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "${workspaceFolder}/output/test/integrationtest_transport/integrationtest_transport",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "${workspaceFolder}",
+            "environment": [],
+            "externalConsole": false,
+            "MIMode": "gdb",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                }
+            ],
+            "preLaunchTask": "make integrationtest_transport",
+            "miDebuggerPath": "/usr/bin/gdb"
         }
     ]
 }

+ 7 - 0
.vscode/settings.json

@@ -0,0 +1,7 @@
+{
+    "files.associations": {
+        "sstream": "cpp",
+        "regex": "cpp"
+    },
+    "C_Cpp.default.defines": ["SHELLMATTA_AUTH", "SHELLMATTA_TRANSPORT"]
+}

+ 8 - 0
.vscode/tasks.json

@@ -46,6 +46,14 @@
                 "$gcc"
             ]
         },
+        {
+            "label": "make integrationtest_transport",
+            "type": "shell",
+            "command": "make integrationtest_transport",
+            "problemMatcher": [
+                "$gcc"
+            ]
+        },
         {
             "label": "make test",
             "type": "shell",

+ 145 - 47
api/shellmatta.h

@@ -28,7 +28,7 @@
 
 /*
  * Define the printf format specifier for all GCC versions > 3.3
- * This will let the compiler know that shelmatta_printf() is a function taking printf-like format specifiers.
+ * This will let the compiler know that shellmatta_printf() is a function taking printf-like format specifiers.
  */
 #ifndef SHELLMATTA_ATTR_FORMAT
 #   if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
@@ -192,62 +192,147 @@ typedef struct shellmatta_cmd
     struct shellmatta_cmd   *next;      /**< pointer to next command or NULL        */
 } shellmatta_cmd_t;
 
+#ifdef SHELLMATTA_TRANSPORT
+
+/**
+ * @brief definition of shellmatta transport layer states
+ */
+typedef enum
+{
+    SHELLMATTA_TRANSPORT_STATE_WAIT = 0u    ,   /**< wait for start of header   */
+    SHELLMATTA_TRANSPORT_STATE_GET_HEADER   ,   /**< read in header             */
+    SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD  ,   /**< read in payload            */
+    SHELLMATTA_TRANSPORT_STATE_GET_CRC      ,   /**< read crc and process data  */
+} shellmatta_transport_state_t;
+
+
+/** @brief max length of a plain data payload */
+#define SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH           ((uint8_t)(255))
+
+/**
+ * @brief shellmatta transport crc function definition for custom crcs
+ * @param[in]   data        data to calculate the crc of
+ * @param[in]   size        size of the data in bytes
+ */
+typedef uint32_t (*shellmatta_transport_crc_t)(const char* data, const uint32_t size);
+
+/**
+ * @brief structure of one shellmatta transport header
+ */
+typedef struct __attribute__((__packed__))
+{
+    uint8_t startOfHeader;      /** start of header field               */
+    uint8_t protocolVersion;    /** protocol version of the packet      */
+    uint8_t packetType;         /** type of the packet                  */
+    uint8_t payloadLength;      /** length of the payload               */
+    uint8_t source;             /** source of the packet                */
+    uint8_t destination;        /** destination of the packet           */
+    uint8_t sequenceH2S;        /** sequence counter host to shellmatta */
+    uint8_t sequenceS2H;        /** sequence counter shellmatta to host */
+} shellmatta_transport_header_t;
+
+/**
+ * @brief structure of one shellmatta transport packet
+ */
+typedef struct __attribute__((__packed__))
+{
+    shellmatta_transport_header_t   header;                                         /**< header of the packet   */
+    char                            payload[SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH]; /**< payload of the packet  */
+    uint32_t                        crc;                                            /**< crc of the packet      */
+} shellmatta_transport_packet_t;
+
+/**
+ * @brief structure of one shellmatta transport layer instance
+ */
+typedef struct
+{
+    shellmatta_transport_state_t    state;              /**< current state of the transport layer reception */
+    bool                            active;             /**< is transport layer communication active        */
+    bool                            disableAutoFlush;   /**< enforce manual flushing                        */
+    bool                            mandatory;          /**< is the transport layer enforced                */
+    uint8_t                         sequenceH2S;        /**< sequence counter host to shellmatta            */
+    uint8_t                         sequenceS2H;        /**< sequenc counter shellmatta to host             */
+    uint32_t                        headerIndex;        /**< read index of the header                       */
+    uint32_t                        payloadIndex;       /**< read index of the payload                      */
+    uint32_t                        crcIndex;           /**< read index of the checksum                     */
+    shellmatta_transport_packet_t   inPacket;           /**< buffer for the received packets                */
+    shellmatta_transport_packet_t   outPacket;          /**< buffer for the sent packets                    */
+    shellmatta_write_t              writeFct;           /**< shellmatta write function                      */
+    shellmatta_transport_crc_t      customCrcFct;       /**< use this function to calculate crcs            */
+} shellmatta_transport_layer_t;
+
+#endif
 
 /**
  * @brief structure of one shellmatta instance
  */
 typedef struct
 {
-    uint32_t            magic;                  /**< magic number to check if initialized   */
-    char                *buffer;                /**< input buffer                           */
-    uint32_t            bufferSize;             /**< size of the input buffer               */
-    uint32_t            inputCount;             /**< offset of the current write operation  */
-    uint32_t            byteCounter;            /**< counter used to loop over input data   */
-    uint32_t            lastNewlineIdx;         /**< index of the lest newline              */
-    uint32_t            cursor;                 /**< offset where the cursor is at          */
-    uint32_t            stdinIdx;               /**< start index of stdin in buffer         */
-    uint32_t            stdinLength;            /**< length of the stdin data               */
-    char                *historyBuffer;         /**< buffer to store the last commands      */
-    uint32_t            historyBufferSize;      /**< size of the history buffer             */
-    uint32_t            historyStart;           /**< index of the oldest stored command     */
-    uint32_t            historyEnd;             /**< index of the newest stored command     */
-    uint32_t            historyRead;            /**< index of the current search            */
-    bool                historyReadUp;          /**< flag to show the last history dir      */
-    uint32_t            tabCounter;             /**< counts the tabulator key presses       */
-    uint32_t            escapeCounter;          /**< counts the characters of an escape seq */
-    char                escapeChars[4u];        /**< buffer to save the escape characters   */
-    uint32_t            hereStartIdx;           /**< heredoc start of "<<"                  */
-    uint32_t            hereDelimiterIdx;       /**< heredoc delimiter index in input       */
-    uint32_t            hereLength;             /**< length of the heredoc delimiter        */
-    bool                echoEnabled;            /**< if true the input is printed           */
-    bool                dirty;                  /**< dirty flag to show changes             */
-    const char          *prompt;                /**< prompt is printed after every command  */
-    char                delimiter;              /**< delimiter (return) to terminate a cmd  */
-    shellmatta_mode_t   mode;                   /**< mode of the shell                      */
-    shellmatta_write_t  write;                  /**< pointer to write function              */
-    shellmatta_cmd_t    helpCmd;                /**< help command structure                 */
-    shellmatta_cmd_t    *cmdList;               /**< pointer to the first command           */
-    shellmatta_cmd_t    *continuousCmd;         /**< command to be called continuously      */
-    shellmatta_cmd_t    *busyCmd;               /**< command to be polled (busy mode)       */
-    bool                cmdListIsConst;         /**< true if the #cmdList was passed during
-                                                     initialization                         */
-    shellmatta_opt_t    optionParser;           /**< option parser sructure                 */
+    uint32_t                        magic;              /**< magic number to check if initialized   */
+    char                            *buffer;            /**< input buffer                           */
+    uint32_t                        bufferSize;         /**< size of the input buffer               */
+    uint32_t                        inputCount;         /**< offset of the current write operation  */
+    uint32_t                        byteCounter;        /**< counter used to loop over input data   */
+    uint32_t                        lastNewlineIdx;     /**< index of the lest newline              */
+    uint32_t                        cursor;             /**< offset where the cursor is at          */
+    uint32_t                        stdinIdx;           /**< start index of stdin in buffer         */
+    uint32_t                        stdinLength;        /**< length of the stdin data               */
+    char                            *historyBuffer;     /**< buffer to store the last commands      */
+    uint32_t                        historyBufferSize;  /**< size of the history buffer             */
+    uint32_t                        historyStart;       /**< index of the oldest stored command     */
+    uint32_t                        historyEnd;         /**< index of the newest stored command     */
+    uint32_t                        historyRead;        /**< index of the current search            */
+    bool                            historyReadUp;      /**< flag to show the last history dir      */
+    uint32_t                        tabCounter;         /**< counts the tabulator key presses       */
+    uint32_t                        escapeCounter;      /**< counts the characters of an escape seq */
+    char                            escapeChars[4u];    /**< buffer to save the escape characters   */
+    uint32_t                        hereStartIdx;       /**< heredoc start of "<<"                  */
+    uint32_t                        hereDelimiterIdx;   /**< heredoc delimiter index in input       */
+    uint32_t                        hereLength;         /**< length of the heredoc delimiter        */
+    bool                            echoEnabled;        /**< if true the input is printed           */
+    bool                            dirty;              /**< dirty flag to show changes             */
+    const char                      *prompt;            /**< prompt is printed after every command  */
+    char                            delimiter;          /**< delimiter (return) to terminate a cmd  */
+    shellmatta_mode_t               mode;               /**< mode of the shell                      */
+    shellmatta_write_t              write;              /**< pointer to write function              */
+    shellmatta_cmd_t                helpCmd;            /**< help command structure                 */
+    shellmatta_cmd_t                *cmdList;           /**< pointer to the first command           */
+    shellmatta_cmd_t                *continuousCmd;     /**< command to be called continuously      */
+    shellmatta_cmd_t                *busyCmd;           /**< command to be polled (busy mode)       */
+    bool                            cmdListIsConst;     /**< true if the #cmdList was passed during
+                                                             initialization                         */
+    shellmatta_opt_t                optionParser;       /**< option parser sructure                 */
 #ifdef SHELLMATTA_AUTHENTICATION
-    shellmatta_auth_state_t     loginState;     /**< state variable of the login cmd        */
-    shellmatta_cmd_t            loginCmd;       /**< login command structure                */
-    shellmatta_cmd_t            logoutCmd;      /**< logout command structure               */
-    uint32_t                    userId;         /**< user ID of the current session         */
-    uint32_t                    tmpUserId;      /**< remporary user ID during input         */
-    shellmatta_auth_user_t      *userPointer;   /**< pointer to the user in the user list   */
-    shellmatta_auth_user_t      *userList;      /**< user list                              */
-    uint32_t                    userListLength; /**< length of the user list                */
-    shellmatta_auth_perm_t      *permList;      /**< permission list                        */
-    uint32_t                    permListLength; /**< length of the permission list          */
-    shellmatta_auth_check_t     checkFct;       /**< custom credential check function       */
-    shellmatta_auth_log_t       logFct;         /**< auth log function                      */
+    shellmatta_auth_state_t         loginState;         /**< state variable of the login cmd        */
+    shellmatta_cmd_t                loginCmd;           /**< login command structure                */
+    shellmatta_cmd_t                logoutCmd;          /**< logout command structure               */
+    uint32_t                        userId;             /**< user ID of the current session         */
+    uint32_t                        tmpUserId;          /**< remporary user ID during input         */
+    shellmatta_auth_user_t          *userPointer;       /**< pointer to the user in the user list   */
+    shellmatta_auth_user_t          *userList;          /**< user list                              */
+    uint32_t                        userListLength;     /**< length of the user list                */
+    shellmatta_auth_perm_t          *permList;          /**< permission list                        */
+    uint32_t                        permListLength;     /**< length of the permission list          */
+    shellmatta_auth_check_t         checkFct;           /**< custom credential check function       */
+    shellmatta_auth_log_t           logFct;             /**< auth log function                      */
+#endif
+#ifdef SHELLMATTA_TRANSPORT
+    uint32_t                        transportBusyMark;  /**< transport processing position during 
+                                                             busy cmd execution                     */
+    shellmatta_transport_layer_t    transportLayer;     /**< transport layer instance               */
 #endif
 } shellmatta_instance_t;
 
+/**
+ * @brief helper macro for the send function
+ */
+#ifdef SHELLMATTA_TRANSPORT
+#define SHELLMATTA_WRITE(data, length)  inst->transportLayer.active == true ?                                                                   \
+                                        shellmatta_transport_write((shellmatta_transport_layer_t*)&inst->transportLayer, (data), (length)) :    \
+                                        inst->write((data), (length))
+#else
+#define SHELLMATTA_WRITE(data, length)  inst->write((data), (length))
+#endif
 
 shellmatta_retCode_t shellmatta_doInit( shellmatta_instance_t   *inst,
                                         shellmatta_handle_t     *handle,
@@ -297,6 +382,19 @@ shellmatta_retCode_t shellmatta_opt_long(   shellmatta_handle_t         handle,
                                             char                        **argument,
                                             uint32_t                    *argLen);
 
+#ifdef SHELLMATTA_TRANSPORT
+
+shellmatta_retCode_t shellmatta_transport_configure(shellmatta_handle_t         handle,
+                                                    bool                        mandatory,
+                                                    bool                        disableAutoFlush,
+                                                    shellmatta_transport_crc_t  customCrcFct);
+
+shellmatta_retCode_t shellmatta_transport_reset(shellmatta_handle_t handle);
+
+shellmatta_retCode_t shellmatta_transport_flush(shellmatta_handle_t handle);
+
+#endif
+
 #ifndef SHELLMATTA_STRIP_PRINTF
 shellmatta_retCode_t shellmatta_printf(     shellmatta_handle_t handle,
                                             const char          *fmt,

+ 1 - 1
cfg/doxygen/doxyfile

@@ -2170,7 +2170,7 @@ INCLUDE_FILE_PATTERNS  =
 # recursively expanded use the := operator instead of the = operator.
 # This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
 
-PREDEFINED             =
+PREDEFINED             = SHELLMATTA_AUTHENTICATION SHELLMATTA_TRANSPORT
 
 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
 # tag can be used to specify a list of macro names that should be expanded. The

+ 3 - 0
doc/shellmatta.dox

@@ -36,10 +36,13 @@
         end
     @enduml
 
+
     @section shellmatta_options Shellmatta options
 
     The Shellmatta comes with some features which can be opted in:
 
     @subpage shellmatta_auth
 
+    @subpage shellmatta_transport_layer
+
 */

+ 119 - 0
doc/shellmatta_transport_layer.dox

@@ -0,0 +1,119 @@
+/**
+
+    @page shellmatta_transport_layer Shellmatta Transport Layer
+
+    To be able to use the shellmatta directly on an unsecured interface like
+    raw UART a simple connectionless transport layer has been implemented.
+
+    The transport layer is optional and can be removed during compile time as
+    well as deactivated during runtime.
+
+    To enable it during compile time add the define ``SHELLMATTA_TRANSPORT``.
+
+
+    The transport layer intends to be used in machine to machine interfaces.
+
+    @warning    As the transport layer is connectionless there is no way to
+                determine wether a packet is received properly.
+                To check if all packets have been received by the shellmatta
+                the sequence counters included in any packet can be used.
+
+    @section shellmatta_transport_layer_sequence Basic sequence
+
+    @startuml
+        loop until command is sent
+            Host -> Shellmatta: send packet
+            Shellmatta -> Shellmatta: validate packet
+        end
+
+        loop until response is sent
+            Shellmatta -> Host: send return packet
+            Host -> Host: validate packet
+        end
+    @enduml
+
+
+    @section shellmatta_transport_layer_protocol Protocol
+
+
+    | Offset | Length        | Description                                 |
+    |--------|---------------|---------------------------------------------|
+    |    0   |     1         | Start of header (\\SOH)                     |
+    |    1   |     1         | Protocol version                            |
+    |    2   |     1         | Packet type                                 |
+    |    3   |     1         | Payload Length                              |
+    |    4   |     1         | Source                                      |
+    |    5   |     1         | Destination                                 |
+    |    6   |     1         | Sequence counter host to shellmatta         |
+    |    7   |     1         | Sequence counter shellmatta to host         |
+    |    8   | L1 = 0 .. 255 | Payload                                     |
+    |8 + L1  |     4         | CRC32 of header + payload without CRC32     |
+
+
+    @subsection shellmatta_transport_layer_protocol_packet_Types Packet types
+
+    The type codes are divided into request and respond codes using the MSB.
+    The MSB indicates a response.
+
+    | type | Description                    | Payload length |  Payload               |
+    |------|--------------------------------|----------------|------------------------|
+    | 0x00 | Plain Data                     | 0 .. 255       | User data              |
+    | 0x01 | Request Sequence counters      | 0              | -                      |
+    | 0x81 | Respond Sequence counters      | 0              | -                      |
+    | 0x02 | Request and set max buffersize | 1              | Hosts buffersize       |
+    | 0x82 | Respond max buffersize         | 1              | Shellmattas buffersize |
+    | 0x03 | Search device by unique ID     | 32             | UUID Range 2x 16 byte  |
+    | 0x83 | Respond to search              | 16             | UUID of Shellmatta     |
+    | 0x04 | Set address                    | 16             | UUID of Shellmatta     |
+    | 0x84 | Respond to set address         | 16             | UUID of Shellmatta     |
+
+
+    @section shellmatta_transport_layer_sequence_counters Sequence counters
+
+    The sequence counters are included in the header of every packet to enable
+    the host to check for any dropped packets.
+    This is a quite nasty workaround as the host has no chance to determine
+    which packet has been dropped - but better than nothing.
+
+    If no response is received from the shellmatta the sequence counters can be
+    requested explicitly.
+
+    The sequence counter host to shellmatta will increment on every successfully
+    received packet.
+
+    The sequence counter shellmatta to host will increment on every packet the
+    shellmatta sends to the host.
+
+
+    @section shellmatta_transport_layer_buffersize Buffer sizes
+
+    @todo Not implemented yet
+
+
+    @section shellmatta_transport_layer_addressing Addressing and Search
+
+    @todo Not implemented yet
+
+
+    @section shellmatta_transport_layer_crc CRC calculation
+
+    The shellmatta transport layer uses the CRC32 algorithm to secure the
+    transmission (0x04c11db7).
+
+    By default the shellmatta crc implementation uses a lookup table to
+    calculate the crc in a performant way.
+
+    This uses quite a lot of read only memory on the device. If the memory
+    consumption is an Issue you can switch to a slower implementation without
+    the lookup table. This will increase CPU load quite a bit, but saves nearly
+    1K of read only memory.
+
+    To enable the lookup table less CRC just define
+    ``SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP`` during compilation.
+
+
+    @section shellmatta_transport_layer_control Controlling the transport layer
+
+    @todo Not implemented yet
+
+*/

+ 69 - 28
makefile

@@ -1,18 +1,20 @@
 #
-# Copyright (c) 2019 - 2021 Stefan Strobel <stefan.strobel@shimatta.net>
+# Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
 #
 
-OBJ_DIR := output/
-OBJ_DIR_EXAMPLE := $(OBJ_DIR)example_obj/
-INTEGRATIONTEST_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest/
-INTEGRATIONTEST_AUTH_CPP_OBJ_DIR := $(OBJ_DIR)test/integrationtest_auth/
-INTEGRATIONTEST_C_OBJ_DIR := $(INTEGRATIONTEST_CPP_OBJ_DIR)
-INTEGRATIONTEST_AUTH_C_OBJ_DIR := $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)
-UNITTEST_OBJ_DIR := $(OBJ_DIR)test/unittest/
+OBJ_DIR                                 := output/
+OBJ_DIR_EXAMPLE                         := $(OBJ_DIR)example_obj/
+INTEGRATIONTEST_CPP_OBJ_DIR             := $(OBJ_DIR)test/integrationtest/
+INTEGRATIONTEST_AUTH_CPP_OBJ_DIR        := $(OBJ_DIR)test/integrationtest_auth/
+INTEGRATIONTEST_C_OBJ_DIR               := $(INTEGRATIONTEST_CPP_OBJ_DIR)
+INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT   := $(OBJ_DIR)test/integrationtest_transport/
+INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT     := $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)
+INTEGRATIONTEST_AUTH_C_OBJ_DIR          := $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)
+UNITTEST_OBJ_DIR                        := $(OBJ_DIR)test/unittest/
 
 # helper define to run tests from a list
 define \n
@@ -31,11 +33,19 @@ SOURCES :=  src/shellmatta.c                \
             src/shellmatta_escape.c         \
             src/shellmatta_opt.c
 
+
+SOURCES_TRANPORT_LAYER  :=  $(SOURCES)                      \
+                            src/shellmatta_transport.c      \
+                            src/shellmatta_crc.c
 AUTH_SOURCES     := $(SOURCES) src/shellmatta_auth.c
-EXAMPLE_SOURCES  := $(AUTH_SOURCES) example/main.c
+EXAMPLE_SOURCES  := example/main.c
+EXAMPLE_SOURCES  += $(filter-out $(EXAMPLE_SOURCES),$(AUTH_SOURCES))
+EXAMPLE_SOURCES  += $(filter-out $(EXAMPLE_SOURCES),$(SOURCES_TRANPORT_LAYER))
 EXAMPLE_COBJ     := $(patsubst %.c,$(OBJ_DIR_EXAMPLE)%.o,$(EXAMPLE_SOURCES))
 
-CPPCHECK_SOURCES := $(AUTH_SOURCES)
+CPPCHECK_SOURCES := $(AUTH_SOURCES)                         \
+                    src/shellmatta_transport.c              \
+                    src/shellmatta_crc.c
 CPPCHECK_OPTIONS := --enable=all                                            \
                     --check-level=exhaustive                                \
                     --template=gcc                                          \
@@ -64,7 +74,9 @@ UNITTEST_SOURCES := test/unittest/test_main.cpp
                     test/unittest/shellmatta_autocomplete/test_autocomplete_run.cpp     \
                     test/unittest/shellmatta_escape/test_escape_processArrowKeys.cpp    \
                     test/unittest/shellmatta_history/test_appendHistoryByte.cpp         \
-                    test/unittest/shellmatta/test_shellmatta_doInit.cpp
+                    test/unittest/shellmatta/test_shellmatta_doInit.cpp                 \
+                    test/unittest/shellmatta_crc/test_crc32Slow.cpp                     \
+                    test/unittest/shellmatta_crc/test_crc32Fast.cpp
 
 INTEGRATIONTEST_SOURCES :=  test/integrationtest/test_main.cpp                  \
                             test/integrationtest/test_integration.cpp           \
@@ -75,6 +87,8 @@ INTEGRATIONTEST_SOURCES :=  test/integrationtest/test_main.cpp
                             test/integrationtest/test_integration_history.cpp   \
                             test/integrationtest/test_integration_help.cpp
 
+INTEGRATIONTEST_TRANSPORT_SOURCES  :=  $(INTEGRATIONTEST_SOURCES)                           \
+                                       test/integrationtest_transport/test_integration_transport.cpp
 INTEGRATIONTEST_AUTH_SOURCES := test/integrationtest_auth/test_main.cpp                 \
                                 test/integrationtest_auth/test_integration_auth.cpp
 
@@ -83,34 +97,48 @@ UNITTEST_CPPOBJ  := $(patsubst %.cpp,$(UNITTEST_OBJ_DIR)%.o,$(UNITTEST_SOURCES))
 INTEGRATIONTEST_CPPOBJ  :=  $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
 INTEGRATIONTEST_COBJ    :=  $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR)%.o,$(SOURCES))
 
+INTEGRATIONTEST_TRANSPORT_CPPOBJ    :=  $(patsubst %.cpp,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(INTEGRATIONTEST_TRANSPORT_SOURCES))
+INTEGRATIONTEST_TRANSPORT_COBJ     	:=  $(patsubst %.c,$(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT)%.o,$(SOURCES_TRANPORT_LAYER))
 INTEGRATIONTEST_AUTH_CPPOBJ :=  $(patsubst %.cpp,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(INTEGRATIONTEST_AUTH_SOURCES))
 INTEGRATIONTEST_AUTH_COBJ   :=  $(patsubst %.c,$(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR)%.o,$(AUTH_SOURCES))
 
-CFLAGS      := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
-CFLAGS_EXAMPLE = $(CFLAGS) -DSHELLMATTA_AUTHENTICATION
-TESTFLAGS   := $(CFLAGS) -fprofile-arcs -ftest-coverage
-TESTFLAGS_AUTH   := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -fprofile-arcs -ftest-coverage
-TESTLFLAGS  := -fprofile-arcs -Wl,--allow-multiple-definition
 
-DEPEND      = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
+CFLAGS                  := $(INCLUDES:%=-I%) -g -Wall -Werror -Wextra -pedantic
+CFLAGS                  += -DSHELLMATTA_HELP_ALIAS=\(char*\)\"?\"
+CFLAGS_EXAMPLE          := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -DSHELLMATTA_TRANSPORT
+TESTFLAGS               := $(CFLAGS) -fprofile-arcs -ftest-coverage
+TESTFLAGS_AUTH          := $(CFLAGS) -DSHELLMATTA_AUTHENTICATION -fprofile-arcs -ftest-coverage
+TESTLFLAGS              := -fprofile-arcs -Wl,--allow-multiple-definition
+TESTFLAGS_TRANSPORT     := $(TESTFLAGS) -DSHELLMATTA_TRANSPORT
+TESTLFLAGS_TRANSPORT    := $(TESTLFLAGS)
+DEPEND                  = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
 
-COBJ    := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
 
-EXAMPLE_TARGET  := $(OBJ_DIR)example/example
+COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
 
-UNITTEST_TARGET     := $(OBJ_DIR)test/unittest/unittest
-INTEGRATIONTEST_TARGET     := $(OBJ_DIR)test/integrationtest/integrationtest
-INTEGRATIONTEST_TARGET_AUTH     := $(OBJ_DIR)test/integrationtest_auth/integrationtest_auth
+EXAMPLE_TARGET                      := $(OBJ_DIR)example/example
+UNITTEST_TARGET                     := $(OBJ_DIR)test/unittest/unittest
+INTEGRATIONTEST_TARGET              := $(OBJ_DIR)test/integrationtest/integrationtest
+INTEGRATIONTEST_TARGET_AUTH         := $(OBJ_DIR)test/integrationtest_auth/integrationtest_auth
+INTEGRATIONTEST_TARGET_TRANSPORT    := $(OBJ_DIR)test/integrationtest_transport/integrationtest_transport
 
-TEST_RUN_TARGETS := unittest integrationtest integrationtest_auth
+TEST_RUN_TARGETS := unittest integrationtest integrationtest_auth integrationtest_transport
 # ensure the tests are running one after another when general test target is called
 ifneq ($(filter test,$(MAKECMDGOALS)),)
 TEST_RUN_TARGETS_HELPER := $(TEST_RUN_TARGETS)
 endif
-TEST_TARGETS := $(UNITTEST_TARGET) $(INTEGRATIONTEST_TARGET) $(INTEGRATIONTEST_TARGET_AUTH)
-
-OBJ     := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ) $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
-DEPS    := $(OBJ:%.o=%.d)
+TEST_TARGETS := $(UNITTEST_TARGET) $(INTEGRATIONTEST_TARGET) $(INTEGRATIONTEST_TARGET_AUTH) $(INTEGRATIONTEST_TARGET_TRANSPORT)
+
+OBJ     :=  $(COBJ)                             \
+            $(EXAMPLE_COBJ)                     \
+            $(UNITTEST_CPPOBJ)                  \
+            $(INTEGRATIONTEST_CPPOBJ)           \
+            $(INTEGRATIONTEST_COBJ)             \
+            $(INTEGRATIONTEST_AUTH_CPPOBJ)      \
+            $(INTEGRATIONTEST_AUTH_COBJ)        \
+            $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) \
+            $(INTEGRATIONTEST_TRANSPORT_COBJ)
+DEPS    :=  $(OBJ:%.o=%.d)
 
 export
 
@@ -175,10 +203,13 @@ $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
 $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(INTEGRATIONTEST_COBJ)
 	- @mkdir -p $(@D)
 	$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
+	
+$(INTEGRATIONTEST_TARGET_TRANSPORT): $(INTEGRATIONTEST_TRANSPORT_CPPOBJ) $(INTEGRATIONTEST_TRANSPORT_COBJ)
+	- @mkdir -p $(@D)
+	$(CPP) $(TESTLFLAGS_TRANSPORT) $(LIB_PATH) -o $@ $^ $(LIBS)
 
 $(INTEGRATIONTEST_TARGET_AUTH): $(INTEGRATIONTEST_AUTH_CPPOBJ) $(INTEGRATIONTEST_AUTH_COBJ)
 	- @mkdir -p $(@D)
-	echo askdjhaskjdhskj
 	$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
 
 $(TARGET): $(OBJ)
@@ -210,6 +241,16 @@ $(INTEGRATIONTEST_COBJ):
 	@$(CC) -c $(TESTFLAGS) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
 	$(CC) -c $(TESTFLAGS) -o $@  $(subst $(INTEGRATIONTEST_C_OBJ_DIR), ,$(@:%.o=%.c))
 
+$(INTEGRATIONTEST_TRANSPORT_CPPOBJ):
+	- @mkdir -p $(@D)
+	@$(CPP) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
+	$(CPP) -c $(TESTFLAGS_TRANSPORT) -o $@  $(subst $(INTEGRATIONTEST_CPP_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.cpp))
+
+$(INTEGRATIONTEST_TRANSPORT_COBJ):
+	- @mkdir -p $(@D)
+	@$(CC) -c $(TESTFLAGS_TRANSPORT) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
+	$(CC) -c $(TESTFLAGS_TRANSPORT) -o $@  $(subst $(INTEGRATIONTEST_C_OBJ_DIR_TRANSPORT), ,$(@:%.o=%.c))
+
 $(INTEGRATIONTEST_AUTH_CPPOBJ):
 	- @mkdir -p $(@D)
 	@$(CPP) -c $(TESTFLAGS_AUTH) $(DEPEND) -o $(@:%.o=%.d) $(subst $(INTEGRATIONTEST_AUTH_CPP_OBJ_DIR), ,$(@:%.o=%.cpp))

+ 0 - 0
python_driver/__init__.py


+ 265 - 0
python_driver/shellmatta_transport.py

@@ -0,0 +1,265 @@
+""" Python module to handle the shellmatta transport layer """
+
+from crccheck.crc import Crc32
+import struct
+
+class ShellmattaTransport():
+    """ Class to handle the shellmatta transport layer """
+
+    class Packet():
+        """ A shellmatta packet structure """
+
+        HEADER_LENGTH = 8
+        MAX_PAYLOAD_LENGTH = 255
+        CRC_LENGTH = 4
+
+        SOH                         = 1
+        PROTOCOL_VERSION            = 1
+
+        TYPE_DATA                   = 0
+        TYPE_SEQ_CNT_REQUEST        = 1
+        TYPE_SEQ_CNT_RESPOND        = 129
+        TYPE_MAX_BUFFERSIZE_REQUEST = 2
+        TYPE_MAX_BUFFERSIZE_RESPOND = 130
+        TYPE_SEARCH_DEVICE_REQUEST  = 3
+        TYPE_SEARCH_DEVICE_RESPOND  = 131
+        TYPE_SET_ADDRESS_REQUEST    = 4
+        TYPE_SET_ADDRESS_RESPOND    = 132
+
+        def __init__(self,
+                     start_of_header,
+                     protocol_version,
+                     packet_type,
+                     payload_length,
+                     source,
+                     destination,
+                     sequence_h2s,
+                     sequence_s2h,
+                     payload=b'',
+                     crc=0,
+                     crc_fct=Crc32.calc):
+            """ creates a shellmatta transport packet based on the passed data """
+
+            self.start_of_header    = start_of_header
+            self.protocol_version   = protocol_version
+            self.packet_type        = packet_type
+            self.payload_length     = payload_length
+            self.source             = source
+            self.destination        = destination
+            self.sequence_h2s       = sequence_h2s
+            self.sequence_s2h       = sequence_s2h
+            self.payload            = payload
+            self.crc                = crc
+            self.crc_fct            = crc_fct
+
+        @classmethod
+        def from_header_data(cls, header_data):
+            """ create an empty packet based on raw header data """
+
+            if not header_data or len(header_data) != cls.HEADER_LENGTH:
+                raise ValueError("A shellmatta transport packet needs 8 data bytes as a header.")
+
+            data = struct.unpack('BBBBBBBB', header_data)
+            return cls(*data)
+
+        def set_payload(self, payload):
+            """ sets/replaces the complete payload of the packet """
+
+            if len(payload) > self.MAX_PAYLOAD_LENGTH:
+                raise ValueError("Payload size exceeds limit!")
+            self.payload = payload
+            self.payload_length = len(self.payload)
+
+        def append_payload(self, payload):
+            """ append passed payload to the packet """
+
+            if len(payload) + self.payload_length > self.MAX_PAYLOAD_LENGTH:
+                raise ValueError("Payload size exceeds limit!")
+            self.payload += payload
+            self.payload_length = len(self.payload)
+
+        def calc_crc(self):
+            """ Calculates the crc checksum """
+
+            return self.crc_fct(bytes(self)[:-4])
+
+        def secure(self):
+            """ Calculates the crc checksum """
+
+            self.crc = self.calc_crc()
+
+        def verify(self, crc):
+            """ Checks the packet agains the passed crc """
+
+            return crc == self.calc_crc()
+
+        def __bytes__(self):
+            """ Create binary representation of the packet """
+
+            # pack header
+            raw_buffer = struct.pack('BBBBBBBB',
+                                     self.start_of_header,
+                                     self.protocol_version,
+                                     self.packet_type,
+                                     self.payload_length,
+                                     self.source,
+                                     self.destination,
+                                     self.sequence_h2s,
+                                     self.sequence_s2h)
+            raw_buffer += self.payload
+            raw_buffer += self.crc.to_bytes(4, 'big')
+            return raw_buffer
+
+    def __init__(self, com_obj, mandatory=False, custom_crc=Crc32.calc):
+        self.com_obj = com_obj
+        self.mandatory = mandatory
+        self.custom_crc = custom_crc
+        self.sequence_counter_h2s = 0
+        self.sequence_counter_s2h = 0
+        self.received_raw_buffer = b''
+        self.received_packet = None
+        self.received_buffer = b''
+
+    def __send(self, packet_type, data, destination=0):
+        """ Sends data to the shellmatta - splitting at max size
+
+        Args:
+            packet_type (int): type of packet to send
+            data (bytestring): string of data to send
+        """
+        while len(data) > 0:
+            packet = self.Packet(self.Packet.SOH,
+                                self.Packet.PROTOCOL_VERSION,
+                                packet_type,
+                                min(len(data), self.Packet.MAX_PAYLOAD_LENGTH),
+                                0,
+                                destination,
+                                self.sequence_counter_h2s,
+                                self.sequence_counter_s2h,
+                                data[:self.Packet.MAX_PAYLOAD_LENGTH],
+                                crc_fct=self.custom_crc)
+            self.sequence_counter_h2s += 1
+            packet.secure()
+            self.com_obj.write(bytes(packet))
+            data = data[self.Packet.MAX_PAYLOAD_LENGTH:]
+
+    def __peek_com(self, size):
+        """ wraps the read method to be able to peek data - leave data in buffer
+
+        Args:
+            size(integer) : number of bytes to peek"""
+        if len(self.received_raw_buffer) < size:
+            received_data = self.com_obj.read(size - len(self.received_raw_buffer))
+            self.received_raw_buffer += received_data
+
+            if len(self.received_raw_buffer) < size:
+                raise TimeoutError("No response from Shellmatta")
+
+        # return the requested data from the buffer
+        data = self.received_raw_buffer[:size]
+
+        return data
+
+    def __read_com(self, size):
+        """ wraps the read method - removes read data from the bufffer
+
+        Args:
+            size(integer) : number of bytes to read"""
+
+        # return the requested data from the buffer
+        data = self.__peek_com(size)
+        self.received_raw_buffer = self.received_raw_buffer[size:]
+
+        return data
+
+    def __process_reception(self):
+        """ try to read a complete telegram from the shellmatta """
+
+        data = self.__peek_com(1)
+        success = False
+
+        # start parsing transport layer telegram
+        if int(data[0]) == self.Packet.SOH:
+
+            # process the header
+            data = self.__peek_com(self.Packet.HEADER_LENGTH)
+            packet = self.Packet.from_header_data(data)
+
+            # read complete packet
+            packet_size = self.Packet.HEADER_LENGTH + packet.payload_length + self.Packet.CRC_LENGTH
+            packet_data = self.__peek_com(packet_size)
+            packet.set_payload(packet_data[self.Packet.HEADER_LENGTH:-self.Packet.CRC_LENGTH])
+
+            # verify crc
+            crc = int.from_bytes(packet_data[-self.Packet.CRC_LENGTH:], 'big', signed=False)
+            success = packet.verify(crc)
+
+            if success:
+
+                # remove the packet from the raw buffer
+                self.__read_com(packet_size)
+
+                if packet.packet_type == packet.TYPE_DATA:
+                    self.received_buffer += packet.payload
+
+        # process invalid bytes
+        if not success:
+            if not self.mandatory:
+                # append the received SOH directly to the buffer
+                self.received_buffer += self.__read_com(1)
+            else:
+                # throw away the SOH byte
+                self.__read_com(1)
+
+    def write(self, data):
+        """ Send data using the transport layer
+
+        Args:
+            data (bytes): data to send to shellmatta
+        """
+
+        if not isinstance(data, bytes):
+            raise ValueError("data must be od type bytes")
+        self.__send(self.Packet.TYPE_DATA, data)
+
+    def write_manual(self, data):
+        """Send data as if it was written by manual input. Will not use transport layer protocol.
+
+        Args:
+            data (string): String to send to shellmatta
+        """
+        if not isinstance(data, bytes):
+            raise ValueError("data must be od type bytes")
+        self.com_obj.write(data)
+
+    def read(self, size=1):
+        """ Reads size bytes from the shellmatta transport layer
+
+        Args:
+            size (integer): number of bytes to read
+        """
+        try:
+            while len(self.received_buffer) < size:
+                self.__process_reception()
+        except TimeoutError:
+            pass
+
+        data = self.received_buffer[:size]
+        self.received_buffer = self.received_buffer[size:]
+
+        return data
+
+    def reset(self):
+        """ resets all internal states and flush the counterpart """
+        self.sequence_counter_h2s = 0
+        self.sequence_counter_s2h = 0
+        self.received_raw_buffer = b''
+        self.received_packet = None
+        self.received_buffer = b''
+        # flush the buffer and send one cancel
+        self.com_obj.write(b'\x00' * (self.Packet.MAX_PAYLOAD_LENGTH + 12))
+        self.write(b'\x03')
+
+    def close(self):
+        """ Close port """
+        self.reset()

+ 115 - 0
python_driver/shellmatta_transport_serial.py

@@ -0,0 +1,115 @@
+""" Wrapper arount a shellmatta with transport layer to send commands and receive the response """
+
+import time
+import serial
+import argparse
+from shellmatta_transport import ShellmattaTransport
+
+class ShellmattaSerial():
+    """ Helper class to communicate with a shellmatta enabled device """
+
+
+    def __init__(self, com_port, baudrate=115200, prompt="->", timeout=1, transport_layer_mandatory=False):
+        """ create the transport layer instance using the passed com port """
+        self.prompt = prompt
+        self.com = com_port
+        self.com_port = serial.Serial(com_port, baudrate=baudrate, timeout=timeout)
+
+        self.transport = ShellmattaTransport(self.com_port, transport_layer_mandatory)
+
+    def send_command(self, command):
+        """ Send command and wait for the prompt in the response. """
+
+        if isinstance(command, str):
+            send_data = str.encode(command)
+        else:
+            send_data = command
+
+        retries = 3
+
+        while retries:
+            send_data = send_data + b"\r"
+            self.transport.write(send_data)
+            data = b''
+
+            while True:
+                data += self.transport.read()
+
+                if data.endswith(str.encode(self.prompt)):
+                    # return received string without echo and prompt
+                    data = data[:-len(str.encode(self.prompt))]
+                    if data.startswith(send_data):
+
+                        data = data[len(send_data):]
+
+                    break
+
+            # todo implement proper retries / sequence checking
+            if b"crc error\r\n" not in data:
+                break
+
+            retries -= 1
+
+        return data
+
+    def send_command_only(self, command):
+        """ Send command without waiting for response. """
+
+        send_string = command + "\r"
+        self.transport.write(str.encode(send_string))
+
+    def send_raw(self, data):
+        """ Send a passed bytes string without any mercy. """
+
+        self.transport.write_manual(data)
+
+    def reset_communication(self):
+        """ Clears all internal buffers, throwing away all data. """
+        self.transport.reset()
+        self.com_port.flush()
+
+        self.com_port.reset_input_buffer()
+        self.com_port.reset_output_buffer()
+
+    def close_serial(self):
+        """ Closes the serial port """
+        self.com_port.close()
+
+    def set_baudrate(self, baud):
+        """ Set the baudrate of the serial port """
+        self.com_port.baudrate = baud
+        self.com_port.close()
+        time.sleep(0.5)
+
+        self.com_port = serial.Serial(self.com, baudrate=baud, timeout=self.com_port.timeout)
+        self.transport.close()
+        self.transport = ShellmattaTransport(self.com_port,
+                                             False,
+                                             None)
+
+# start interactive mode if not used as a module
+if __name__ == "__main__":
+
+    # setup an argument parser
+    parser = argparse.ArgumentParser()
+    parser.add_argument("-c", "--com-port", dest="com_port", help="Com port to use.", required=True)
+    parser.add_argument("-b", "--baudrate", dest="baudrate", help="Baudrate to use.", type=int, default=115200)
+    parser.add_argument("-p", "--prompt",   dest="prompt",   help="Prompt text of the shellmatta instance.", default="->")
+    parser.add_argument("-t", "--timeout",  dest="timeout",  help="Timeout on the com port.", type=float, default=0.1)
+    parser.add_argument("-m", "--mandatory", dest="mandatory", help="Force transport layer usage.", default=True)
+    args = parser.parse_args()
+
+    # get our own shellmatta serial instance
+    shellmatta = ShellmattaSerial(args.com_port,
+                                  args.baudrate,
+                                  args.prompt,
+                                  args.timeout,
+                                  args.mandatory)
+
+    shellmatta.reset_communication()
+
+    # process user input
+    print("Shellmatta Transport Serial wrapper - type commands as you like:")
+    while True:
+        command = input()
+        print(shellmatta.send_command(command))

+ 407 - 328
src/shellmatta.c

@@ -23,14 +23,382 @@
 #include "shellmatta_utils.h"
 #include "shellmatta_escape.h"
 #include "shellmatta_opt.h"
+#ifdef SHELLMATTA_TRANSPORT
+#include "shellmatta_transport.h"
+#endif
 #ifdef SHELLMATTA_AUTHENTICATION
 #include "shellmatta_auth.h"
 #endif
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
 
+/**
+ * @brief       processes the passed amount of data - called from the transport layer
+ * @param[in]   handle  shellmatta instance handle
+ * @param[in]   data    pointer to input data to process
+ * @param[in]   size    length of input data to process
+ * @return      errorcode   #SHELLMATTA_OK
+ *                          #SHELLMATTA_USE_FAULT
+ */
+static shellmatta_retCode_t shellmatta_processDataInt(shellmatta_handle_t     handle,
+                                                      char                    *data,
+                                                      uint32_t                 size)
+{
+    shellmatta_cmd_t        *cmd;
+    uint8_t                 cmdExecuted = 0u;
+    uint32_t                cmdLen;
+    char                    *tempString;
+
+    shellmatta_retCode_t    ret = SHELLMATTA_OK;
+    shellmatta_retCode_t    cmdRet;
+    shellmatta_instance_t   *inst = (shellmatta_instance_t*)handle;
+
+    /** -# in busy mode - keep calling this command */
+    if(NULL != inst->busyCmd)
+    {
+        /** -# just call the function until it is not busy anymore */
+        (void)shellmatta_opt_reInit(inst);
+        ret = inst->busyCmd->cmdFct(handle, inst->buffer, inst->inputCount);
+
+        if(SHELLMATTA_BUSY == ret)
+        {
+            /** -# do nothing - still busy */
+        }
+        else if(SHELLMATTA_CONTINUE == ret)
+        {
+            inst->continuousCmd = inst->busyCmd;
+            inst->busyCmd       = NULL;
+        }
+        else
+        {
+            utils_terminateInput(inst);
+        }
+    }
+    /** -# call continuous function even if there is no data */
+    else if((0u == size) && (NULL != inst->continuousCmd))
+    {
+        /** -# just call the function without any new data */
+        inst->stdinLength               = 0u;
+        inst->buffer[inst->stdinIdx]    = '\0';
+        (void)shellmatta_opt_reInit(inst);
+        ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
+
+        if(SHELLMATTA_CONTINUE == ret)
+        {
+            /** -# do nothing just continue */
+        }
+        else if(SHELLMATTA_BUSY == ret)
+        {
+            inst->busyCmd       = inst->continuousCmd;
+            inst->continuousCmd = NULL;
+        }
+        else
+        {
+            utils_terminateInput(inst);
+        }
+    }
+    else
+    {
+        /* nothing to do here - continue parsing the command */
+    }
+
+    /** -# process byte wise */
+    for (; (inst->byteCounter < size) && (NULL == inst->busyCmd); inst->byteCounter++)
+    {
+        /** -# in continuous mode - pass data directly to the command */
+        if(NULL != inst->continuousCmd)
+        {
+            /** -# copy data and call command function */
+            inst->buffer[inst->stdinIdx]        = data[inst->byteCounter];
+            inst->buffer[inst->stdinIdx + 1u]   = '\0';
+            inst->stdinLength                   = 1u;
+            (void)shellmatta_opt_reInit(inst);
+            ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
+            
+            /** -# check if continuous mode is canceled or interrupted by busy mode */
+            if(SHELLMATTA_BUSY == ret)
+            {
+                inst->busyCmd 	= inst->continuousCmd;
+                inst->continuousCmd = NULL;
+            }
+            else if(('\x03' == data[inst->byteCounter]))
+            {
+                /** -# cancel continue session */
+                utils_terminateInput(inst);
+                ret = SHELLMATTA_OK;
+            }
+            else if(SHELLMATTA_CONTINUE == ret)
+            {
+                /** -# do nothing - continue */
+            }
+            else
+            {
+                utils_terminateInput(inst);
+            }
+        }
+        /** -# handle escape sequences */
+        else if(inst->escapeCounter != 0u)
+        {
+            escape_handleSequence(inst, data[inst->byteCounter]);
+        }
+        /** -# handle delimiter as start of processing the command */
+        else if (inst->delimiter == data[inst->byteCounter])
+        {
+            if(0u == inst->hereLength)
+            {
+                /**
+                     *  @dot
+                     *  digraph heredocParser {
+                     *      start -> wait [ label="<< in first line - store delimiter" ];
+                     *      wait -> wait [ label="delimiter not detected" ];
+                     *      wait -> end [ label="delimiter found - remove all heredoc stuff and send the input to the command" ];
+                     *  }
+                     *  @enddot */
+
+                /** -# check for heredoc - add string delimiter to stop strstr from searching too far */
+                inst->buffer[inst->inputCount] = '\0';
+                tempString = strstr(inst->buffer, "<<");
+                if(NULL != tempString)
+                {
+                    /*' -# check if length of heredoc delimiter is valid */
+                    if(inst->inputCount > ((uint32_t)(tempString - inst->buffer) + 2u))
+                    {
+                        inst->hereStartIdx      = (uint32_t)(tempString - inst->buffer);
+                        inst->hereDelimiterIdx  = inst->hereStartIdx + 2u;
+                        while((inst->hereDelimiterIdx < inst->inputCount)
+                                && (    ('\0' == inst->buffer[inst->hereDelimiterIdx])
+                                    ||  (' '  == inst->buffer[inst->hereDelimiterIdx])))
+                        {
+                            inst->hereDelimiterIdx ++;
+                        }
+
+                        inst->hereLength = inst->inputCount - inst->hereDelimiterIdx;
+
+                        inst->dirty = true;
+                        utils_insertChars(inst, &data[inst->byteCounter], 1u);
+                        inst->lastNewlineIdx = inst->inputCount;
+                    }
+                    else
+                    {
+                        inst->hereLength    = 0u;
+
+                        /** -# store the current command and reset the history buffer */
+                        inst->dirty = true;
+                        history_storeCmd(inst);
+                        history_reset(inst);
+                    }
+                }
+                else
+                {
+                    /** -# store the current command and reset the history buffer */
+                    inst->dirty = true;
+                    history_storeCmd(inst);
+                    history_reset(inst);
+                }
+            }
+            else
+            {
+                tempString  = &inst->buffer[inst->lastNewlineIdx];
+                cmdLen      = inst->inputCount - inst->lastNewlineIdx;
+
+                /** -# skip newline characters before comparison */
+                while(('\n' == *tempString) || ('\r' == *tempString))
+                {
+                    tempString ++;
+                    cmdLen --;
+                }
+
+                if(     (inst->hereLength == cmdLen)
+                    &&  (0  == strncmp( &inst->buffer[inst->hereDelimiterIdx],
+                                        tempString,
+                                        inst->hereLength)))
+                {
+                    /** -# store the current command and reset the history buffer */
+                    inst->dirty = true;
+                    history_storeCmd(inst);
+                    history_reset(inst);
+
+                    /** -# process heredoc as stdin like input  */
+                    /** -# find start of heredoc data           */
+                    inst->stdinIdx = inst->hereDelimiterIdx + inst->hereLength;
+                    while(      ('\n' == inst->buffer[inst->stdinIdx])
+                            ||  ('\r' == inst->buffer[inst->stdinIdx]))
+                    {
+                        inst->stdinIdx ++;
+                    }
+                    /** -# calculate length and terminate stdin string */
+                    if(inst->stdinIdx < inst->lastNewlineIdx)
+                    {
+                        inst->stdinLength = inst->lastNewlineIdx - inst->stdinIdx;
+                        inst->buffer[inst->lastNewlineIdx] = '\0';
+                    }
+                    else
+                    {
+                        inst->stdinLength = 0u;
+                    }
+
+                    /** -# calculate length and terminate argument string */
+                    inst->inputCount = inst->hereStartIdx;
+                    inst->buffer[inst->hereStartIdx] = '\0';
+
+                    /** -# terminate heredoc session */
+                    inst->hereLength = 0u;
+                }
+                else
+                {
+                    /** -# the party goes on - just print the delimiter and store the position */
+                    inst->lastNewlineIdx = inst->inputCount;
+                    utils_insertChars(inst, &data[inst->byteCounter], 1u);
+                }
+            }
+
+            if(0u == inst->hereLength)
+            {
+                cmd = inst->cmdList;
+
+                /** -# determine the cmd len (chars until first space or \0 is found */
+                cmdLen = 0u;
+                while(      (cmdLen <   inst->inputCount)
+                        &&  (' '    !=  inst->buffer[cmdLen])
+                        &&  ('\r'   !=  inst->buffer[cmdLen])
+                        &&  ('\n'   !=  inst->buffer[cmdLen])
+                        &&  ('\0'   !=  inst->buffer[cmdLen]))
+                {
+                    cmdLen ++;
+                }
+
+                /** -# search for a matching command */
+                while (NULL != cmd)
+                {
+                    /** -# compare command and alias string and length */
+                    if (    ((cmdLen    == strlen(cmd->cmd))
+                            && (0       == strncmp(inst->buffer, cmd->cmd, cmdLen)))
+                        || ((NULL != cmd->cmdAlias)
+                            && (cmdLen  == strlen(cmd->cmdAlias))
+                            && (0       == strncmp(inst->buffer, cmd->cmdAlias, cmdLen))))
+                    {
+                        utils_writeEcho(inst, "\r\n", 2u);
+                        shellmatta_opt_init(inst, cmdLen + 1u);
+
+#ifdef SHELLMATTA_AUTHENTICATION
+                        cmdRet = SHELLMATTA_OK;
+                        if (SHELLMATTA_OK == shellmatta_auth_is_cmd_permitted(inst, cmd))
+                        {
+                            cmdExecuted = 1u;
+                            cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
+                        }
+
+#else
+                        cmdExecuted = 1u;
+                        cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
+#endif
+
+                        switch(cmdRet)
+                        {
+                            case SHELLMATTA_CONTINUE:
+                                /** -# initialize stdin buffer and continuous cmd */
+                                inst->stdinIdx      = inst->bufferSize - 2u;
+                                inst->stdinLength   = 0u;
+                                inst->continuousCmd = cmd;
+                                ret                 = cmdRet;
+                                break;
+                            
+                            case SHELLMATTA_BUSY:
+                                inst->busyCmd   = cmd;
+                                ret             = cmdRet;
+                                break;
+
+                            default:
+                                /* nothing to do - everything ok */
+                                break;
+                        }
+                        cmd = NULL;
+                    }
+                    else
+                    {
+                        cmd = cmd->next;
+                    }
+                }
+
+                if ((0u == cmdExecuted) && (inst->inputCount > 0))
+                {
+                    if (inst->echoEnabled)
+                    {
+                        inst->write("\r\nCommand: ", 11u);
+                        inst->write(inst->buffer, inst->inputCount);
+                        inst->write(" not found", 10u);
+                    }
+                    else
+                    {
+                        inst->write("\r\nCommand not found!", 20u);
+                    }
+                }
+
+                /** -# terminate this session if no continuous mode is requested */
+                if(     (NULL == inst->continuousCmd)
+                    &&  (NULL == inst->busyCmd))
+                {
+                    utils_terminateInput(inst);
+                }
+            }
+        }
+        /** -# ignore newline as first character (to be compatible to
+         * terminals sending newline after return */
+        else if((0u == inst->inputCount) && ('\n' == data[inst->byteCounter]))
+        {
+            /* do nothing */
+        }
+        /** -# check for tabulator key - auto complete */
+        else if('\t' == data[inst->byteCounter])
+        {
+            inst->dirty = true;
+            autocomplete_run(inst);
+        }
+        /** -# check for cancel -
+         *      terminate current input and print prompt again */
+        else if('\x03' == data[inst->byteCounter])
+        {
+            inst->dirty = false;
+            history_reset(inst);
+            utils_terminateInput(inst);
+        }
+        /** -# check for backspace */
+        else if(    ('\b'   == data[inst->byteCounter])
+                ||  ('\x7f' == data[inst->byteCounter]))
+        {
+            inst->dirty = true;
+            utils_removeChars(inst, 1u, true);
+        }
+        /** -# check for start of escape sequence */
+        else if('\x1b' == data[inst->byteCounter])
+        {
+            inst->escapeCounter = 1u;
+        }
+        else
+        {
+            inst->dirty = true;
+            utils_insertChars(inst, &data[inst->byteCounter], 1u);
+        }
+
+        /** -# reset tab counter on not a tab */
+        if ('\t' != data[inst->byteCounter])
+        {
+            inst->tabCounter = 0u;
+        }
+    }
+
+    /** -# initialize the byte buffer if processing of the input is finished */
+    if(ret != SHELLMATTA_BUSY)
+    {
+        inst->byteCounter = 0u;
+    }
+
+    return ret;
+}
+
 /**
  * @}
  * @addtogroup shellmatta_api
@@ -113,6 +481,12 @@ shellmatta_retCode_t shellmatta_doInit(
         inst->magic = SHELLMATTA_MAGIC;
         *handle     = (shellmatta_handle_t)inst;
 
+#ifdef SHELLMATTA_TRANSPORT
+        /* init transport layer */
+        inst->transportBusyMark = 0u;
+        shellmatta_transport_init(&inst->transportLayer, inst->write);
+#endif
+
         /** -# print the first prompt */
         utils_terminateInput(inst);
     }
@@ -388,363 +762,68 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
                                             char                    *data,
                                             uint32_t                 size)
 {
-    shellmatta_cmd_t        *cmd;
-    uint8_t                 cmdExecuted = 0u;
-    uint32_t                cmdLen;
-    char                    *tempString;
-
-    shellmatta_retCode_t    ret = SHELLMATTA_OK;
-    shellmatta_retCode_t    cmdRet;
+    shellmatta_retCode_t    ret   = SHELLMATTA_OK;
     shellmatta_instance_t   *inst = (shellmatta_instance_t*)handle;
+#ifdef SHELLMATTA_TRANSPORT
+    char                    *tmpData;
+    uint32_t                tmpSize = 0;
+    uint32_t                i;
+    bool                    processingDone = false;
+#endif
 
     /** -# check parameters for plausibility  */
     if(     (NULL               != inst)
         &&  (SHELLMATTA_MAGIC   == inst->magic))
     {
-        /** -# in busy mode - keep calling this command */
-        if(NULL != inst->busyCmd)
+#ifdef SHELLMATTA_TRANSPORT
+        for (i = inst->transportBusyMark; i < size; i ++)
         {
-            /** -# just call the function until it is not busy anymore */
-            (void)shellmatta_opt_reInit(inst);
-            ret = inst->busyCmd->cmdFct(handle, inst->buffer, inst->inputCount);
-
-            if(SHELLMATTA_BUSY == ret)
-            {
-                /** -# do nothing - still busy */
-            }
-            else if(SHELLMATTA_CONTINUE == ret)
-            {
-                inst->continuousCmd = inst->busyCmd;
-                inst->busyCmd       = NULL;
-            }
-            else
+            ret = shellmatta_transport_process(&inst->transportLayer, data[i], &tmpData, &tmpSize);
+            if (SHELLMATTA_OK == ret)
             {
-                utils_terminateInput(inst);
-            }
-        }
-        /** -# call continuous function even if there is no data */
-        else if((0u == size) && (NULL != inst->continuousCmd))
-        {
-            /** -# just call the function without any new data */
-            inst->stdinLength               = 0u;
-            inst->buffer[inst->stdinIdx]    = '\0';
-            (void)shellmatta_opt_reInit(inst);
-            ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
-
-            if(SHELLMATTA_CONTINUE == ret)
-            {
-                /** -# do nothing just continue */
-            }
-            else if(SHELLMATTA_BUSY == ret)
-            {
-                inst->busyCmd       = inst->continuousCmd;
-                inst->continuousCmd = NULL;
-            }
-            else
-            {
-                utils_terminateInput(inst);
-            }
-        }
-        else
-        {
-            /* nothing to do here - continue parsing the command */
-        }
+                ret = shellmatta_processDataInt(handle, tmpData, tmpSize);
+                processingDone = true;
 
-        /** -# process byte wise */
-        for (; (inst->byteCounter < size) && (NULL == inst->busyCmd); inst->byteCounter++)
-        {
-            /** -# in continuous mode - pass data directly to the command */
-            if(NULL != inst->continuousCmd)
-            {
-                /** -# copy data and call command function */
-                inst->buffer[inst->stdinIdx]        = data[inst->byteCounter];
-                inst->buffer[inst->stdinIdx + 1u]   = '\0';
-                inst->stdinLength                   = 1u;
-                (void)shellmatta_opt_reInit(inst);
-                ret = inst->continuousCmd->cmdFct(handle, inst->buffer, inst->inputCount);
-                
-                /** -# check if continuous mode is canceled or interrupted by busy mode */
-                if(SHELLMATTA_BUSY == ret)
-                {
-                    inst->busyCmd 	= inst->continuousCmd;
-                    inst->continuousCmd = NULL;
-                }
-                else if(('\x03' == data[inst->byteCounter]))
+                if (SHELLMATTA_BUSY == ret)
                 {
-                    /** -# cancel continue session */
-                    utils_terminateInput(inst);
-                    ret = SHELLMATTA_OK;
-                }
-                else if(SHELLMATTA_CONTINUE == ret)
-                {
-                    /** -# do nothing - continue */
-                }
-                else
-                {
-                    utils_terminateInput(inst);
-                }
-            }
-            /** -# handle escape sequences */
-            else if(inst->escapeCounter != 0u)
-            {
-                escape_handleSequence(inst, data[inst->byteCounter]);
-            }
-            /** -# handle delimiter as start of processing the command */
-            else if (inst->delimiter == data[inst->byteCounter])
-            {
-                if(0u == inst->hereLength)
-                {
-                    /**
-                      *  @dot
-                      *  digraph heredocParser {
-                      *      start -> wait [ label="<< in first line - store delimiter" ];
-                      *      wait -> wait [ label="delimiter not detected" ];
-                      *      wait -> end [ label="delimiter found - remove all heredoc stuff and send the input to the command" ];
-                      *  }
-                      *  @enddot */
-
-                    /** -# check for heredoc - add string delimiter to stop strstr from searching too far */
-                    inst->buffer[inst->inputCount] = '\0';
-                    tempString = strstr(inst->buffer, "<<");
-                    if(NULL != tempString)
-                    {
-                        /*' -# check if length of heredoc delimiter is valid */
-                        if(inst->inputCount > ((uint32_t)(tempString - inst->buffer) + 2u))
-                        {
-                            inst->hereStartIdx      = (uint32_t)(tempString - inst->buffer);
-                            inst->hereDelimiterIdx  = inst->hereStartIdx + 2u;
-                            while((inst->hereDelimiterIdx < inst->inputCount)
-                                    && (    ('\0' == inst->buffer[inst->hereDelimiterIdx])
-                                        ||  (' '  == inst->buffer[inst->hereDelimiterIdx])))
-                            {
-                                inst->hereDelimiterIdx ++;
-                            }
-
-                            inst->hereLength = inst->inputCount - inst->hereDelimiterIdx;
-
-                            inst->dirty = true;
-                            utils_insertChars(inst, &data[inst->byteCounter], 1u);
-                            inst->lastNewlineIdx = inst->inputCount;
-                        }
-                        else
-                        {
-                            inst->hereLength    = 0u;
-
-                            /** -# store the current command and reset the history buffer */
-                            inst->dirty = true;
-                            history_storeCmd(inst);
-                            history_reset(inst);
-                        }
-                    }
-                    else
-                    {
-                        /** -# store the current command and reset the history buffer */
-                        inst->dirty = true;
-                        history_storeCmd(inst);
-                        history_reset(inst);
-                    }
+                    inst->transportBusyMark = i;
+                    break;
                 }
                 else
                 {
-                    tempString  = &inst->buffer[inst->lastNewlineIdx];
-                    cmdLen      = inst->inputCount - inst->lastNewlineIdx;
-
-                    /** -# skip newline characters before comparison */
-                    while(('\n' == *tempString) || ('\r' == *tempString))
-                    {
-                        tempString ++;
-                        cmdLen --;
-                    }
-
-                    if(     (inst->hereLength == cmdLen)
-                        &&  (0  == strncmp( &inst->buffer[inst->hereDelimiterIdx],
-                                            tempString,
-                                            inst->hereLength)))
-                    {
-                        /** -# store the current command and reset the history buffer */
-                        inst->dirty = true;
-                        history_storeCmd(inst);
-                        history_reset(inst);
-
-                        /** -# process heredoc as stdin like input  */
-                        /** -# find start of heredoc data           */
-                        inst->stdinIdx = inst->hereDelimiterIdx + inst->hereLength;
-                        while(      ('\n' == inst->buffer[inst->stdinIdx])
-                                ||  ('\r' == inst->buffer[inst->stdinIdx]))
-                        {
-                            inst->stdinIdx ++;
-                        }
-                        /** -# calculate length and terminate stdin string */
-                        if(inst->stdinIdx < inst->lastNewlineIdx)
-                        {
-                            inst->stdinLength = inst->lastNewlineIdx - inst->stdinIdx;
-                            inst->buffer[inst->lastNewlineIdx] = '\0';
-                        }
-                        else
-                        {
-                            inst->stdinLength = 0u;
-                        }
-
-                        /** -# calculate length and terminate argument string */
-                        inst->inputCount = inst->hereStartIdx;
-                        inst->buffer[inst->hereStartIdx] = '\0';
-
-                        /** -# terminate heredoc session */
-                        inst->hereLength = 0u;
-                    }
-                    else
-                    {
-                        /** -# the party goes on - just print the delimiter and store the position */
-                        inst->lastNewlineIdx = inst->inputCount;
-                        utils_insertChars(inst, &data[inst->byteCounter], 1u);
-                    }
-                }
-
-                if(0u == inst->hereLength)
-                {
-                    cmd = inst->cmdList;
-
-                    /** -# determine the cmd len (chars until first space or \0 is found */
-                    cmdLen = 0u;
-                    while(      (cmdLen <   inst->inputCount)
-                            &&  (' '    !=  inst->buffer[cmdLen])
-                            &&  ('\r'   !=  inst->buffer[cmdLen])
-                            &&  ('\n'   !=  inst->buffer[cmdLen])
-                            &&  ('\0'   !=  inst->buffer[cmdLen]))
-                    {
-                        cmdLen ++;
-                    }
-
-                    /** -# search for a matching command */
-                    while (NULL != cmd)
-                    {
-                        /** -# compare command and alias string and length */
-                        if (    ((cmdLen    == strlen(cmd->cmd))
-                                && (0       == strncmp(inst->buffer, cmd->cmd, cmdLen)))
-                            || ((NULL != cmd->cmdAlias)
-                                && (cmdLen  == strlen(cmd->cmdAlias))
-                                && (0       == strncmp(inst->buffer, cmd->cmdAlias, cmdLen))))
-                        {
-                            utils_writeEcho(inst, "\r\n", 2u);
-                            shellmatta_opt_init(inst, cmdLen + 1u);
-
-#ifdef SHELLMATTA_AUTHENTICATION
-                            cmdRet = SHELLMATTA_OK;
-                            if (SHELLMATTA_OK == shellmatta_auth_is_cmd_permitted(inst, cmd))
-                            {
-                                cmdExecuted = 1u;
-                                cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
-                            }
-
-#else
-                            cmdExecuted = 1u;
-                            cmdRet = cmd->cmdFct(handle, inst->buffer, inst->inputCount);
-#endif
-
-                            switch(cmdRet)
-                            {
-                                case SHELLMATTA_CONTINUE:
-                                    /** -# initialize stdin buffer and continuous cmd */
-                                    inst->stdinIdx      = inst->bufferSize - 2u;
-                                    inst->stdinLength   = 0u;
-                                    inst->continuousCmd = cmd;
-                                    ret                 = cmdRet;
-                                    break;
-                                
-                                case SHELLMATTA_BUSY:
-                                    inst->busyCmd   = cmd;
-                                    ret             = cmdRet;
-                                    break;
-
-                                default:
-                                    /* nothing to do - everything ok */
-                                    break;
-                            }
-                            cmd = NULL;
-                        }
-                        else
-                        {
-                            cmd = cmd->next;
-                        }
-                    }
-
-                    if ((0u == cmdExecuted) && (inst->inputCount > 0))
-                    {
-                        if (inst->echoEnabled)
-                        {
-                            inst->write("\r\nCommand: ", 11u);
-                            inst->write(inst->buffer, inst->inputCount);
-                            inst->write(" not found", 10u);
-                        }
-                        else
-                        {
-                            inst->write("\r\nCommand not found!", 20u);
-                        }
-                    }
-
-                    /** -# terminate this session if no continuous mode is requested */
-                    if(     (NULL == inst->continuousCmd)
-                        &&  (NULL == inst->busyCmd))
-                    {
-                        utils_terminateInput(inst);
-                    }
+                    inst->transportBusyMark = 0u;
                 }
             }
-            /** -# ignore newline as first character (to be compatible to
-             * terminals sending newline after return */
-            else if((0u == inst->inputCount) && ('\n' == data[inst->byteCounter]))
-            {
-                /* do nothing */
-            }
-            /** -# check for tabulator key - auto complete */
-            else if('\t' == data[inst->byteCounter])
-            {
-                inst->dirty = true;
-                autocomplete_run(inst);
-            }
-            /** -# check for cancel -
-             *      terminate current input and print prompt again */
-            else if('\x03' == data[inst->byteCounter])
+            else if (SHELLMATTA_ERROR == ret)
             {
-                inst->dirty = false;
-                history_reset(inst);
+                utils_writeEcho(inst, "crc error\r\n", 11);
                 utils_terminateInput(inst);
             }
-            /** -# check for backspace */
-            else if(    ('\b'   == data[inst->byteCounter])
-                    ||  ('\x7f' == data[inst->byteCounter]))
-            {
-                inst->dirty = true;
-                utils_removeChars(inst, 1u, true);
-            }
-            /** -# check for start of escape sequence */
-            else if('\x1b' == data[inst->byteCounter])
-            {
-                inst->escapeCounter = 1u;
-            }
             else
             {
-                inst->dirty = true;
-                utils_insertChars(inst, &data[inst->byteCounter], 1u);
+                /* nothing to do - transport layer busy */
             }
+        }
 
-            /** -# reset tab counter on not a tab */
-            if ('\t' != data[inst->byteCounter])
-            {
-                inst->tabCounter = 0u;
-            }
+        /*! -# call the internal processing at least once - for continued and busy commands */
+        if (true != processingDone)
+        {
+            ret = shellmatta_processDataInt(handle, tmpData, 0);
         }
 
-        /** -# initialize the byte buffer if processing of the input is finished */
-        if(ret != SHELLMATTA_BUSY)
+        if (false == inst->transportLayer.disableAutoFlush)
         {
-            inst->byteCounter = 0u;
+            (void)shellmatta_transport_flush(handle);
         }
+#else
+        ret = shellmatta_processDataInt(handle, data, size);
+#endif
     }
     else
     {
         ret = SHELLMATTA_USE_FAULT;
     }
+
     return ret;
 }
 
@@ -767,7 +846,7 @@ shellmatta_retCode_t shellmatta_write(  shellmatta_handle_t handle,
         &&  (SHELLMATTA_MAGIC   == inst->magic))
     {
         /** -# pass the data to the write function of the instance  */
-        ret = inst->write(data, length);
+        ret = SHELLMATTA_WRITE(data, length);
     }
 
     return ret;
@@ -843,7 +922,7 @@ shellmatta_retCode_t shellmatta_printf( shellmatta_handle_t handle,
         }
         else
         {
-            inst->write(outputBuffer, length);
+            SHELLMATTA_WRITE(outputBuffer, length);
         }
     }
     else

+ 6 - 6
src/shellmatta_autocomplete.c

@@ -67,11 +67,11 @@ void autocomplete_run(shellmatta_instance_t *inst)
                 /** -# add newline on first find */
                 if(0u == printedLen)
                 {
-                    inst->write("\r\n", 2u);
+                    SHELLMATTA_WRITE("\r\n", 2u);
                 }
-                inst->write(cmd->cmd, strlen(cmd->cmd));
+                SHELLMATTA_WRITE(cmd->cmd, strlen(cmd->cmd));
                 printedLen += strlen(cmd->cmd);
-                inst->write("    ", 4u);
+                SHELLMATTA_WRITE("    ", 4u);
                 printedLen += 4u;
             }
             /** -# check if command alias matches the input */
@@ -82,11 +82,11 @@ void autocomplete_run(shellmatta_instance_t *inst)
                 /** -# add newline on first find */
                 if(0u == printedLen)
                 {
-                    inst->write("\r\n", 2u);
+                    SHELLMATTA_WRITE("\r\n", 2u);
                 }
-                inst->write(cmd->cmdAlias, strlen(cmd->cmdAlias));
+                SHELLMATTA_WRITE(cmd->cmdAlias, strlen(cmd->cmdAlias));
                 printedLen += strlen(cmd->cmdAlias);
-                inst->write("    ", 4u);
+                SHELLMATTA_WRITE("    ", 4u);
                 printedLen += 4u;
             }
             cmd = cmd->next;

+ 149 - 0
src/shellmatta_crc.c

@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @file    shellmatta_crc.c
+ * @brief   cyclic redundancy check functions of shellmatta
+ * @author  Simon Fischer <fischer.simon.1991@gmail.com>
+ */
+
+#include "shellmatta_crc.h"
+
+#ifndef SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
+/** \brief CRC Lookup table for 0x04c11db7 reflected */
+uint32_t crc32Table[] = {
+    0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
+    0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
+    0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+    0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
+    0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+    0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+    0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
+    0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+    0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+    0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+    0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
+    0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+    0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
+    0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
+    0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+    0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+    0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
+    0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+    0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
+    0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+    0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+    0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
+    0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
+    0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+    0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+    0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
+    0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+    0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
+    0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
+    0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+    0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
+    0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
+};
+#endif
+
+#ifdef SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
+/**
+ * @brief       Reverses bits of a value.
+ * @param[in]   x       input value
+ * @param[in]   size    amount of bits used in value
+ * @return      reversed data
+ */
+static uint32_t reverse(uint32_t x, uint32_t bits)
+{
+    x = ((x & 0x55555555u) << 1u)  | ((x & 0xAAAAAAAAu) >> 1u);
+    x = ((x & 0x33333333u) << 2u)  | ((x & 0xCCCCCCCCu) >> 2u);
+    x = ((x & 0x0F0F0F0Fu) << 4u)  | ((x & 0xF0F0F0F0u) >> 4u);
+    x = ((x & 0x00FF00FFu) << 8u)  | ((x & 0xFF00FF00u) >> 8u);
+    x = ((x & 0x0000FFFFu) << 16u) | ((x & 0xFFFF0000u) >> 16u);
+    return x >> (32u - bits);
+}
+
+
+/**
+ * @brief       Computes the crc32-checksum of a buffer. O(4n)
+ * @param[in]   data            pointer to data buffer
+ * @param[in]   size            amount of bytes to be processed
+ * @return      crc             calculated crc32 value
+ */
+static uint32_t crc32Slow(const char* data, uint32_t size)
+{
+    uint32_t i;
+    uint8_t j;
+    uint32_t polynom = reverse(CRC32_POLYNOM, 32u);
+    uint8_t pivotByte;
+
+    /* start with 0xffffffffu */
+    uint32_t crcTemp = 0xffffffffu;
+
+    for (i = 0u; i < size; i++)
+    {
+        pivotByte = data[i];
+        for (j = 0u; j < BITS_PER_BYTE; j++)
+        {
+            if ((crcTemp & 1u) != (pivotByte & 1u))
+            {
+                crcTemp = (crcTemp >> 1u) ^ polynom;
+            }
+            else
+            {
+                crcTemp >>= 1u;
+            }
+            pivotByte >>= 1u;
+        }
+    }
+
+    /* final xor */
+    crcTemp ^= 0xffffffffu;
+
+    return crcTemp;
+}
+
+#else
+/**
+ * @brief       Computes the crc32-checksum of a buffer. O(n)
+ * @param[in]   data            pointer to data buffer
+ * @param[in]   size            amount of bytes to be processed
+ * @param[in]   lookupTable     pointer to uint32_t lookup table for crc computation
+ * @return      crc             calculated crc32 value
+ */
+static uint32_t crc32Fast(const char* data, uint32_t size, const uint32_t* lookupTable)
+{
+    uint32_t i;
+    uint32_t crcTemp = 0xffffffffu;
+
+    for (i = 0u; i < size; i++)
+    {
+        uint8_t index = data[i] ^ (crcTemp & 0xffu);
+        crcTemp = lookupTable[index] ^ (crcTemp >> 8u);
+    }
+
+    return ~crcTemp;
+}
+#endif
+
+
+/**
+ * @brief       Computes the crc32-checksum of a buffer.
+ * @param[in]   data            pointer to data buffer
+ * @param[in]   size            amount of bytes to be processed
+ * @return      crc             calculated crc32 value
+ */
+uint32_t crc32Calc(const char* data, uint32_t size)
+{
+    #ifdef  SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
+        return crc32Slow(data, size);
+    #else
+        return crc32Fast(data, size, crc32Table);
+    #endif
+}

+ 25 - 0
src/shellmatta_crc.h

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @file    shellmatta_crc.h
+ * @brief   cyclic redundancy check functions of shellmatta
+ * @author  Simon Fischer <fischer.simon.1991@gmail.com>
+ */
+
+#ifndef _SHELLMATTA_CRC_H_
+#define _SHELLMATTA_CRC_H_
+
+#include <stdint.h>
+
+#define CRC32_POLYNOM   0x04c11db7u     /**< crc-32 ethernet 802.3                          */
+#define BITS_PER_BYTE   ((uint8_t)8)    /**< amount of bits per byte; to avoid magic number */
+
+uint32_t crc32Calc(const char* data, uint32_t size);
+
+#endif /* _SHELLMATTA_CRC_H_ */

+ 417 - 0
src/shellmatta_transport.c

@@ -0,0 +1,417 @@
+/*
+ * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @file    shellmatta_transport.c
+ * @brief   transport layer functions of shellmatta
+ * @author  Simon Fischer <fischer.simon.1991@gmail.com>
+ */
+#ifdef SHELLMATTA_TRANSPORT
+#include "shellmatta_transport.h"
+#include "shellmatta.h"
+#include "shellmatta_crc.h"
+#include "shellmatta_utils.h"
+#include <string.h>
+
+
+/**
+ * @brief   create a secured packet and pass it to the shellmatta write function
+ *
+ * @note    The packetType, payloadLength and payload have to be preset!
+ *
+ * @param[in, out]  transportLayer  transport layer instance to work on
+ * @param[in]       packetType      type of packet to send
+ * @param[in]       packet          packet to send
+ * @return          errorcode
+ */
+static shellmatta_retCode_t shellmatta_transport_send(shellmatta_transport_layer_t *transportLayer,
+                                                      shellmatta_transport_packet_t *packet)
+{
+    uint32_t crc;
+    char *rawPacket = (char*)packet;
+    shellmatta_transport_header_t *header = &packet->header;
+
+    /** -# fill header */
+    header->startOfHeader   = SHELLMATTA_TRANSPORT_START_OF_HEADER;
+    header->protocolVersion = SHELLMATTA_TRANSPORT_PROTOCOL_VERSION;
+    header->source          = 0;
+    header->destination     = 0;
+    header->sequenceH2S     = transportLayer->sequenceH2S;
+    header->sequenceS2H     = ++transportLayer->sequenceS2H;
+
+    crc = crc32Calc((char*) packet, SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength);
+
+    /** -# append crc to end of payload */
+    rawPacket[SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength] = (uint8_t)(crc >> 24u);
+    rawPacket[SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength + 1u] = (uint8_t)(crc >> 16u);
+    rawPacket[SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength + 2u] = (uint8_t)(crc >> 8u);
+    rawPacket[SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength + 3u] = (uint8_t)(crc);
+
+    /** -# use original write function to send full buffer */
+    return transportLayer->writeFct((char*) rawPacket,
+                                    SHELLMATTA_TRANSPORT_LENGTH_STATIC +
+                                    header->payloadLength);
+}
+
+/**
+ * @brief           Initializes the transportLayerInst
+ * @param[in, out]  transportLayer  transport layer instance to work on
+ * @param[in]       writeFct        function pointer to output function
+ * @return          errorcode       #SHELLMATTA_OK
+ */
+shellmatta_retCode_t shellmatta_transport_init( shellmatta_transport_layer_t    *transportLayer,
+                                                shellmatta_write_t              writeFct)
+{
+    /** -# clear instance and store write function */
+    memset(transportLayer, 0u, sizeof(shellmatta_transport_layer_t));
+    transportLayer->writeFct = writeFct;
+
+    return SHELLMATTA_OK;
+}
+
+/**
+ * @brief           Configures the transport layer
+ * @param[in, out]  handle              shellmatta handle of the instance
+ * @param[in]       mandatory           enforce using the transport layer
+ * @param[in]       disableAutoFlush    enforce manual flushing of the output packet
+ * @param[in]       customCrcFct        use a custom crc generation (default NULL)
+ * @return          errorcode
+ */
+shellmatta_retCode_t shellmatta_transport_configure(shellmatta_handle_t         handle,
+                                                    bool                        mandatory,
+                                                    bool                        disableAutoFlush,
+                                                    shellmatta_transport_crc_t  customCrcFct)
+{
+    shellmatta_retCode_t    ret     = SHELLMATTA_OK;
+    shellmatta_instance_t   *inst   = (shellmatta_instance_t*)handle;
+
+    /** -# check parameters for plausibility  */
+    if(     (NULL               != inst)
+        &&  (SHELLMATTA_MAGIC   == inst->magic))
+    {
+        shellmatta_transport_layer_t *transportLayer = &inst->transportLayer;
+
+        transportLayer->mandatory           = mandatory;
+        transportLayer->disableAutoFlush    = disableAutoFlush;
+        transportLayer->customCrcFct        = customCrcFct;
+
+        /** -# set the transport layer active when configured as mandatory */
+        if(true == mandatory)
+        {
+            transportLayer->active = true;
+        }
+    }
+    else
+    {
+        ret = SHELLMATTA_USE_FAULT;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief           Resets all values of tranportLayerInst except for sequence counters
+ * @param[in, out]  handle      shellmatta handle of the instance
+ * @return          errorcode
+ */
+shellmatta_retCode_t shellmatta_transport_reset(shellmatta_handle_t handle)
+{
+    shellmatta_retCode_t    ret     = SHELLMATTA_OK;
+    shellmatta_instance_t   *inst   = (shellmatta_instance_t*)handle;
+
+    /** -# check parameters for plausibility  */
+    if(     (NULL               != inst)
+        &&  (SHELLMATTA_MAGIC   == inst->magic))
+    {
+        /** -# set transport layer back to initial state */
+        shellmatta_transport_layer_t *transportLayer = &inst->transportLayer;
+
+        transportLayer->state = SHELLMATTA_TRANSPORT_STATE_WAIT;
+        transportLayer->active = transportLayer->mandatory;
+        transportLayer->headerIndex = 0u;
+        transportLayer->payloadIndex = 0u;
+        transportLayer->crcIndex = 0u;
+        memset(&transportLayer->inPacket, 0, sizeof(transportLayer->inPacket));
+        memset(&transportLayer->outPacket, 0, sizeof(transportLayer->outPacket));
+    }
+    else
+    {
+        ret = SHELLMATTA_USE_FAULT;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief           processes the passed amount of data
+ * @param[in, out]  transportLayer  transport layer instance to work on
+ * @param[in]       byte            byte to process
+ * @param[out]      data            payload of processed packet - or manual mode
+ * @param[out]      length          length of processed packet
+ * @return          errorcode       #SHELLMATTA_OK      data is returned\n
+ *                                  #SHELLMATTA_BUSY    packet reception ongoing\n
+ *                                  #SHELLMATTA_ERROR   in case of crc error
+ */
+shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t   *transportLayer,
+                                                  char                           byte,
+                                                  char                           **data,
+                                                  uint32_t                       *length)
+{
+    shellmatta_retCode_t ret = SHELLMATTA_BUSY;
+    char *rawPacket = (char*)&transportLayer->inPacket;
+    shellmatta_transport_header_t *header = &transportLayer->inPacket.header;
+    shellmatta_transport_packet_int_t intPacket;
+    uint32_t refCrc;
+
+    switch (transportLayer->state)
+    {
+    /** -# look for start of header */
+    case SHELLMATTA_TRANSPORT_STATE_WAIT:
+        /** -# if start of header is found, continue transport layer fsm */
+        if (SHELLMATTA_TRANSPORT_START_OF_HEADER == byte)
+        {
+            memset(&transportLayer->inPacket, 0, sizeof(transportLayer->inPacket));
+            transportLayer->headerIndex = 1u;
+            transportLayer->payloadIndex = 0u;
+            transportLayer->crcIndex = 0u;
+            header->startOfHeader = byte;
+            transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_HEADER;
+        }
+        else if((true == transportLayer->mandatory))
+        {
+            /** -# if transport layer is mandatory - throw away unrecognized bytes */
+            *data = transportLayer->inPacket.payload;
+            *length = 0;
+            transportLayer->active = true;
+            ret = SHELLMATTA_OK;
+        }
+        else
+        {
+            /** -# otherwise just pass the payload as is */
+            transportLayer->inPacket.payload[0] = byte;
+            *data = transportLayer->inPacket.payload;
+            *length = 1;
+            transportLayer->active = false;
+            ret = SHELLMATTA_OK;
+        }
+        break;
+
+    case SHELLMATTA_TRANSPORT_STATE_GET_HEADER:
+
+        rawPacket[transportLayer->headerIndex] = byte;
+        transportLayer->headerIndex ++;
+
+        if (transportLayer->headerIndex == SHELLMATTA_TRANSPORT_LENGTH_HEADER)
+        {
+            //TODO check for errors in header data
+            if (0u != header->payloadLength)
+            {
+                transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD;
+            }
+            else
+            {
+                transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_CRC;
+            }
+        }
+
+        break;
+
+    /** -# read payload for previously read length of payload */
+    case SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD:
+
+        transportLayer->inPacket.payload[transportLayer->payloadIndex] = byte;
+        transportLayer->payloadIndex ++;
+
+        if (transportLayer->payloadIndex >= header->payloadLength)
+        {
+            transportLayer->state = SHELLMATTA_TRANSPORT_STATE_GET_CRC;
+        }
+        break;
+
+    /** -# read crc32 for four bytes */
+    case SHELLMATTA_TRANSPORT_STATE_GET_CRC:
+
+        transportLayer->crcIndex ++;
+        transportLayer->inPacket.crc |= ((uint8_t)byte << ((SHELLMATTA_TRANSPORT_LENGTH_CRC - transportLayer->crcIndex) * 8u));
+
+        if (transportLayer->crcIndex >= SHELLMATTA_TRANSPORT_LENGTH_CRC)
+        {
+            refCrc = SHELLMATTA_TRANSPORT_CALC_CRC(transportLayer,
+                                                   rawPacket,
+                                                   SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength);
+
+            /** -# if crc is correct, further handling of data depends on type of packet */
+            if (transportLayer->inPacket.crc == refCrc)
+            {
+                transportLayer->active = true;
+
+                /* crc is correct */
+                transportLayer->sequenceH2S++;
+
+                switch (header->packetType)
+                {
+                case SHELLMATTA_TRANSPORT_PACKET_DATA:
+                    /** -# return pointer to payload and length */
+                    *data = (char*)&transportLayer->inPacket.payload;
+                    *length = header->payloadLength;
+                    ret = SHELLMATTA_OK;
+                    break;
+                
+                case SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_REQUEST:
+                    /** -# send out packet with no payload */
+                    intPacket.header.packetType = SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_RESPOND;
+                    intPacket.header.payloadLength = 0u;
+                    (void)shellmatta_transport_send(transportLayer, (shellmatta_transport_packet_t *)&intPacket);
+                    break;
+
+                case SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_RESPOND:
+                    /** -# ignore #SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_RESPOND - nothing to do */
+                    break;
+                
+                case SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_REQUEST:
+                    /** @todo implement */
+                    break;
+
+                case SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_RESPOND:
+                    /** -# ignore #SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_RESPOND - nothing to do */
+                    break;
+                
+                case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_REQUEST:
+                    /** @todo implement */
+                    break;
+                
+                case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND:
+                    /** -# ignore #SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND - nothing to do */
+                    break;
+
+                case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_REQUEST:
+                    /** @todo implement */
+                    break;
+
+                case SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND:
+                    /** -# ignore #SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND - nothing to do */
+                    break;
+
+                default:
+                    /** -# undo sequence counter increment on wrong packet type */
+                    transportLayer->sequenceH2S--;
+                    break;
+                }
+            }
+            else
+            {
+                /** -#  return error if crc is incorrect */
+                ret = SHELLMATTA_ERROR;
+            }
+
+            /** -# reset state machine */
+            transportLayer->state = SHELLMATTA_TRANSPORT_STATE_WAIT;
+        }
+        break;
+    
+    default:
+        break;
+    }
+
+    return ret;
+}
+
+/**
+ * @brief       Wrapper function for the write-function of shellmatta handle
+ * 
+ * This function is used to transmit data with the tranport layer protocol.\n
+ * The input data is copied into a new array along with the header and crc32.\n
+ * The resulting buffer is the forwarded to the original write function.\n
+ * 
+ * @note        If length of data exceeds #UINT8_MAX, data is sent in multiple packets.\n
+ * 
+ * @param[in, out]  transportLayer  transport layer instance to work on
+ * @param[in]       data            pointer to input data to process
+ * @param[in]       length          length of data to process
+ * @return          errorcode       #SHELLMATTA_OK
+ */
+shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *transportLayer,
+                                                const char* data,
+                                                uint32_t length)
+{
+    shellmatta_retCode_t ret = SHELLMATTA_OK;
+    uint32_t outPayloadLength = length;
+    shellmatta_transport_packet_t *packet = &transportLayer->outPacket;
+    shellmatta_transport_header_t *header = &transportLayer->outPacket.header;
+
+    /** -# handle data with length bigger than max length */
+    uint32_t processedLength = 0u;
+    uint32_t piledUpPayload;
+    uint32_t splitLength;
+    uint32_t restOfPayload;
+
+    /** -# foot-controlled loop to send packets without payload length */
+    do
+    {
+        piledUpPayload = header->payloadLength;
+
+        /* compute length of next payload split */
+        restOfPayload = (outPayloadLength - processedLength);
+        if (restOfPayload > (SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH - piledUpPayload))
+        {
+            splitLength = SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH - piledUpPayload;
+        }
+        else
+        {
+            splitLength = restOfPayload;
+        }
+
+        (void)memcpy(&packet->payload[piledUpPayload], &data[processedLength], splitLength);
+        header->payloadLength += splitLength;
+        processedLength += splitLength;
+
+        if(header->payloadLength >= SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH)
+        {
+            /** -# packet is full - send */
+            header->packetType = SHELLMATTA_TRANSPORT_PACKET_DATA;
+            ret = shellmatta_transport_send(transportLayer, packet);
+            header->payloadLength = 0u;
+        }
+    }
+    while (processedLength < outPayloadLength);
+    return ret;
+}
+
+/**
+ * @brief           Send out piled up payload
+ * 
+ * @param[in, out]  handle      shellmatta handle of the instance
+ * @return          errorcode
+ */
+shellmatta_retCode_t shellmatta_transport_flush(shellmatta_handle_t handle)
+{
+    shellmatta_retCode_t    ret = SHELLMATTA_OK;
+    shellmatta_instance_t   *inst = (shellmatta_instance_t*)handle;
+
+    /** -# check parameters for plausibility  */
+    if(     (NULL               != inst)
+        &&  (SHELLMATTA_MAGIC   == inst->magic))
+    {
+
+        shellmatta_transport_packet_t *packet = &inst->transportLayer.outPacket;
+
+        if(0 != packet->header.payloadLength)
+        {
+            packet->header.packetType = SHELLMATTA_TRANSPORT_PACKET_DATA;
+            ret = shellmatta_transport_send(&inst->transportLayer, packet);
+            packet->header.payloadLength = 0u;
+        }
+    }
+    else
+    {
+        ret = SHELLMATTA_USE_FAULT;
+    }
+
+    return ret;
+}
+#endif

+ 76 - 0
src/shellmatta_transport.h

@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @file    shellmatta_transport.h
+ * @brief   transport layer functions of shellmatta
+ * @author  Simon Fischer <fischer.simon.1991@gmail.com>
+ */
+
+#ifndef _SHELLMATTA_TRANSPORT_H_
+#define _SHELLMATTA_TRANSPORT_H_
+
+#include "shellmatta.h"
+
+/** @brief value of start-of-header character */
+#define SHELLMATTA_TRANSPORT_START_OF_HEADER    0x01u
+/** @brief currently supported protocol version */
+#define SHELLMATTA_TRANSPORT_PROTOCOL_VERSION   0x01u
+
+/* header field length defines */
+/** @brief length of header */
+#define SHELLMATTA_TRANSPORT_LENGTH_HEADER      ((uint8_t)(8))
+/** @brief maximum length of shellmatta internal packages (e.g. sequence counter packets) */
+#define SHELLMATTA_TRANSPORT_LENGTH_PAYLOAD_INT ((uint8_t)(32))
+/** @brief length of crc32 */
+#define SHELLMATTA_TRANSPORT_LENGTH_CRC         ((uint8_t)(4))
+/** @brief length of crc32 */
+#define SHELLMATTA_TRANSPORT_LENGTH_STATIC      (SHELLMATTA_TRANSPORT_LENGTH_HEADER + SHELLMATTA_TRANSPORT_LENGTH_CRC)
+
+/** @brief helper macro for CRC calculation */
+#define SHELLMATTA_TRANSPORT_CALC_CRC(transporLayer, data, size)    NULL != (transportLayer)->customCrcFct ?         \
+                                                                    (transportLayer)->customCrcFct((data), (size)) : \
+                                                                    crc32Calc((data), (size));
+
+/** @brief packet definition with reduced payload (for internal packets) */
+typedef struct __attribute__((__packed__))
+{
+    shellmatta_transport_header_t   header;                 /**< header of the packet   */
+    char payload[SHELLMATTA_TRANSPORT_LENGTH_PAYLOAD_INT];  /**< payload of the packet  */
+    uint32_t                        crc;                    /**< checksum of the packet */
+} shellmatta_transport_packet_int_t;
+
+
+/**
+ * @brief definitions of shellmatta transport layer packet types
+ */
+
+#define SHELLMATTA_TRANSPORT_PACKET_DATA                    0x00u   /**< packet type to send plain data                                  */
+#define SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_REQUEST         0x01u   /**< packet type to request sequence counters                        */
+#define SHELLMATTA_TRANSPORT_PACKET_SEQ_CNT_RESPOND         0x81u   /**< packet type to respond with sequence counters                   */
+#define SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_REQUEST  0x02u   /**< packet type to set and request max buffersize                   */
+#define SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_RESPOND  0x82u   /**< packet type to respond with max buffersize                      */
+#define SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_REQUEST   0x03u   /**< UNUSED: packet type to request search for a device by unique id */
+#define SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND   0x83u   /**< UNUSED: packet type to respond with search results              */
+#define SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_REQUEST     0x04u   /**< UNUSED: packet type to set and request an address               */
+#define SHELLMATTA_TRANSPORT_PACKET_SET_ADDRESS_RESPOND     0x84u   /**< UNUSED: packet type to respond with a set address               */
+
+
+shellmatta_retCode_t shellmatta_transport_init( shellmatta_transport_layer_t    *transportLayer,
+                                                shellmatta_write_t              writeFct);
+
+shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t   *transportLayer,
+                                                  char                           byte,
+                                                  char                           **data,
+                                                  uint32_t                       *length);
+
+shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *transportLayer,
+                                                const char* data,
+                                                uint32_t length);
+
+#endif /* _SHELLMATTA_TRANSPORT_H_ */

+ 21 - 21
src/shellmatta_utils.c

@@ -37,7 +37,7 @@ void utils_writeEcho(   shellmatta_instance_t   *inst,
 {
     if(true == inst->echoEnabled)
     {
-        inst->write(data, length);
+        SHELLMATTA_WRITE(data, length);
     }
 }
 
@@ -288,27 +288,27 @@ static shellmatta_retCode_t printUsage(const shellmatta_instance_t *inst, const
     shellmatta_retCode_t ret = SHELLMATTA_OK;
 
     /** -# write the command and alias if configured */
-    SHELLMATTA_RET(ret, inst->write("Help for command: ", 18u));
-    SHELLMATTA_RET(ret, inst->write(cmd->cmd, strlen(cmd->cmd)));
+    SHELLMATTA_RET(ret, SHELLMATTA_WRITE("Help for command: ", 18u));
+    SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->cmd, strlen(cmd->cmd)));
     if((NULL != cmd->cmdAlias) && (0u != strlen(cmd->cmdAlias)))
     {
-        SHELLMATTA_RET(ret, inst->write(" (", 2u));
-        SHELLMATTA_RET(ret, inst->write(cmd->cmdAlias, strlen(cmd->cmdAlias)));
-        SHELLMATTA_RET(ret, inst->write(")", 1u));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE(" (", 2u));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->cmdAlias, strlen(cmd->cmdAlias)));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE(")", 1u));
     }
     /** -# write the help text if configured */
     if((NULL != cmd->helpText) && (0u != strlen(cmd->helpText)))
     {
-        SHELLMATTA_RET(ret, inst->write("\r\n\r\n", 4u));
-        SHELLMATTA_RET(ret, inst->write(cmd->helpText, strlen(cmd->helpText)));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE("\r\n\r\n", 4u));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->helpText, strlen(cmd->helpText)));
     }
     /** -# write the usage text if configured */
     if((NULL != cmd->usageText) && (0u != strlen(cmd->usageText)))
     {
-        SHELLMATTA_RET(ret, inst->write("\r\n\r\nUsage: \r\n", 13u));
-        SHELLMATTA_RET(ret, inst->write(cmd->usageText, strlen(cmd->usageText)));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE("\r\n\r\nUsage: \r\n", 13u));
+        SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->usageText, strlen(cmd->usageText)));
     }
-    SHELLMATTA_RET(ret, inst->write("\r\n", 2u));
+    SHELLMATTA_RET(ret, SHELLMATTA_WRITE("\r\n", 2u));
 
     return ret;
 }
@@ -419,29 +419,29 @@ static shellmatta_retCode_t helpCmdFct(const shellmatta_handle_t handle, const c
             cmdLen       = strlen(cmd->cmd);
             cmdAliasLen  = (NULL != cmd->cmdAlias) ? strlen(cmd->cmdAlias) : 0u;
 
-            SHELLMATTA_RET(ret, inst->write(cmd->cmd, strlen(cmd->cmd)));
+            SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->cmd, strlen(cmd->cmd)));
             tabCnt = (maxCmdLen - cmdLen) + 2u;
 
             /** -# add padding if there is anything to be printed afterwards */
             if(    ((NULL != cmd->cmdAlias) && (0u != strlen(cmd->cmdAlias)))
                 || ((NULL != cmd->helpText) && (0u != strlen(cmd->helpText))))
             {
-                SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
+                SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt);
             }
 
             if((NULL != cmd->cmdAlias) && (0u != strlen(cmd->cmdAlias)))
             {
-                SHELLMATTA_RET(ret, inst->write(cmd->cmdAlias, cmdAliasLen));
+                SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->cmdAlias, cmdAliasLen));
             }
             tabCnt = (maxCmdAliasLen - cmdAliasLen) + 2u;
 
             if((NULL != cmd->helpText) && (0u != strlen(cmd->helpText)))
             {
-                SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt, inst->write);
-                SHELLMATTA_RET(ret, inst->write(cmd->helpText, strlen(cmd->helpText)));
+                SHELLMATTA_PRINT_BUFFER(tabBuffer, tabCnt);
+                SHELLMATTA_RET(ret, SHELLMATTA_WRITE(cmd->helpText, strlen(cmd->helpText)));
             }
 
-            SHELLMATTA_RET(ret, inst->write("\r\n", 2u));
+            SHELLMATTA_RET(ret, SHELLMATTA_WRITE("\r\n", 2u));
 
             cmd = cmd->next;
         }
@@ -474,16 +474,16 @@ void utils_terminateInput(shellmatta_instance_t *inst)
     inst->stdinLength       = 0u;
     inst->continuousCmd     = NULL;
     inst->busyCmd           = NULL;
-    inst->write("\r\n", 2u);
+    SHELLMATTA_WRITE("\r\n", 2u);
 #ifdef SHELLMATTA_AUTHENTICATION
     inst->loginState        = SHELLMATTA_AUTH_IDLE;
     if (NULL != inst->userPointer)
     {
-        inst->write(inst->userPointer->username, strlen(inst->userPointer->username));
-        inst->write("@", 1);
+        SHELLMATTA_WRITE(inst->userPointer->username, strlen(inst->userPointer->username));
+        SHELLMATTA_WRITE("@", 1);
     }
 #endif
-    inst->write(inst->prompt, strlen(inst->prompt));
+    SHELLMATTA_WRITE(inst->prompt, strlen(inst->prompt));
 }
 
 /**

+ 12 - 9
src/shellmatta_utils.h

@@ -19,6 +19,9 @@
 #ifndef _SHELLMATTA_UTILS_H_
 #define _SHELLMATTA_UTILS_H_
 
+#ifdef SHELLMATTA_TRANSPORT
+#include "shellmatta_transport.h"
+#endif
 #include "shellmatta.h"
 #include <stdint.h>
 
@@ -49,15 +52,15 @@
  * @param[in]   cnt     count of bytes to send
  * @param[in]   fct     write function
  */
-#define SHELLMATTA_PRINT_BUFFER(buffer,cnt,fct) \
-    while((cnt) > sizeof((buffer)))             \
-    {                                           \
-        (cnt) -= sizeof((buffer));              \
-        (fct)((buffer), sizeof((buffer)));      \
-    }                                           \
-    if((cnt) != 0u)                             \
-    {                                           \
-        (fct)((buffer), (cnt));                 \
+#define SHELLMATTA_PRINT_BUFFER(buffer,cnt)             \
+    while((cnt) > sizeof((buffer)))                     \
+    {                                                   \
+        (cnt) -= sizeof((buffer));                      \
+        SHELLMATTA_WRITE((buffer), sizeof((buffer)));   \
+    }                                                   \
+    if((cnt) != 0u)                                     \
+    {                                                   \
+        SHELLMATTA_WRITE((buffer), (cnt));              \
     }
 
 /** @brief help command which prints all shellmatta commands as table */

+ 440 - 0
test/integrationtest_transport/test_integration_transport.cpp

@@ -0,0 +1,440 @@
+/*
+ * Copyright (c) 2021 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @file    test_integration_transport.cpp
+ * @brief   integration test implementation for the transport layer
+ * @author  Stefan Strobel <stefan.strobel@shimatta.net>
+ */
+
+#include "test/framework/catch.hpp"
+extern "C" {
+#include "shellmatta.h"
+}
+#include <string.h>
+
+static uint32_t write_callCnt = 0u;
+static char write_data[1024];
+static uint32_t write_length;
+static const char *doSomethingArguments;
+static uint32_t doSomethingLength;
+static char *doSomethingStdin;
+static uint32_t doSomethingStdinLength;
+
+static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
+{
+    write_callCnt ++;
+    while((length > 0) && (write_length < sizeof(write_data)))
+    {
+        write_data[write_length] = *data;
+        data ++;
+        length --;
+        write_length ++;
+    }
+
+    return SHELLMATTA_OK;
+}
+
+static shellmatta_retCode_t doSomething(shellmatta_handle_t handle, const char *arguments, uint32_t length)
+{
+    doSomethingArguments = arguments;
+    doSomethingLength = length;
+
+    shellmatta_read(handle, &doSomethingStdin, &doSomethingStdinLength);
+
+    shellmatta_printf(handle, "%s - length: %u", arguments, length);
+    return SHELLMATTA_OK;
+}
+shellmatta_cmd_t doSomethingCmd =
+{
+    (char*)"doSomething",
+    (char*)"do",
+    (char*)"Function does something",
+    (char*)"use me, please",
+    doSomething,
+    NULL
+};
+
+static shellmatta_retCode_t largePayload(shellmatta_handle_t handle, const char *arguments, uint32_t length)
+{
+    uint32_t i;
+
+    for (i = 0u; i < 8; i ++)
+    {
+        shellmatta_printf(handle, "This is my very very very very large payload\r\n");
+    }
+
+    (void)arguments;
+    (void)length;
+
+    return SHELLMATTA_OK;
+}
+shellmatta_cmd_t largePayloadCmd =
+{
+    (char*)"largePayload",
+    (char*)"lp",
+    (char*)"Function returns large payload",
+    (char*)"i have much to say",
+    largePayload,
+    NULL
+};
+
+static shellmatta_retCode_t largePayloadAtOnce(shellmatta_handle_t handle, const char *arguments, uint32_t length)
+{
+    shellmatta_write(handle,
+                    (char*)"This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n"
+                    "This is my very very very very large payload\r\n",
+                    46u*8u);
+
+    (void)arguments;
+    (void)length;
+
+    return SHELLMATTA_OK;
+}
+shellmatta_cmd_t largePayloadAtOnceCmd =
+{
+    (char*)"largePayload",
+    (char*)"lp",
+    (char*)"Function returns large payload",
+    (char*)"i have much to say",
+    largePayloadAtOnce,
+    NULL
+};
+
+SCENARIO("Integration test of Transport layer", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command")
+    {
+        shellmatta_instance_t inst;
+        shellmatta_handle_t handle;
+        char buffer[1024];
+        char historyBuffer[1024];
+
+        shellmatta_doInit(  &inst,
+                            &handle,
+                            buffer,
+                            sizeof(buffer),
+                            historyBuffer,
+                            sizeof(historyBuffer),
+                            "shellmatta->",
+                            NULL,
+                            writeFct);
+        shellmatta_addCmd(handle, &doSomethingCmd);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("Invalid CRC is passed")
+        {
+            /* check with invalid payload */
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                  "doSomething argument\r\n"
+                                                  "\x00\x00\x00\x00", 34u);
+
+            THEN("Shellmatta responds with CRC error")
+            {
+                char *dummyData =   (char*)"crc error\r\n\r\nshellmatta->";
+
+                CHECK(write_length == strlen(dummyData));
+                REQUIRE(strcmp(dummyData, write_data) == 0);
+            }
+        }
+
+        WHEN("Valid CRC is passed")
+        {
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                "doSomething argument\r\n"
+                                                "\x7b\x49\xfa\x72", 34u);
+            THEN("The shellmatta responds to the command")
+            {
+                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                                           "doSomething argument - length: 20"
+                                           "\r\n"
+                                           "shellmatta->"
+                                           "\xc8\xae\xc0\x56";
+
+                CHECK(write_length == 59u);
+                REQUIRE(memcmp(write_data, dummyData, 59) == 0);
+            }
+        }
+
+        WHEN("Large payload is written by shellmatta in steps")
+        {
+            /* add large payload command */
+            shellmatta_addCmd(handle, &largePayloadCmd);
+
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x0e\x00\x00\x00\x00"
+                                                "largePayload\r\n"
+                                                "\xad\x33\x31\xcc", 26u);
+            THEN("The shellmatta responds multiple telegrams")
+            {
+                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x00\x01\x01"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very"
+                                           "\x0f\x90\xc0\xfd"
+                                           "\x01\x01\x00\x7f\x00\x00\x01\x02"
+                                           " very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "\r\n"
+                                           "shellmatta->"
+                                           "\x00\xc9\x5d\x37";
+
+                CHECK(write_length == 406u);
+                REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
+            }
+        }
+
+        WHEN("Large payload is written by shellmatta at once")
+        {
+            /* add large payload command */
+            shellmatta_addCmd(handle, &largePayloadAtOnceCmd);
+
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x0e\x00\x00\x00\x00"
+                                                "largePayload\r\n"
+                                                "\xad\x33\x31\xcc", 26u);
+            THEN("The shellmatta responds multiple telegrams")
+            {
+                char *dummyData =   (char*)"\x01\x01\x00\xff\x00\x00\x01\x01"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very"
+                                           "\x0f\x90\xc0\xfd"
+                                           "\x01\x01\x00\x7f\x00\x00\x01\x02"
+                                           " very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "This is my very very very very large payload\r\n"
+                                           "\r\n"
+                                           "shellmatta->"
+                                           "\x00\xc9\x5d\x37";
+
+                CHECK(write_length == 406u);
+                REQUIRE(memcmp(write_data, dummyData, 406u) == 0);
+            }
+        }
+
+        WHEN("manual mode is used after transport layer mode")
+        {
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                "doSomething argument\r\n"
+                                                "\x7b\x49\xfa\x72", 34u);
+            shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
+            THEN("The shellmatta responds to the command")
+            {
+                char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                                           "doSomething argument - length: 20"
+                                           "\r\n"
+                                           "shellmatta->"
+                                           "\xc8\xae\xc0\x56"
+                                           "doSomething argument - length: 20\r\n"
+                                           "shellmatta->";
+
+                CHECK(write_length == 106);
+                REQUIRE(memcmp(write_data, dummyData, 106) == 0);
+            }
+        }
+
+        WHEN("disabling auto flush")
+        {
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_transport_configure(handle, false, true, NULL);
+            shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                "doSomething argument\r\n"
+                                                "\x7b\x49\xfa\x72", 34u);
+
+            THEN("The Shellmatta does not respond")
+            {
+                CHECK(write_length == 0u);
+
+                AND_WHEN("The flush method is called")
+                {
+                    shellmatta_transport_flush(handle);
+                    THEN("The shellmatta returns the data")
+                    {
+
+                        char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                                                "doSomething argument - length: 20"
+                                                "\r\n"
+                                                "shellmatta->"
+                                                "\xc8\xae\xc0\x56";
+
+                        CHECK(write_length == 59u);
+                        REQUIRE(memcmp(write_data, dummyData, 59) == 0);
+                    }
+                }
+            }
+        }
+
+        WHEN("Sequence counter is requested")
+        {
+            /* request sequence counter */
+            shellmatta_processData(handle, (char*)"\x01\x01\x01\x00\x00\x00\x00\x00"
+                                                  "\xc4\xa3\x07\xe6", 12u);
+            THEN("The valid Sequence counter is returned")
+            {
+                char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x00\x01\x01"
+                                           "\xb4\x0f\x12\xe9";
+
+                CHECK(write_length == 12);
+                REQUIRE(memcmp(write_data, dummyData, 12) == 0);
+            }
+            AND_WHEN("Sequence counter is requested again")
+            {
+                /* request sequence counter again */
+                write_callCnt = 0u;
+                memset(write_data, 0, sizeof(write_data));
+                write_length = 0u;
+                shellmatta_processData(handle, (char*)"\x01\x01\x01\x00\x00\x00\x00\x00"
+                                                      "\xc4\xa3\x07\xe6", 12u);
+                THEN("The next Sequence counter is returned")
+                {
+                    char *dummyData =   (char*)"\x01\x01\x81\x00\x00\x00\x02\x02"
+                                               "\x06\x2b\x10\x90";
+
+                    CHECK(write_length == 12);
+                    REQUIRE(memcmp(write_data, dummyData, 12) == 0);
+                }
+            }
+        }
+    }
+}
+
+SCENARIO("Integration test of Transport layer with mandatory transport layer", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command")
+    {
+        shellmatta_instance_t inst;
+        shellmatta_handle_t handle;
+        shellmatta_retCode_t ret;
+        char buffer[1024];
+        char historyBuffer[1024];
+
+        shellmatta_doInit(  &inst,
+                            &handle,
+                            buffer,
+                            sizeof(buffer),
+                            historyBuffer,
+                            sizeof(historyBuffer),
+                            "shellmatta->",
+                            NULL,
+                            writeFct);
+        shellmatta_addCmd(handle, &doSomethingCmd);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("The tansport layer is set to mandatory") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL);
+            CHECK(ret == SHELLMATTA_OK);
+
+            AND_WHEN("manual mode is used after transport layer mode")
+            {
+                /* check with valid payload - disable echo to reduce cluttering */
+                shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+                shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                    "doSomething argument\r\n"
+                                                    "\x7b\x49\xfa\x72", 34u);
+                shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
+                THEN("The shellmatta responds only to the first command - and waits for a new telegram to start")
+                {
+                    char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                                            "doSomething argument - length: 20"
+                                            "\r\n"
+                                            "shellmatta->"
+                                            "\xc8\xae\xc0\x56";
+
+                    CHECK(write_length == 59);
+                    CHECK(memcmp(write_data, dummyData, write_length) == 0);
+                    REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+                }
+            }
+        }
+    }
+}
+
+SCENARIO("Integration test of Transport layer - reset transport layer", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command")
+    {
+        shellmatta_instance_t inst;
+        shellmatta_handle_t handle;
+        shellmatta_retCode_t ret;
+        char buffer[1024];
+        char historyBuffer[1024];
+
+        shellmatta_doInit(  &inst,
+                            &handle,
+                            buffer,
+                            sizeof(buffer),
+                            historyBuffer,
+                            sizeof(historyBuffer),
+                            "shellmatta->",
+                            NULL,
+                            writeFct);
+        shellmatta_addCmd(handle, &doSomethingCmd);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("The tansport layer is set to mandatory") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL);
+            CHECK(ret == SHELLMATTA_OK);
+
+            AND_WHEN("A partial telegram is passed")
+            {
+                /* check with valid payload - disable echo to reduce cluttering */
+                shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+                shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                    "doSomething argument", 28u);
+                THEN("The transport layer is in state SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD")
+                {
+                    CHECK(write_length == 0);
+                    CHECK_THAT(inst.transportLayer.inPacket.payload, Catch::Matchers::Equals("doSomething argument"));
+                    REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD);
+
+                    AND_WHEN("The transport layer is resetted")
+                    {
+                        ret = shellmatta_transport_reset(handle);
+                        CHECK(ret == SHELLMATTA_OK);
+
+                        THEN("The transport layer is in state wait again and no payload is set") {
+                            CHECK(write_length == 0);
+                            CHECK(inst.transportLayer.inPacket.payload[0] == '\0');
+                            REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 11 - 0
test/integrationtest_transport/test_main.cpp

@@ -0,0 +1,11 @@
+// 010-TestCase.cpp
+
+// Let Catch provide main():
+#define CATCH_CONFIG_MAIN
+
+#include "test/framework/catch.hpp"
+extern "C" {
+#include "test/framework/fff.h"
+DEFINE_FFF_GLOBALS
+}
+

+ 2 - 0
test/unittest/shellmatta/test_shellmatta_doInit.cpp

@@ -1,5 +1,7 @@
 #include "test/framework/catch.hpp"
 #include "src/shellmatta.c"
+#include "src/shellmatta_transport.c"
+#include "src/shellmatta_crc.c"
 #include <string.h>
 
 TEST_CASE( "shellmatta dummy" ) {

+ 20 - 0
test/unittest/shellmatta_crc/test_crc32Fast.cpp

@@ -0,0 +1,20 @@
+#include "test/framework/catch.hpp"
+#include <string.h>
+
+#undef SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
+#include "test_crc32_data.h"
+#include "src/shellmatta_crc.c"
+
+TEST_CASE( "shellmatta_crc crc32Fast" ) {
+
+    uint32_t crc = crc32Fast((char*)"123456789", 9, crc32Table);
+
+    REQUIRE(crc == 0xCBF43926u);
+}
+
+TEST_CASE( "shellmatta_crc crc32Fast - more data" ) {
+
+    uint32_t crc = crc32Fast((char*)data, sizeof(data), crc32Table);
+
+    REQUIRE(crc == data_crc);
+}

+ 20 - 0
test/unittest/shellmatta_crc/test_crc32Slow.cpp

@@ -0,0 +1,20 @@
+#include "test/framework/catch.hpp"
+#include <string.h>
+
+#define SHELLMATTA_TRANSPORT_CRC_NO_LOOKUP
+#include "test_crc32_data.h"
+#include "src/shellmatta_crc.c"
+
+TEST_CASE( "shellmatta_crc crc32Slow" ) {
+
+    uint32_t crc = crc32Slow((char*)"123456789", 9);
+
+    REQUIRE( crc == 0xCBF43926u);
+}
+
+TEST_CASE( "shellmatta_crc crc32Slow - more data" ) {
+
+    uint32_t crc = crc32Slow((char*)data, sizeof(data));
+
+    REQUIRE(crc == data_crc);
+}

+ 265 - 0
test/unittest/shellmatta_crc/test_crc32_data.h

@@ -0,0 +1,265 @@
+#ifndef _TEST_CRC32_DATA_H_
+#define _TEST_CRC32_DATA_H_
+
+const uint8_t data[] = {
+    0xB8, 0xCA, 0xFD, 0x92, 0x55, 0x6A, 0x2F, 0x22, 0x5B, 0xB3, 0x0F, 0xEE, 0x69, 0x4E, 0x83, 0x4A,
+    0x2A, 0x4E, 0x5E, 0x29, 0x58, 0x2C, 0xE0, 0x21, 0x1C, 0x92, 0x76, 0x7C, 0x87, 0xB1, 0x00, 0x18,
+    0x25, 0xFE, 0x49, 0x24, 0xDC, 0x8F, 0x82, 0x09, 0x9D, 0x83, 0xE6, 0x01, 0xA3, 0x12, 0xDF, 0x39,
+    0x2E, 0x4A, 0x3F, 0x75, 0x0D, 0x8D, 0x7E, 0x9D, 0x5B, 0x48, 0x01, 0x9C, 0x3D, 0x92, 0xD5, 0x81,
+    0x93, 0x97, 0x7C, 0xD1, 0xDE, 0xFD, 0x97, 0x6D, 0xD3, 0xB1, 0x9D, 0x84, 0x55, 0xCB, 0xF1, 0x69,
+    0xDC, 0x6B, 0xF1, 0x5D, 0x78, 0xC6, 0xDE, 0x87, 0xF5, 0xC9, 0xBE, 0xB8, 0xDA, 0xFE, 0x83, 0xC0,
+    0x3D, 0xA0, 0x2B, 0x61, 0xA9, 0x10, 0x9F, 0x25, 0x92, 0x06, 0x7A, 0xB2, 0x17, 0x43, 0x0E, 0x59,
+    0x02, 0x95, 0x4B, 0xF4, 0x56, 0x70, 0x54, 0x60, 0xCF, 0x79, 0xF5, 0x16, 0x26, 0xBA, 0x3D, 0xBC,
+    0x03, 0x59, 0xEF, 0xB1, 0xEC, 0x1A, 0x90, 0xDC, 0x93, 0xFE, 0x46, 0x5F, 0x60, 0xB8, 0xCC, 0xD8,
+    0x12, 0xE0, 0x27, 0x61, 0xCA, 0x13, 0xF6, 0x7D, 0xF5, 0x6D, 0x72, 0x93, 0xCC, 0xFD, 0x7D, 0xAF,
+    0x69, 0x32, 0x64, 0xB1, 0xBA, 0x60, 0x23, 0x12, 0xB2, 0xC8, 0x50, 0xEF, 0x8E, 0xDC, 0x05, 0x0A,
+    0x20, 0x99, 0x65, 0xDE, 0x5A, 0x31, 0xA1, 0x08, 0x96, 0x6E, 0x85, 0x9E, 0x5A, 0x74, 0xFE, 0x27,
+    0x97, 0xD3, 0x2C, 0x67, 0x8E, 0x1A, 0xD6, 0x1A, 0xF0, 0x48, 0x6A, 0x5E, 0xE2, 0xD6, 0xD7, 0x69,
+    0xE8, 0x41, 0xE8, 0xBA, 0xF0, 0x3C, 0xF4, 0xFF, 0x03, 0xFA, 0x02, 0x3B, 0x45, 0x3E, 0xC2, 0x07,
+    0x58, 0x17, 0xEB, 0xEA, 0x42, 0x77, 0xE9, 0x1B, 0x72, 0x15, 0xE8, 0x38, 0x82, 0x3F, 0xA5, 0xC0,
+    0xC6, 0x8C, 0x96, 0x59, 0xDA, 0x9A, 0x51, 0x32, 0xB4, 0x43, 0x41, 0x02, 0xE4, 0xF1, 0x0C, 0x85,
+    0x1B, 0x0C, 0x4B, 0x6A, 0x17, 0x96, 0x63, 0x11, 0x80, 0x7A, 0xA7, 0x9F, 0x76, 0x25, 0x16, 0x2F,
+    0xBC, 0x63, 0x5B, 0x31, 0xCB, 0xA8, 0xE2, 0x46, 0x43, 0x2D, 0x1E, 0x1F, 0x71, 0x93, 0x66, 0x2B,
+    0xF6, 0xF4, 0xF9, 0x25, 0xB1, 0x8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 0x57, 0x10, 0xA7, 0xD7, 0x84, 0xB7, 0x25, 0xC8,
+    0x97, 0x11, 0xE2, 0x50, 0xB2, 0x30, 0x4F, 0x89, 0xAC, 0xCC, 0x31, 0x24, 0xB8, 0x57, 0xD9, 0xD2,
+    0x9A, 0x0A, 0x00, 0x08, 0xB4, 0x07, 0x2B, 0x6D, 0x5E, 0x03, 0xB5, 0x82, 0x47, 0x2B, 0xDF, 0x42,
+    0xE2, 0x1C, 0x6F, 0xD8, 0x0E, 0x2F, 0xD6, 0xA8, 0x82, 0x7B, 0xE0, 0x40, 0xAE, 0x36, 0x57, 0xFD,
+    0x19, 0x6A, 0x36, 0x67, 0x6D, 0x24, 0x3E, 0x9B, 0xAF, 0x86, 0x13, 0x48, 0x64, 0x75, 0x39, 0x0E,
+    0xA2, 0xBF, 0x8F, 0x4D, 0x34, 0xED, 0x1D, 0xA7, 0x6F, 0x2F, 0x59, 0xCB, 0x53, 0x0B, 0x3F, 0x55,
+    0x08, 0xB6, 0xD3, 0xC3, 0xEB, 0x54, 0xE9, 0xD8, 0xAF, 0x6F, 0x55, 0xF7, 0x41, 0x71, 0xD7, 0x38,
+    0x73, 0xEF, 0x6B, 0x52, 0xB2, 0x11, 0xC6, 0x98, 0x2D, 0x59, 0x33, 0x9E, 0x40, 0xA8, 0x15, 0x51,
+    0x15, 0x3D, 0xC0, 0x87, 0xAD, 0xF9, 0x73, 0x5F, 0xE8, 0x4B, 0x96, 0xF0, 0x25, 0x6B, 0x9F, 0x20,
+    0x98, 0xD5, 0x2D, 0x9E, 0x7A, 0x34, 0x3A, 0x61, 0x94, 0x1F, 0x8A, 0x25, 0xEF, 0x58, 0xA2, 0xBA,
+    0x94, 0x81, 0xEA, 0x34, 0x98, 0x68, 0xE4, 0x3F, 0x05, 0x59, 0x74, 0x2B, 0x3F, 0x26, 0xBC, 0x7A,
+    0xF7, 0xCD, 0x03, 0xFB, 0xE2, 0xE8, 0xA3, 0xBA, 0xA3, 0x5A, 0xFF, 0x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, 0xEC, 0x16, 0xC7,
+    0xE1, 0xEC, 0x03, 0xCD, 0x8C, 0x4D, 0x3D, 0x93, 0x45, 0x8A, 0x1D, 0x3B, 0x6E, 0xDB, 0x05, 0xEA,
+    0x8B, 0x8D, 0xC7, 0x2C, 0x62, 0x90, 0x2E, 0x1E, 0x0A, 0xB5, 0xCD, 0xF0, 0xA7, 0x39, 0x76, 0x8C,
+    0xC2, 0x92, 0xE0, 0x63, 0x94, 0xA5, 0x70, 0xB6, 0x9D, 0xD6, 0x2F, 0xE7, 0x63, 0x9A, 0x58, 0x96,
+    0x41, 0x77, 0x0C, 0xA4, 0x8A, 0xA3, 0x0F, 0x52, 0x77, 0xA4, 0xAA, 0x24, 0xA7, 0xA8, 0x0F, 0x37,
+    0x1B, 0x7E, 0xDA, 0x32, 0xFE, 0x55, 0x83, 0x05, 0xA3, 0xB4, 0xEE, 0x15, 0x83, 0x57, 0x63, 0x91,
+    0x2F, 0xDA, 0x98, 0x11, 0x75, 0x62, 0xA1, 0xAF, 0x2F, 0xA5, 0xE4, 0x41, 0x88, 0x0F, 0x6F, 0x6F,
+    0x96, 0xE2, 0x44, 0xB7, 0xA5, 0x81, 0x88, 0xAD, 0x9B, 0x51, 0x9E, 0xF8, 0x32, 0xE2, 0x94, 0xED,
+    0x11, 0x40, 0x7D, 0xBC, 0xEE, 0xA9, 0x95, 0x8A, 0x47, 0xFF, 0x44, 0x05, 0x5E, 0xB8, 0x67, 0x31,
+    0x7E, 0x22, 0x74, 0x87, 0xC6, 0x40, 0x51, 0xAF, 0xEA, 0x90, 0x07, 0x5A, 0xB6, 0x80, 0xA1, 0x11,
+    0x45, 0x68, 0xD7, 0x01, 0x27, 0x4A, 0x61, 0x10, 0xF8, 0xB0, 0x12, 0xC2, 0x23, 0x60, 0x10, 0xCD,
+    0xC8, 0xD6, 0xC6, 0x47, 0x03, 0x9C, 0x76, 0xE0, 0x1B, 0x06, 0x76, 0x95, 0x3B, 0xE8, 0x83, 0xB7,
+    0x44, 0xC1, 0x53, 0xB3, 0x0A, 0x3E, 0x3F, 0x9E, 0x65, 0x1D, 0x5F, 0xB4, 0x3B, 0xC2, 0xE7, 0x07,
+    0xCB, 0x99, 0xB2, 0x64, 0x95, 0x52, 0xEA, 0xDE, 0xFB, 0xB9, 0x99, 0xD1, 0x47, 0x76, 0xEC, 0x5B,
+    0xFB, 0x5D, 0x34, 0x8B, 0xA1, 0x29, 0xEB, 0xBA, 0x83, 0xB6, 0x54, 0xD2, 0xEF, 0x1D, 0x79, 0x76,
+    0x02, 0x4F, 0x98, 0x52, 0x1E, 0x05, 0x4A, 0x05, 0x6F, 0x25, 0xEA, 0x69, 0x3D, 0xF9, 0x15, 0x2F,
+    0xE7, 0xCF, 0x3F, 0x0A, 0xBE, 0xE4, 0xBC, 0xF1, 0x21, 0xB3, 0xB0, 0x23, 0x94, 0x02, 0xCE, 0xF3,
+    0xB0, 0x50, 0xDC, 0x9B, 0x1E, 0x72, 0x52, 0x86, 0x13, 0x93, 0xA1, 0xDC, 0xDE, 0xD3, 0xE6, 0x3D,
+    0x97, 0x41, 0x21, 0xF1, 0x00, 0xF5, 0x2C, 0x0C, 0x0B, 0x6F, 0x14, 0x2F, 0xBA, 0x9A, 0x86, 0xFF,
+    0x3C, 0x06, 0x73, 0x71, 0x71, 0x41, 0x26, 0x7D, 0x4B, 0x5D, 0x68, 0xE5, 0xB1, 0x0B, 0x6B, 0x18,
+    0xCE, 0xE0, 0x99, 0x65, 0xFE, 0xA5, 0x8B, 0xF6, 0xC0, 0xC8, 0xB7, 0x64, 0x63, 0x4D, 0x97, 0xC0,
+    0x43, 0xE1, 0x69, 0x6C, 0xE4, 0xDD, 0xC1, 0x28, 0x32, 0x64, 0x81, 0x23, 0xB4, 0xED, 0x01, 0xFA,
+    0x83, 0xDC, 0x7D, 0xED, 0x40, 0x01, 0xFD, 0xC2, 0x75, 0x1E, 0x61, 0x14, 0x04, 0xCB, 0x47, 0x00,
+    0x97, 0x53, 0xDD, 0x84, 0x3C, 0x76, 0xEF, 0xE9, 0x96, 0x0C, 0xBD, 0x19, 0x56, 0x0A, 0x5B, 0xBC,
+    0xDF, 0x6A, 0xB5, 0x75, 0x43, 0xDB, 0x78, 0xA3, 0x10, 0x5A, 0x72, 0x72, 0x88, 0x05, 0x35, 0x2D,
+    0x3B, 0xD4, 0x01, 0x19, 0x2F, 0xFF, 0x52, 0x49, 0xF7, 0x3D, 0x87, 0x2E, 0x7C, 0x38, 0x80, 0xDF,
+    0x41, 0xC4, 0x3F, 0x4E, 0x78, 0xC9, 0xC8, 0xF3, 0x2D, 0xE3, 0xDB, 0x99, 0x4D, 0x33, 0x4F, 0x58,
+    0x69, 0xDF, 0x1D, 0xEC, 0x68, 0x2F, 0x60, 0xF0, 0x8C, 0x62, 0xD8, 0xAE, 0x7C, 0x8D, 0xC9, 0x87,
+    0x3D, 0x27, 0x2C, 0x2D, 0x46, 0x23, 0x8D, 0x2E, 0x1C, 0xA9, 0x21, 0x86, 0x24, 0xCF, 0xDB, 0x36,
+    0x8C, 0xF1, 0x8C, 0x23, 0x87, 0x83, 0x60, 0xAE, 0x3F, 0x6D, 0x42, 0xC8, 0x25, 0x67, 0xE5, 0x7B,
+    0x98, 0xD3, 0xA0, 0x28, 0x03, 0x08, 0x39, 0xF5, 0xE1, 0x1D, 0x5F, 0x1A, 0x55, 0x97, 0x70, 0x22,
+    0x46, 0x90, 0xBB, 0x4A, 0x1F, 0x39, 0x72, 0x77, 0xAB, 0xD0, 0xE7, 0x8F, 0xB4, 0x65, 0xD7, 0x26,
+    0x4E, 0x0D, 0xD3, 0xBD, 0xFF, 0x58, 0x14, 0x0C, 0x32, 0x35, 0x42, 0x19, 0x99, 0x8D, 0xFC, 0x1A,
+    0x6B, 0x40, 0x2E, 0x4E, 0xB6, 0x55, 0x86, 0x5F, 0x24, 0x84, 0x81, 0xFA, 0xE0, 0x6E, 0xF4, 0x9A,
+    0x8C, 0x1E, 0x14, 0xCC, 0x79, 0xBA, 0x3A, 0x5C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 0x90, 0x28, 0x43, 0x25, 0xD9, 0x75, 0xDA,
+    0x04, 0x20, 0x4E, 0x65, 0x12, 0x17, 0x8B, 0x92, 0xBE, 0xD3, 0x02, 0xAC, 0xC2, 0x01, 0x29, 0xE5,
+    0x8A, 0xA6, 0x1C, 0xC9, 0x4F, 0x2C, 0x69, 0x43, 0x3A, 0xE8, 0x18, 0x06, 0x55, 0x71, 0xC6, 0x4C,
+    0x28, 0x5F, 0xE0, 0x1E, 0x33, 0x5A, 0x47, 0xB8, 0xA9, 0x84, 0xE3, 0xA9, 0x2A, 0xA7, 0x01, 0xC5,
+    0x4D, 0xC4, 0x75, 0x15, 0x44, 0xD5, 0xDF, 0x40, 0xEF, 0xE1, 0x8A, 0x38, 0x11, 0xC6, 0xC5, 0x13,
+    0x9A, 0x4E, 0xB6, 0x63, 0x2B, 0x6B, 0xF8, 0x6C, 0x39, 0xB3, 0x8A, 0x15, 0x94, 0x85, 0xE2, 0x71,
+    0x17, 0x68, 0x30, 0x33, 0xDD, 0x77, 0x18, 0x7F, 0x32, 0x15, 0x6A, 0xD2, 0x21, 0x21, 0xBD, 0x04,
+    0x5D, 0x5A, 0xD1, 0x97, 0xCF, 0xD2, 0x2E, 0xDD, 0x2F, 0x7D, 0x6C, 0x9E, 0x41, 0x47, 0x00, 0x4C,
+    0xC7, 0x3F, 0x98, 0xF7, 0x28, 0xBE, 0x4C, 0x7D, 0x5E, 0xA7, 0x39, 0xB5, 0xC2, 0x0E, 0x4C, 0x95,
+    0xA6, 0xF2, 0x45, 0x83, 0xEA, 0xDC, 0x4C, 0x59, 0xFC, 0x86, 0x94, 0xD4, 0xE9, 0xDB, 0xE5, 0x62,
+    0x6C, 0xFD, 0x0B, 0x9E, 0x29, 0x19, 0x89, 0xDD, 0x80, 0x38, 0x0A, 0xA4, 0xA4, 0x5D, 0x65, 0xE3,
+    0xE0, 0x8C, 0x3B, 0x53, 0x37, 0x9C, 0x89, 0x57, 0xCA, 0xF3, 0xA0, 0x2D, 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9A, 0xF8,
+    0xF4, 0xE0, 0x75, 0xCE, 0xA7, 0x48, 0xF9, 0x23, 0xE0, 0xF5, 0xEF, 0xFA, 0xC5, 0xE4, 0x6A, 0x13,
+    0xE6, 0x76, 0xEF, 0xF6, 0x3D, 0x25, 0x7A, 0x2E, 0x6B, 0x53, 0xE6, 0x88, 0xD2, 0x84, 0x87, 0x46,
+    0x81, 0xA3, 0x02, 0x81, 0x16, 0x37, 0xAD, 0x3E, 0x13, 0x94, 0x07, 0xE8, 0x3A, 0x70, 0x09, 0x39,
+    0xED, 0x77, 0x72, 0xB8, 0xBB, 0xAE, 0x40, 0x63, 0x84, 0xD7, 0xF2, 0x28, 0xDD, 0x19, 0x60, 0x3F,
+    0xA3, 0xA0, 0x28, 0x8A, 0xF1, 0xF7, 0x0C, 0x8F, 0xD4, 0x56, 0xC1, 0xB3, 0x73, 0x24, 0xFD, 0xC4,
+    0xA2, 0x5D, 0xDA, 0xFC, 0xEF, 0xAA, 0xCB, 0x06, 0xB2, 0x52, 0xB7, 0xC5, 0xBD, 0x5A, 0x0B, 0xC2,
+    0x9B, 0x6F, 0xC3, 0x99, 0x89, 0x7D, 0xC0, 0xCF, 0x9C, 0x06, 0xEF, 0xD4, 0xB0, 0x97, 0x16, 0x28,
+    0x20, 0x05, 0x4E, 0xE3, 0x64, 0x32, 0x70, 0x23, 0x09, 0x92, 0x10, 0x09, 0xAA, 0xBE, 0xC3, 0x52,
+    0xD9, 0xAE, 0xC6, 0xC2, 0x23, 0x84, 0x49, 0xDD, 0x9D, 0xF1, 0xF7, 0xA8, 0xA2, 0xA3, 0x79, 0x78,
+    0xB1, 0x4C, 0x08, 0xF4, 0x99, 0x1F, 0x59, 0xE9, 0x54, 0xE5, 0x6D, 0x85, 0x52, 0x01, 0x17, 0x18,
+    0x06, 0xFE, 0x33, 0x7E, 0xF7, 0x88, 0xFA, 0xB7, 0xB9, 0xEA, 0xD3, 0x71, 0x6F, 0x67, 0x9E, 0x6F,
+    0xD7, 0x16, 0x58, 0x1A, 0x00, 0x12, 0x83, 0xA9, 0x10, 0x21, 0xD3, 0xAB, 0xD3, 0x25, 0xE8, 0xE0,
+    0xFA, 0x04, 0x26, 0xA8, 0x34, 0xCC, 0xFA, 0x83, 0x88, 0x46, 0x11, 0x52, 0xB1, 0x44, 0x51, 0x6A,
+    0x47, 0x49, 0x9F, 0xA1, 0x02, 0x6F, 0xC0, 0xDB, 0x6E, 0x9D, 0xD9, 0xD2, 0xC2, 0x6E, 0x6D, 0x18,
+    0xC6, 0x68, 0xC9, 0x82, 0xF9, 0x53, 0x44, 0x89, 0x57, 0xE0, 0xD2, 0x56, 0x77, 0xE2, 0xB3, 0x6D,
+    0xE8, 0xD1, 0x56, 0x3E, 0xF8, 0x5C, 0xB4, 0x19, 0x54, 0x34, 0xAB, 0x37, 0x27, 0x64, 0x30, 0xD5,
+    0xAC, 0xD7, 0x5E, 0xAE, 0x5D, 0xE9, 0xA9, 0x37, 0x24, 0x15, 0xCC, 0x6A, 0x42, 0x2B, 0x37, 0x1B,
+    0xD7, 0x9D, 0x07, 0x05, 0x33, 0xC6, 0xDA, 0x23, 0x5D, 0x48, 0x08, 0xF7, 0x7E, 0xD3, 0x10, 0xCF,
+    0x22, 0x03, 0x3A, 0x37, 0x68, 0x1A, 0xCB, 0x1D, 0xA2, 0xC8, 0x4A, 0x60, 0x09, 0x4D, 0xA7, 0xBE,
+    0x66, 0x9E, 0x50, 0x71, 0xF5, 0x5B, 0x7E, 0xDA, 0xD4, 0xBB, 0x45, 0x16, 0xB7, 0xCD, 0x3F, 0x60,
+    0xD3, 0xA1, 0xC5, 0x86, 0x17, 0x38, 0x21, 0xEF, 0x3B, 0x5E, 0x28, 0xEB, 0x35, 0xBB, 0x1F, 0x46,
+    0x19, 0xCE, 0xE5, 0x60, 0x76, 0x8F, 0xC2, 0x46, 0xBC, 0xF6, 0x4A, 0x7C, 0x37, 0xA5, 0x43, 0x8A,
+    0x9D, 0x69, 0x7E, 0x6E, 0x5C, 0x59, 0xF8, 0x87, 0x08, 0xC1, 0xDA, 0xA6, 0xA6, 0x2C, 0x0E, 0x42,
+    0xA7, 0x26, 0x8D, 0x15, 0xE0, 0x9A, 0x9B, 0x91, 0xCB, 0xE5, 0x92, 0xF4, 0xD5, 0xF5, 0xF7, 0xEF,
+    0x93, 0x18, 0xF3, 0x21, 0x1B, 0x55, 0x6E, 0xE1, 0xDB, 0x5F, 0x64, 0x0E, 0xAC, 0x99, 0x3A, 0xEA,
+    0xFF, 0xA5, 0x22, 0x35, 0x52, 0x77, 0xD3, 0x0A, 0x6A, 0xF7, 0x2C, 0x2C, 0xDD, 0x98, 0x89, 0xD7,
+    0xFC, 0x70, 0xCB, 0x39, 0x2D, 0xCA, 0x77, 0x1E, 0x36, 0x2B, 0x61, 0x83, 0x0F, 0x42, 0xBB, 0x16,
+    0x3F, 0x4F, 0x93, 0xCC, 0xE1, 0xE5, 0x06, 0x23, 0xB7, 0x22, 0xBE, 0xB8, 0x10, 0xAF, 0x7B, 0x2E,
+    0x52, 0x35, 0xBE, 0xB1, 0x61, 0x1A, 0xDA, 0x82, 0x51, 0x9A, 0xFE, 0x4C, 0x07, 0xA8, 0xFC, 0x44,
+    0xBE, 0x2A, 0xE3, 0x46, 0x92, 0x69, 0xA7, 0x74, 0x83, 0xDC, 0x7F, 0x10, 0xA2, 0x9E, 0xA4, 0x84,
+    0x44, 0x31, 0x98, 0xEA, 0x76, 0x6B, 0x32, 0x77, 0x17, 0xA6, 0xFD, 0x91, 0x44, 0x93, 0xBF, 0x96,
+    0x04, 0x41, 0x28, 0x77, 0x60, 0x49, 0xFA, 0xB8, 0x53, 0x22, 0x3A, 0x8E, 0x3A, 0x0E, 0x2E, 0x0D,
+    0xB4, 0x30, 0x3C, 0xA8, 0x22, 0xA5, 0xEF, 0x88, 0x29, 0xCE, 0xB4, 0x60, 0xE7, 0x0C, 0x18, 0xD3,
+    0xCC, 0xA3, 0x8F, 0x94, 0x3C, 0x90, 0x1A, 0xCC, 0x63, 0x73, 0x50, 0x72, 0xF5, 0xEC, 0x98, 0x9F,
+    0xB9, 0x03, 0x9D, 0x14, 0x0E, 0x76, 0x54, 0x68, 0xD9, 0x12, 0x0D, 0xAA, 0x86, 0x63, 0x6E, 0x62,
+    0x09, 0x64, 0x54, 0x38, 0x08, 0x10, 0xF2, 0xB3, 0x9E, 0xD4, 0xB4, 0xDE, 0x63, 0x68, 0xB3, 0xB8,
+    0x9E, 0x7F, 0xC4, 0xB8, 0xD7, 0x50, 0x78, 0xE9, 0x30, 0xFA, 0x86, 0x44, 0x2C, 0x29, 0x80, 0x53,
+    0xDE, 0x9A, 0xCD, 0x61, 0x9B, 0x5A, 0x46, 0x95, 0xA7, 0xCD, 0xEF, 0xDB, 0x88, 0xF6, 0xA6, 0x76,
+    0xE1, 0x7E, 0xCF, 0x86, 0x0F, 0x68, 0x48, 0x06, 0xE9, 0x8F, 0x31, 0xE7, 0x56, 0x35, 0x5B, 0x57,
+    0xA4, 0x61, 0x5E, 0x71, 0xC0, 0xC6, 0xA9, 0xBC, 0xD4, 0x69, 0x1B, 0x54, 0xDC, 0x4F, 0xEB, 0x9D,
+    0x35, 0xDB, 0xEE, 0xD2, 0x39, 0xB8, 0x81, 0xDB, 0x73, 0x5E, 0xB3, 0x30, 0xF7, 0xA2, 0x66, 0xC4,
+    0xE7, 0xD6, 0x83, 0x2F, 0x36, 0x70, 0x85, 0x97, 0x2D, 0x39, 0xE9, 0x17, 0x4C, 0x6F, 0x52, 0x95,
+    0x80, 0x79, 0x65, 0x54, 0xD0, 0xFD, 0xB8, 0xA8, 0xF2, 0x7B, 0x46, 0xA1, 0x75, 0xCD, 0x59, 0x93,
+    0x69, 0x1D, 0xCC, 0xC4, 0xB1, 0x38, 0x18, 0xB8, 0x70, 0x50, 0x9D, 0xD7, 0x37, 0x97, 0xFB, 0x6A,
+    0xDD, 0x3C, 0x8F, 0x28, 0x41, 0xB8, 0x53, 0xD3, 0x3E, 0x7B, 0xB9, 0x9F, 0xA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x50, 0xCD,
+    0xEF, 0xE7, 0x65, 0x44, 0xAF, 0x9E, 0x32, 0x39, 0x94, 0xDE, 0x95, 0x7F, 0xB3, 0xAC, 0xAE, 0x77,
+    0x9B, 0xCF, 0xDD, 0x50, 0x74, 0xFC, 0x21, 0x00, 0xCC, 0x9A, 0x53, 0xB5, 0xCE, 0x78, 0x21, 0xC3,
+    0xC3, 0x09, 0xB3, 0x3E, 0x10, 0x10, 0x6D, 0xC5, 0x1F, 0xCA, 0x35, 0x3A, 0xD2, 0xF9, 0x28, 0x57,
+    0x83, 0x72, 0xB3, 0x73, 0xA1, 0xFA, 0x69, 0xD7, 0x6D, 0x9C, 0x1F, 0x78, 0x77, 0xCF, 0x17, 0x04,
+    0xCD, 0x08, 0x49, 0x7C, 0x04, 0x94, 0x17, 0xE4, 0x82, 0xD8, 0xF3, 0xBB, 0xC9, 0x4B, 0xC9, 0x35,
+    0x93, 0xD7, 0x35, 0x7C, 0x03, 0x65, 0xD4, 0x70, 0x46, 0xCD, 0x38, 0x9A, 0x5F, 0x66, 0x4A, 0x5F,
+    0xFD, 0xEC, 0x35, 0x9E, 0x8A, 0x90, 0x0D, 0x3F, 0xEB, 0x43, 0xD0, 0x6C, 0x86, 0xA9, 0x90, 0x72,
+    0x93, 0x47, 0xBA, 0x80, 0xD4, 0xC4, 0xE8, 0xC7, 0x1E, 0x6A, 0xA8, 0xB6, 0x70, 0x25, 0x23, 0x48,
+    0x74, 0xC4, 0x97, 0xA8, 0x99, 0x2D, 0xFC, 0xA2, 0x38, 0xC9, 0x64, 0x9A, 0x6A, 0x5D, 0xD3, 0x15,
+    0x80, 0x11, 0xAE, 0xF4, 0x43, 0x63, 0xFD, 0xFA, 0x6D, 0x31, 0x11, 0x4B, 0x05, 0x39, 0x62, 0xD7,
+    0x8A, 0x9F, 0xA4, 0x04, 0x1A, 0x59, 0x69, 0xFE, 0xFE, 0xAB, 0xD6, 0x77, 0x4C, 0xF6, 0x39, 0xC7,
+    0x8A, 0x8A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0xBD, 0x87, 0xD2, 0x27, 0x61, 0x7A, 0xF1, 0xCE, 0xCD, 0xDD, 0x92, 0x2E,
+    0x43, 0x7E, 0x28, 0x40, 0x27, 0x99, 0xF2, 0x79, 0x86, 0x22, 0xEB, 0x9C, 0x30, 0xF1, 0x1A, 0x73,
+    0x4C, 0x6E, 0x4B, 0xB3, 0xA2, 0x8E, 0x87, 0x72, 0xED, 0x4C, 0xCF, 0x00, 0x03, 0xEC, 0xE5, 0x10,
+    0x99, 0xAE, 0x39, 0x7C, 0xF2, 0xC9, 0x3C, 0x0B, 0xCA, 0xC8, 0xA2, 0x0D, 0x3D, 0xA7, 0x72, 0xB8,
+    0x85, 0x53, 0xD8, 0x84, 0xCC, 0x59, 0x15, 0x0C, 0x6C, 0xEC, 0x17, 0x24, 0x5B, 0xA2, 0x79, 0x29,
+    0x9F, 0x74, 0x0E, 0xBF, 0x02, 0xE8, 0x27, 0x83, 0x6D, 0x8A, 0x36, 0x62, 0x91, 0xF0, 0x96, 0x99,
+    0xD8, 0x14, 0x75, 0x93, 0xB7, 0xAF, 0x41, 0x2F, 0xE3, 0xD7, 0x14, 0x16, 0xFC, 0x29, 0xFA, 0x2A,
+    0xB6, 0x1B, 0x07, 0x4E, 0x8C, 0x61, 0xA1, 0xF0, 0x8E, 0x66, 0x7D, 0x28, 0xCF, 0x57, 0x1B, 0x5A,
+    0x81, 0x3F, 0xCE, 0x95, 0xD2, 0x1C, 0xA3, 0x39, 0x0B, 0x0D, 0xA7, 0x94, 0x84, 0xEC, 0x65, 0x6D,
+    0x75, 0xF7, 0x98, 0xD1, 0xB9, 0x5F, 0x6E, 0x81, 0x01, 0xDE, 0xE1, 0xD0, 0x0C, 0xAA, 0xE9, 0xE5,
+    0xF0, 0x68, 0xA1, 0xA4, 0x81, 0xF0, 0xA9, 0xAF, 0x52, 0x11, 0x44, 0x42, 0x01, 0x9C, 0x0D, 0xED,
+    0xA6, 0x5A, 0x4A, 0x55, 0xA7, 0xD5, 0x26, 0x8C, 0x4D, 0xF8, 0x60, 0xAE, 0xD3, 0xFC, 0x3C, 0xC9,
+    0xCB, 0x24, 0xC2, 0x40, 0x19, 0x3D, 0x95, 0x35, 0xDA, 0xEC, 0xF1, 0xA7, 0xF8, 0x2D, 0x98, 0x49,
+    0x49, 0x9E, 0xBB, 0x49, 0x65, 0x78, 0x34, 0x89, 0xAE, 0x3F, 0x8C, 0xFD, 0x21, 0xA3, 0xA5, 0x37,
+    0xEA, 0x10, 0x17, 0x4A, 0xE7, 0xDC, 0x7C, 0x98, 0x78, 0x2A, 0x4C, 0x2F, 0x62, 0xD8, 0x00, 0xC6,
+    0x8F, 0x21, 0x9B, 0x82, 0xF9, 0xC1, 0xD7, 0x15, 0x14, 0xBF, 0x89, 0xDA, 0x69, 0x39, 0x08, 0x04,
+    0x5A, 0xCA, 0x9B, 0x08, 0x28, 0x68, 0x48, 0xC5, 0xB6, 0xDA, 0x84, 0x28, 0xA9, 0x19, 0x94, 0x4A,
+    0xE0, 0x43, 0xAE, 0x38, 0x5D, 0xEF, 0x22, 0xF0, 0x21, 0x0C, 0x14, 0x45, 0x90, 0x9E, 0x9E, 0xAB,
+    0x5A, 0xF5, 0x5D, 0x25, 0x12, 0x40, 0xB5, 0xD0, 0xD2, 0x90, 0x5C, 0xC7, 0xAF, 0xB1, 0xF6, 0x63,
+    0xD6, 0x69, 0xCF, 0x08, 0x7E, 0x02, 0xFD, 0x00, 0x2F, 0x3A, 0x78, 0x24, 0xF2, 0xF3, 0xF2, 0x49,
+    0x61, 0x38, 0x7F, 0xAF, 0xC9, 0x87, 0x55, 0xEE, 0xBC, 0x65, 0x2D, 0x21, 0xC8, 0xA5, 0x1C, 0x3F,
+    0x3F, 0xFC, 0xE9, 0xF0, 0x3C, 0xC0, 0x23, 0x4C, 0x48, 0xE5, 0x98, 0x40, 0x5B, 0x9F, 0xE5, 0xA0,
+    0x16, 0x3E, 0x3A, 0x18, 0x6B, 0x26, 0x8D, 0x7C, 0x1B, 0xF5, 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xA7, 0xAA, 0x12, 0xEA,
+    0x1A, 0xC2, 0xDC, 0x0D, 0x62, 0x21, 0xE1, 0x77, 0xB9, 0xB2, 0x4C, 0xCF, 0x35, 0x86, 0x63, 0xD3,
+    0x36, 0xA9, 0x0E, 0x31, 0xAC, 0x39, 0xC8, 0x76, 0xA9, 0xE9, 0x8C, 0xC3, 0xE3, 0x3C, 0x79, 0x4E,
+    0x14, 0x21, 0x4B, 0xDE, 0x6D, 0xC4, 0xE9, 0xC9, 0x75, 0xBA, 0x9C, 0x2D, 0x14, 0xD4, 0xB2, 0xFF
+};
+
+const uint32_t data_crc = 0x7322E75E;
+
+#endif

+ 2 - 2
test/unittest/shellmatta_utils/test_utils_writeEcho.cpp

@@ -18,7 +18,7 @@ TEST_CASE( "shellmatta_writeEcho echo enabled" ) {
 
     shellmatta_instance_t inst;
     char buffer[20] = {0};
-    char dummyData[29] = {0};
+    char dummyData[29] = "asd";
 
     inst.buffer = buffer;
     inst.bufferSize = 20;
@@ -43,7 +43,7 @@ TEST_CASE( "shellmatta_writeEcho echo disabled" ) {
 
     shellmatta_instance_t inst;
     char buffer[20] = {0};
-    char dummyData[29] = {0};
+    char dummyData[29] = "asd";
 
     inst.buffer = buffer;
     inst.bufferSize = 20;