Browse Source

handle transport layer header instead of processing as input

Fischer, Simon 3 năm trước cách đây
mục cha
commit
6d7f31cba6
1 tập tin đã thay đổi với 73 bổ sung1 xóa
  1. 73 1
      src/shellmatta.c

+ 73 - 1
src/shellmatta.c

@@ -23,6 +23,7 @@
 #include "shellmatta_utils.h"
 #include "shellmatta_escape.h"
 #include "shellmatta_opt.h"
+#include "shellmatta_transport.h"
 #include <stddef.h>
 #include <string.h>
 #include <stdarg.h>
@@ -117,6 +118,9 @@ shellmatta_retCode_t shellmatta_doInit(
 
         /** -# print the first prompt */
         utils_terminateInput(inst);
+
+        /* init transport layer */
+        shellmatta_init_transport_inst();
     }
 
     return SHELLMATTA_OK;
@@ -382,6 +386,74 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
     if(     (NULL               != inst)
         &&  (SHELLMATTA_MAGIC   == inst->magic))
     {
+
+        uint8_t headerCounter = 0;
+        while ( (size >= headerCounter) 
+            ||  (   (true == transportLayerInst.mandatory)
+                &&  (size >= headerCounter)))
+        {
+            /* if payload is reached, continue with usual behaviour */
+            if (STATE_GET_PAYLOAD == transportLayerInst.state)
+            {
+                break;
+            }
+
+            switch (transportLayerInst.state)
+            {
+            case STATE_GET_SOH:
+                /* wait for SOH or go to payload */
+                break;
+
+            case STATE_GET_PROTOCOL_VERSION:
+                protocolVersion = data[headerCounter];
+                break;
+
+            case STATE_GET_PACKET_TYPE:
+                packetType = data[headerCounter];
+                break;
+
+            case STATE_GET_PAYLOAD_LENGTH:
+                payloadLength = data[headerCounter];
+                break;
+
+            case STATE_GET_SOURCE:
+                source = data[headerCounter];
+                break;
+
+            case STATE_GET_DESTINATION:
+                destination = data[headerCounter];
+                break;
+            
+            case STATE_GET_H2S_SEQUENCE_CNT:
+                transportLayerInst.h2s_sequenceCnt = data[headerCounter];
+                break;
+            
+            case STATE_GET_S2H_SEQUENCE_CNT:
+                transportLayerInst.s2h_sequenceCnt = data[headerCounter];
+                break;
+
+            case STATE_GET_CRC:
+                crc32 |= data[headerCounter] << (SHELLMATTA_LENGTH_CRC - crcCounter++);
+                break;
+            
+            default:
+                break;
+            }
+            /* handling of transport layer fsm */
+            shellmatta_handle_transport_fsm(&transportLayerInst, data);
+            headerCounter++;
+        }
+
+        /* if all data is processed but transport layer fsm is still not in payload, return */
+        if (transportLayerInst.state != STATE_GET_PAYLOAD)
+        {
+            return SHELLMATTA_OK;
+        }
+        else
+        {
+            payloadCounter += size;
+        }
+
         /** -# in busy mode - keep calling this command */
         if(NULL != inst->busyCmd)
         {
@@ -654,7 +726,7 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t     handle,
                 }
             }
             /** -# ignore newline as first character (to be compatible to
-             * terminals sending newline after return */
+             * terminals sending newline after return) */
             else if((0u == inst->inputCount) && ('\n' == data[inst->byteCounter]))
             {
                 /* do nothing */