Explorar el Código

implemented transport layers packet size interface

stefan hace 9 meses
padre
commit
65f61db822
Se han modificado 3 ficheros con 29 adiciones y 14 borrados
  1. 1 0
      api/shellmatta.h
  2. 7 1
      doc/shellmatta_transport_layer.dox
  3. 21 13
      src/shellmatta_transport.c

+ 1 - 0
api/shellmatta.h

@@ -255,6 +255,7 @@ typedef struct
     uint32_t                        headerIndex;        /**< read index of the header                       */
     uint32_t                        payloadIndex;       /**< read index of the payload                      */
     uint32_t                        crcIndex;           /**< read index of the checksum                     */
+    uint8_t                         hostBufferSize;     /**< buffersize of the host                         */
     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                      */

+ 7 - 1
doc/shellmatta_transport_layer.dox

@@ -87,7 +87,13 @@
 
     @section shellmatta_transport_layer_buffersize Buffer sizes
 
-    @todo Not implemented yet
+    The shellmatta always uses the maximum buffersize of
+    #SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH.
+    If the host has a smaller receive buffer this can be set using the 0x02
+    packet.
+
+    A host should use this packet to request the shellmatta buffersize.
+    This can be changed in the future.
 
 
     @section shellmatta_transport_layer_addressing Addressing and Search

+ 21 - 13
src/shellmatta_transport.c

@@ -69,6 +69,7 @@ shellmatta_retCode_t shellmatta_transport_init( shellmatta_transport_layer_t
 {
     /** -# clear instance and store write function */
     memset(transportLayer, 0u, sizeof(shellmatta_transport_layer_t));
+    transportLayer->hostBufferSize = SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH;
     transportLayer->writeFct = writeFct;
 
     return SHELLMATTA_OK;
@@ -261,7 +262,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
                     *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;
@@ -272,19 +273,26 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
                 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 */
+                    /** -# store the hosts buffersize */
+                    transportLayer->hostBufferSize = (uint8_t)transportLayer->inPacket.payload[0];
+
+                    /** -# respont with our own buffer size */
+                    intPacket.header.packetType = SHELLMATTA_TRANSPORT_PACKET_MAX_BUFFERSIZE_RESPOND;
+                    intPacket.header.payloadLength = 1u;
+                    intPacket.payload[0] = SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH;
+                    (void)shellmatta_transport_send(transportLayer, (shellmatta_transport_packet_t *)&intPacket);
                     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;
@@ -313,7 +321,7 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
             transportLayer->state = SHELLMATTA_TRANSPORT_STATE_WAIT;
         }
         break;
-    
+
     default:
         break;
     }
@@ -323,13 +331,13 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
 
 /**
  * @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
@@ -357,9 +365,9 @@ shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *tr
 
         /* compute length of next payload split */
         restOfPayload = (outPayloadLength - processedLength);
-        if (restOfPayload > (SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH - piledUpPayload))
+        if (restOfPayload > (transportLayer->hostBufferSize - piledUpPayload))
         {
-            splitLength = SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH - piledUpPayload;
+            splitLength = transportLayer->hostBufferSize - piledUpPayload;
         }
         else
         {
@@ -370,7 +378,7 @@ shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *tr
         header->payloadLength += splitLength;
         processedLength += splitLength;
 
-        if(header->payloadLength >= SHELLMATTA_TRANPORT_PAYLOAD_MAXLENGTH)
+        if(header->payloadLength >= transportLayer->hostBufferSize)
         {
             /** -# packet is full - send */
             header->packetType = SHELLMATTA_TRANSPORT_PACKET_DATA;
@@ -384,7 +392,7 @@ shellmatta_retCode_t shellmatta_transport_write(shellmatta_transport_layer_t *tr
 
 /**
  * @brief           Send out piled up payload
- * 
+ *
  * @param[in, out]  handle      shellmatta handle of the instance
  * @return          errorcode
  */