Parcourir la source

extended example with a ymodem command

Strobel, Stefan | Friedrich Lütze GmbH il y a 9 mois
Parent
commit
0cab765489
1 fichiers modifiés avec 19 ajouts et 6 suppressions
  1. 19 6
      example/main.c

+ 19 - 6
example/main.c

@@ -209,17 +209,17 @@ static shellmatta_retCode_t ymodem(shellmatta_handle_t handle, const char *argum
     if (SHELLMATTA_OK == ret)
     {
         shellmatta_printf(handle, "Starting ymodem session\r\n");
-        shellmatta_ymodem(handle,
-                        ymodemBuffer,
-                        &ymodemFileSize,
-                        &ymodemPacketSize,
-                        ymodemCallbacks);
         ret = SHELLMATTA_CONTINUE;
     }
+    shellmatta_ymodem(handle,
+                    ymodemBuffer,
+                    &ymodemFileSize,
+                    &ymodemPacketSize,
+                    ymodemCallbacks);
 
     return ret;
 }
-shellmatta_cmd_t ymodemCommand = {"ymodem", NULL, NULL, NULL, ymodem, NULL};
+shellmatta_cmd_t ymodemCommand = {"ymodem", NULL, NULL, NULL, ymodem, NULL, NULL};
 
 
 shellmatta_retCode_t writeFct(const char* data, uint32_t length)
@@ -283,18 +283,31 @@ int main(int argc, char **argv)
 
     shellmatta_auth_init(handle, userList, 2, permList, 2, false, NULL, NULL);
 
+    int i = 0;
     while(exitRequest == false)
     {
         char c;
         shellmatta_retCode_t ret;
+        int flags = fcntl(f, F_GETFL, 0);
+        fcntl(f, F_SETFL, flags | O_NONBLOCK);
         int res = 0;
         res = read (f, &c, 1);
+        if (res == -1)
+        {
+            i = (i + 1) % 1000;
+            usleep(1);
+            if (i != 0)
+            {
+                continue;
+            }
+        }
 
         fprintf(stdout, "0x%02x \n", c);
         fflush(stdout);
 
         do
         {
+            res = res > 0 ? res : 0;
             ret = shellmatta_processData(handle, &c, res);
             if(SHELLMATTA_BUSY == ret)
             {