Переглянути джерело

improved documentation of transport layer and fixed reset function

Strobel, Stefan | Friedrich Lütze GmbH 9 місяців тому
батько
коміт
646c38b793
1 змінених файлів з 30 додано та 20 видалено
  1. 30 20
      src/shellmatta_transport.c

+ 30 - 20
src/shellmatta_transport.c

@@ -46,13 +46,13 @@ static shellmatta_retCode_t shellmatta_transport_send(shellmatta_transport_layer
 
     crc = crc32Calc((char*) packet, SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength);
 
-    /* append crc to end of payload */
+    /** -# 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 */
+    /** -# use original write function to send full buffer */
     return transportLayer->writeFct((char*) rawPacket,
                                     SHELLMATTA_TRANSPORT_LENGTH_STATIC +
                                     header->payloadLength);
@@ -67,6 +67,7 @@ static shellmatta_retCode_t shellmatta_transport_send(shellmatta_transport_layer
 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;
 
@@ -127,13 +128,16 @@ shellmatta_retCode_t shellmatta_transport_reset(shellmatta_handle_t handle)
     if(     (NULL               != inst)
         &&  (SHELLMATTA_MAGIC   == inst->magic))
     {
+        /** -# set transport layer back to initial state */
         shellmatta_transport_layer_t *transportLayer = &inst->transportLayer;
-        uint8_t sequenceH2S = transportLayer->sequenceH2S;
-        uint8_t sequenceS2H = transportLayer->sequenceS2H;
-        memset(transportLayer, 0u, sizeof(shellmatta_transport_layer_t));
 
-        transportLayer->sequenceH2S = sequenceH2S;
-        transportLayer->sequenceS2H = sequenceS2H;
+        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
     {
@@ -217,7 +221,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
 
         break;
 
-    /* read payload for previously read length of payload */
+    /** -# read payload for previously read length of payload */
     case SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD:
 
         transportLayer->inPacket.payload[transportLayer->payloadIndex] = byte;
@@ -229,7 +233,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
         }
         break;
 
-    /* read crc32 for four bytes */
+    /** -# read crc32 for four bytes */
     case SHELLMATTA_TRANSPORT_STATE_GET_CRC:
 
         transportLayer->crcIndex ++;
@@ -241,10 +245,9 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
                                                    rawPacket,
                                                    SHELLMATTA_TRANSPORT_LENGTH_HEADER + header->payloadLength);
 
-            /* if crc is correct, further handling of data depends on type of packet */
+            /** -# if crc is correct, further handling of data depends on type of packet */
             if (transportLayer->inPacket.crc == refCrc)
             {
-
                 transportLayer->active = true;
 
                 /* crc is correct */
@@ -253,54 +256,60 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
                 switch (header->packetType)
                 {
                 case SHELLMATTA_TRANSPORT_PACKET_DATA:
-                    /** return pointer to payload and length */
+                    /** -# 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 */
+                    /** -# 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;
 
-                /* wrong packet type */
                 default:
-                    /* undo sequence counter increment */
+                    /** -# undo sequence counter increment on wrong packet type */
                     transportLayer->sequenceH2S--;
                     break;
                 }
             }
             else
             {
-                /* crc is incorrect */
+                /** -#  return error if crc is incorrect */
                 ret = SHELLMATTA_ERROR;
             }
 
-            /* reset state machine */
+            /** -# reset state machine */
             transportLayer->state = SHELLMATTA_TRANSPORT_STATE_WAIT;
         }
         break;
@@ -323,6 +332,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
  * 
  * @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,
@@ -334,13 +344,13 @@ shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *tr
     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;
+    /** -# 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 */
+    /** -# foot-controlled loop to send packets without payload length */
     do
     {
         piledUpPayload = header->payloadLength;