瀏覽代碼

added check for incomplete or superflous reception to ymodem module

stefan 9 月之前
父節點
當前提交
ba370ea951
共有 3 個文件被更改,包括 14 次插入5 次删除
  1. 3 1
      api/shellmatta.h
  2. 2 1
      example/main.c
  3. 9 3
      src/shellmatta_ymodem.c

+ 3 - 1
api/shellmatta.h

@@ -214,8 +214,10 @@ typedef void (*shellmatta_ymodem_recvPacket_t)(uint8_t *data, uint32_t packetSiz
 
 /**
  * @brief shellmatta ymodem transmission complete callback definition
+ * @param[in]   result      #SHELLMATTA_OK
+ *                          #SHELLMATTA_ERROR - missing data
  */
-typedef void (*shellmatta_ymodem_complete_t)(void);
+typedef void (*shellmatta_ymodem_complete_t)(shellmatta_retCode_t result);
 
 /**
  * @brief state enumeration for ymodem receive state machine

+ 2 - 1
example/main.c

@@ -209,8 +209,9 @@ void ymodemCallbackReceivePacket(uint8_t *data, uint32_t packetSize, uint32_t pa
     return;
 }
 
-void ymodemCallbackTransmissionComplete() {
+void ymodemCallbackTransmissionComplete(shellmatta_retCode_t result) {
     ret = SHELLMATTA_OK;
+    printf("\nTransmission complete: %s\n", result == SHELLMATTA_OK ? "success" : "error");
     return;
 }
 

+ 9 - 3
src/shellmatta_ymodem.c

@@ -145,10 +145,16 @@ static shellmatta_retCode_t ymodem_stateMachine(shellmatta_handle_t handle, uint
                     break;
 
                 case YMODEM_EOT:
-                    inst->ymodem.transmissionCompleteCallback();
+                    /** -# check if the received data matches the file size */
+                    if((inst->ymodem.totalBytesReceived < inst->ymodem.fileSize) ||
+                       ((inst->ymodem.totalBytesReceived - inst->ymodem.fileSize) >= YMODEM_PACKET_SIZE_1K))
+                    {
+                        ret = SHELLMATTA_ERROR;
+                    }
+
+                    inst->ymodem.transmissionCompleteCallback(ret);
 
-                    // todo check for a complete telegram having been received
-                    // ...add a wait state to answer some more EOTs after time
+                    // todo add a wait state to answer some more EOTs after time
 
                     /** -# ACK the successful file reception */
                     shellmatta_ymodem_control(handle, YMODEM_ACK);