Browse Source

added documenting comments

Fischer, Simon 3 năm trước cách đây
mục cha
commit
f9b39aa2e1
1 tập tin đã thay đổi với 27 bổ sung9 xóa
  1. 27 9
      src/shellmatta_transport.c

+ 27 - 9
src/shellmatta_transport.c

@@ -10,11 +10,9 @@
 #include <stdio.h>
 
 /* init global variables */
-uint32_t sentPayloadBytes = 0;
-
 uint8_t protocolVersion                     = 0u;
 shellmatta_transport_packet_t packetType    = 0u;
-uint8_t payloadLength                       = 0u;
+uint32_t payloadLength                      = 0u;
 uint8_t source                              = 0u;
 uint8_t destination                         = 0u;
 uint32_t crc32                              = 0u;
@@ -33,6 +31,10 @@ shellmatta_transport_layer_t transportLayerInst = {
 };
 char payloadBuffer[SHELLMATTA_PAYLOAD_MAXLENGTH + 1];
 
+/**
+ * @brief       Initializes the transportLayerInst
+ * @return      errorcode   #SHELLMATTA_OK
+ */
 shellmatta_retCode_t shellmatta_init_transport_inst()
 {
     transportLayerInst.h2s_sequenceCnt = 0;
@@ -46,6 +48,10 @@ shellmatta_retCode_t shellmatta_init_transport_inst()
     return SHELLMATTA_OK;
 }
 
+/**
+ * @brief       Resets all values of tranportLayerInst except for sequence counters
+ * @return      errorcode   #SHELLMATTA_OK
+ */
 shellmatta_retCode_t shellmatta_reset_transport()
 {
     transportLayerInst.state = STATE_GET_SOH;
@@ -63,6 +69,12 @@ shellmatta_retCode_t shellmatta_reset_transport()
     return SHELLMATTA_OK;
 }
 
+/**
+ * @brief       processes the passed amount of data
+ * @param[in]   data    pointer to input data to process
+ * @return      errorcode   #SHELLMATTA_OK
+ *                          #SHELLMATTA_ERROR   in case of crc error
+ */
 shellmatta_retCode_t shellmatta_handle_transport_fsm(char *data)
 {
     switch (transportLayerInst.state)
@@ -129,7 +141,7 @@ shellmatta_retCode_t shellmatta_handle_transport_fsm(char *data)
     case STATE_GET_CRC:
         if (SHELLMATTA_LENGTH_CRC <= crcCounter)
         {
-            
+            /* for crc computation only */
             char crcdata[SHELLMATTA_PAYLOAD_MAXLENGTH + 1 + SHELLMATTA_HEADER_LENGTH];
             memset(crcdata, 0, SHELLMATTA_PAYLOAD_MAXLENGTH + 1 + SHELLMATTA_HEADER_LENGTH);
             crcdata[0] = SHELLMATTA_START_OF_HEADER;
@@ -166,10 +178,6 @@ shellmatta_retCode_t shellmatta_handle_transport_fsm(char *data)
                     packetType = PACKET_SEQ_CNT_RESPOND;
                     /* send out packet with no payload */
                     shellmatta_write_transport("", 0);
-                    if (transportLayerInst.h2s_sequenceCnt != packetSequenceCounter_h2s)
-                    {
-                        crc32 = 0;
-                    }
                     break;
 
                 case PACKET_SEQ_CNT_RESPOND:
@@ -235,6 +243,16 @@ shellmatta_retCode_t shellmatta_handle_transport_fsm(char *data)
     return SHELLMATTA_OK;
 }
 
+/**
+ * @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
+ * 
+ * @param[in]   data    pointer to input data to process
+ * @return      errorcode   #SHELLMATTA_OK
+ */
 shellmatta_retCode_t shellmatta_write_transport(const char* data, uint32_t length)
 {
     /* create buffer for data + header + crc with maximum size */
@@ -254,7 +272,7 @@ shellmatta_retCode_t shellmatta_write_transport(const char* data, uint32_t lengt
     outputBuffer[6] = transportLayerInst.h2s_sequenceCnt;   /* sequence counter host to shellmatta */
     outputBuffer[7] = ++transportLayerInst.s2h_sequenceCnt; /* sequence counter shellmatta to host */
 
-    /* response of sequence counters is only packet type without payload */
+    /* skip copying of payload in case of sequence counter response */
     if (packetType != PACKET_SEQ_CNT_RESPOND)
     {
         memcpy(&outputBuffer[8], data, length);