소스 검색

moved around implementations of ymodem functions

Strobel, Stefan | Friedrich Lütze GmbH 9 달 전
부모
커밋
82e14ac80f
5개의 변경된 파일515개의 추가작업 그리고 564개의 파일을 삭제
  1. 32 13
      api/shellmatta.h
  2. 4 12
      example/main.c
  3. 7 4
      src/shellmatta.c
  4. 464 518
      src/shellmatta_ymodem.c
  5. 8 17
      src/shellmatta_ymodem.h

+ 32 - 13
api/shellmatta.h

@@ -197,17 +197,38 @@ typedef struct shellmatta_cmd
  */
 typedef enum
 { 
-    INACTIVE,           /* YModem module not initialised */
-    WAIT_FOR_START,     /* waiting for start of header */
-    RECEIVE_PACKET,     /* currently receiving a packet */
+    SHELLMATTA_YMODEM_INACTIVE,         /**< YModem module not initialised  */
+    SHELLMATTA_YMODEM_WAIT_FOR_START,   /**< waiting for start of header    */
+    SHELLMATTA_YMODEM_RECEIVE_HEADER,   /**< reading header data            */
+    SHELLMATTA_YMODEM_RECEIVE_DATA,     /**< reading payload                */
+    SHELLMATTA_YMODEM_RECEIVE_CRC       /**< reading crc                    */
 } shellmatta_ymodem_state_t;
 
+/** @brief packet structure that holds several information about its content */
 typedef struct
 {
-    void (*yModemCancelCallback)(void);
-    void (*yModemRecvPacketCallback)(void);
-    void (*ymodemTransmissionCompleteCallback)(void);
-} shellmatta_ymodem_callbacks_t;
+    uint16_t size;          /**< site of the packet (128 or 1024)     */
+    uint8_t packetNumber;   /**< packet number in this packet         */
+    uint8_t* packetData;    /**< pointer to the data of this packet   */
+    uint16_t crc;           /**< crc checksum in this packet          */
+} shellmatta_ymodem_packet_t;
+
+/**
+ * @brief definition of shellmatta ymodem instance
+ */
+typedef struct
+{
+    shellmatta_ymodem_state_t state;
+    uint32_t byteCounter;
+    uint32_t packetCounter;
+    uint32_t totalBytesReceived;
+    char *fileName;
+    uint32_t fileSize;
+    shellmatta_ymodem_packet_t packet;
+    void (*cancelCallback)(void);
+    void (*recvPacketCallback)(void);
+    void (*transmissionCompleteCallback)(void);
+} shellmatta_ymodem_t;
 
 #ifdef SHELLMATTA_TRANSPORT
 
@@ -319,7 +340,7 @@ typedef struct
     bool                            cmdListIsConst;     /**< true if the #cmdList was passed during
                                                              initialization                         */
     shellmatta_opt_t                optionParser;       /**< option parser sructure                 */
-    shellmatta_ymodem_state_t       ymodemState;        /**< current state of the ymodem module     */
+    shellmatta_ymodem_t             ymodem;             /**< ymodem instance                        */
 #ifdef SHELLMATTA_AUTHENTICATION
     shellmatta_auth_state_t         loginState;         /**< state variable of the login cmd        */
     shellmatta_cmd_t                loginCmd;           /**< login command structure                */
@@ -446,14 +467,12 @@ shellmatta_retCode_t shellmatta_auth_chpasswd(              shellmatta_handle_t
 
 uint8_t shellmatta_ymodem(      shellmatta_handle_t             handle,
                                 uint8_t*                        buffer,
-                                uint32_t*                       fileSize,
-                                uint16_t*                       packetSize,
-                                shellmatta_ymodem_callbacks_t   callbacks);
+                                void (*cancelCallback)(void),
+                                void (*recvPacketCallback)(void),
+                                void (*transmissionCompleteCallback)(void));
 
 void shellmatta_ymodem_cancel(  shellmatta_handle_t             handle);
 
-bool shellmatta_ymodem_is_active(void);
-
 #endif
 
 /** @} */

+ 4 - 12
example/main.c

@@ -192,14 +192,6 @@ void ymodemCallbackTransmissionComplete() {
 
 
 uint8_t ymodemBuffer[1024u] = {0};
-uint32_t ymodemFileSize = 0;
-uint16_t ymodemPacketSize = 0;
-shellmatta_ymodem_callbacks_t ymodemCallbacks = {
-    ymodemCallbackCancel,
-    ymodemCallbackReceivePacket,
-    ymodemCallbackTransmissionComplete
-};
-
 
 static shellmatta_retCode_t ymodem(shellmatta_handle_t handle, const char *arguments, uint32_t length)
 {
@@ -207,10 +199,10 @@ static shellmatta_retCode_t ymodem(shellmatta_handle_t handle, const char *argum
     (void)length;
     shellmatta_printf(handle, "Starting ymodem session\r\n");
     shellmatta_ymodem(handle,
-                    ymodemBuffer,
-                    &ymodemFileSize,
-                    &ymodemPacketSize,
-                    ymodemCallbacks);
+                      ymodemBuffer,
+                      ymodemCallbackCancel,
+                      ymodemCallbackReceivePacket,
+                      ymodemCallbackTransmissionComplete);
 
     return SHELLMATTA_OK;
 }

+ 7 - 4
src/shellmatta.c

@@ -78,7 +78,11 @@ static shellmatta_retCode_t shellmatta_processDataInt(shellmatta_handle_t     ha
             utils_terminateInput(inst);
         }
     }
-    // todo call ymodem implementation to send initial NCKs
+    /** -# poll shellmatta ymomde to send out the request to the sender */
+    if(SHELLMATTA_YMODEM_WAIT_FOR_START == inst->ymodem.state)
+    {
+        (void)shellmatta_ymodem_poll(handle);
+    }
     /** -# call continuous function even if there is no data */
     else if((0u == size) && (NULL != inst->continuousCmd))
     {
@@ -112,7 +116,7 @@ static shellmatta_retCode_t shellmatta_processDataInt(shellmatta_handle_t     ha
     {
 
         /** -# handle ymodem when a session is active */
-        if (inst->ymodemState != INACTIVE)
+        if (inst->ymodem.state != SHELLMATTA_YMODEM_INACTIVE)
         {
             ret = shellmatta_ymodem_processByte(handle, data[inst->byteCounter]);
 
@@ -472,7 +476,6 @@ shellmatta_retCode_t shellmatta_doInit(
         inst->delimiter             = '\r';
         inst->mode                  = SHELLMATTA_MODE_INSERT;
         inst->cmdList               = &(inst->helpCmd);
-        inst->ymodemState           = INACTIVE;
         shellmatta_opt_init(inst, 0u);
 
         /** -# copy the help command structure to this instance */
@@ -547,7 +550,7 @@ shellmatta_retCode_t shellmatta_resetShell(shellmatta_handle_t handle, bool prin
         inst->hereStartIdx          = 0u;
         inst->hereDelimiterIdx      = 0u;
         inst->hereLength            = 0u;
-        inst->ymodemState           = INACTIVE;
+        inst->ymodem.state          = SHELLMATTA_YMODEM_INACTIVE; // todo move to shellmatta_ymodem
         shellmatta_opt_init(inst, 0u);
 
 #ifdef SHELLMATTA_AUTHENTICATION

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 464 - 518
src/shellmatta_ymodem.c


+ 8 - 17
src/shellmatta_ymodem.h

@@ -28,17 +28,6 @@ typedef enum {
     YMODEM_CRC     = 0x43  /* 'C' to indicate CRC type */
 } YMODEM_SYMBOLS;
 
-/** @brief packet structure that holds several information about its content */
-typedef struct
-{
-    uint8_t packetNumber;           /* packet number in this packet */
-    uint8_t reversePacketNumber;    /* reverse packet number in this packet */
-    uint16_t packetCrc;             /* crc checksum in this packet */
-    uint8_t* packetData;            /* pointer to the data of this packet */
-    uint16_t* packetSize;           /* pointer to the length of this packet */
-    uint32_t* fileSize;             /* pointer to the amount of bytes in this packet */
-} shellmatta_ymodem_packet_t;
-
 /**
  * @brief return codes for receive byte function of ymodem module
 */
@@ -58,17 +47,19 @@ typedef enum {
     YMODEM_FOOTER  /* end of transmission packet is transmitted */
 } shellmatta_ymodem_datatype_t;
 
-void shellmatta_ymodem_init(            shellmatta_handle_t             handle, 
+void shellmatta_ymodem_init(            shellmatta_ymodem_t             *ymodem, 
                                         uint8_t*                        recvBuffer, 
-                                        uint32_t*                       fileSize,
-                                        uint16_t*                       packetSize,
-                                        shellmatta_ymodem_callbacks_t   callbacks);
+                                        void                            (*cancelCallback)(void),
+                                        void                            (*recvPacketCallback)(void),
+                                        void                            (*transmissionCompleteCallback)(void));
 
 void shellmatta_ymodem_receive_packet(  shellmatta_handle_t             handle, 
                                         uint8_t                         byteIn);
 
 shellmatta_retCode_t shellmatta_ymodem_processByte( shellmatta_handle_t handle,
-                                                    char                *data);
+                                                    char                byte);
+
+shellmatta_retCode_t shellmatta_ymodem_poll(        shellmatta_handle_t handle);
 
 void shellmatta_ymodem_set_state(       shellmatta_handle_t             handle, 
                                         shellmatta_ymodem_state_t       newState);
@@ -87,7 +78,7 @@ void shellmatta_ymodem_nak(             shellmatta_handle_t handle);
 
 void shellmatta_ymodem_check_packet(    shellmatta_handle_t handle);
 
-void shellmatta_ymodem_reset(           shellmatta_handle_t handle,
+void shellmatta_ymodem_reset(           shellmatta_ymodem_t *ymodem,
                                         bool                doCancel);
 
 shellmatta_ymodem_datatype_t shellmatta_ymodem_get_current_datatype(void);