This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 65c47238a5c3d7d5c6e931376f4e7e630ac59cc4
Author: Christopher Collins <ccoll...@apache.org>
AuthorDate: Fri May 10 18:40:04 2019 -0700

    sys/shell: Change the OS cmds to extended
    
    This allows the OS shell commands to be executed via newtmgr.
---
 sys/shell/src/shell_os.c | 95 +++++++++++++++++++-----------------------------
 1 file changed, 37 insertions(+), 58 deletions(-)

diff --git a/sys/shell/src/shell_os.c b/sys/shell/src/shell_os.c
index a4d0cdf..098e4f4 100644
--- a/sys/shell/src/shell_os.c
+++ b/sys/shell/src/shell_os.c
@@ -26,13 +26,15 @@
 
 #include "hal/hal_system.h"
 #include "hal/hal_nvreg.h"
+#include "streamer/streamer.h"
 #include "shell/shell.h"
 #include "shell_priv.h"
 
 #define SHELL_OS "os"
 
-int
-shell_os_tasks_display_cmd(int argc, char **argv)
+static int
+shell_os_tasks_display_cmd(const struct shell_cmd *cmd, int argc, char **argv,
+                           struct streamer *streamer)
 {
     struct os_task *prev_task;
     struct os_task_info oti;
@@ -46,9 +48,9 @@ shell_os_tasks_display_cmd(int argc, char **argv)
         name = argv[1];
     }
 
-    console_printf("Tasks: \n");
+    streamer_printf(streamer, "Tasks: \n");
     prev_task = NULL;
-    console_printf("%8s %3s %3s %8s %8s %8s %8s %8s %8s %3s\n",
+    streamer_printf(streamer, "%8s %3s %3s %8s %8s %8s %8s %8s %8s %3s\n",
       "task", "pri", "tid", "runtime", "csw", "stksz", "stkuse",
       "lcheck", "ncheck", "flg");
     while (1) {
@@ -65,7 +67,7 @@ shell_os_tasks_display_cmd(int argc, char **argv)
             }
         }
 
-        console_printf("%8s %3u %3u %8lu %8lu %8u %8u %8lu %8lu\n",
+        streamer_printf(streamer, "%8s %3u %3u %8lu %8lu %8u %8u %8lu %8lu\n",
                 oti.oti_name, oti.oti_prio, oti.oti_taskid,
                 (unsigned long)oti.oti_runtime, (unsigned long)oti.oti_cswcnt,
                 oti.oti_stksize, oti.oti_stkusage,
@@ -75,14 +77,15 @@ shell_os_tasks_display_cmd(int argc, char **argv)
     }
 
     if (name && !found) {
-        console_printf("Couldn't find task with name %s\n", name);
+        streamer_printf(streamer, "Couldn't find task with name %s\n", name);
     }
 
     return 0;
 }
 
 int
-shell_os_mpool_display_cmd(int argc, char **argv)
+shell_os_mpool_display_cmd(const struct shell_cmd *cmd, int argc, char **argv,
+                           struct streamer *streamer)
 {
     struct os_mempool *mp;
     struct os_mempool_info omi;
@@ -96,10 +99,10 @@ shell_os_mpool_display_cmd(int argc, char **argv)
         name = argv[1];
     }
 
-    console_printf("Mempools: \n");
+    streamer_printf(streamer, "Mempools: \n");
     mp = NULL;
-    console_printf("%32s %5s %4s %4s %4s\n", "name", "blksz", "cnt", "free",
-                   "min");
+    streamer_printf(streamer, "%32s %5s %4s %4s %4s\n",
+                    "name", "blksz", "cnt", "free", "min");
     while (1) {
         mp = os_mempool_info_get_next(mp, &omi);
         if (mp == NULL) {
@@ -114,13 +117,13 @@ shell_os_mpool_display_cmd(int argc, char **argv)
             }
         }
 
-        console_printf("%32s %5d %4d %4d %4d\n", omi.omi_name,
+        streamer_printf(streamer, "%32s %5d %4d %4d %4d\n", omi.omi_name,
                        omi.omi_block_size, omi.omi_num_blocks,
                        omi.omi_num_free, omi.omi_min_free);
     }
 
     if (name && !found) {
-        console_printf("Couldn't find a memory pool with name %s\n",
+        streamer_printf(streamer, "Couldn't find a memory pool with name %s\n",
                 name);
     }
 
@@ -128,7 +131,8 @@ shell_os_mpool_display_cmd(int argc, char **argv)
 }
 
 int
-shell_os_date_cmd(int argc, char **argv)
+shell_os_date_cmd(const struct shell_cmd *cmd, int argc, char **argv,
+                  struct streamer *streamer)
 {
     int rc;
 #if MYNEWT_VAL(SHELL_OS_DATETIME_CMD)
@@ -146,7 +150,7 @@ shell_os_date_cmd(int argc, char **argv)
         assert(rc == 0);
         rc = datetime_format(&tv, &tz, buf, sizeof(buf));
         assert(rc == 0);
-        console_printf("%s\n", buf);
+        streamer_printf(streamer, "%s\n", buf);
 #endif
     } else if (argc == 1) {
 #if (MYNEWT_VAL(SHELL_OS_DATETIME_CMD) & 2) == 2
@@ -155,7 +159,7 @@ shell_os_date_cmd(int argc, char **argv)
         if (rc == 0) {
             rc = os_settimeofday(&tv, &tz);
         } else {
-            console_printf("Invalid datetime\n");
+            streamer_printf(streamer, "Invalid datetime\n");
         }
 #endif
     } else {
@@ -166,13 +170,14 @@ shell_os_date_cmd(int argc, char **argv)
 }
 
 int
-shell_os_reset_cmd(int argc, char **argv)
+shell_os_reset_cmd(const struct shell_cmd *cmd, int argc, char **argv,
+                   struct streamer *streamer)
 {
 #if MYNEWT_VAL(SHELL_OS_SERIAL_BOOT_NVREG)
     if (argc == 2 && !strcmp(argv[1], "serial_boot")) {
         hal_nvreg_write(MYNEWT_VAL(BOOT_SERIAL_NVREG_INDEX),
                         MYNEWT_VAL(BOOT_SERIAL_NVREG_MAGIC));
-        console_printf("serial_boot mode\n");
+        streamer_printf(streamer, "serial_boot mode\n");
     }
 #endif
     os_time_delay(OS_TICKS_PER_SEC / 10);
@@ -183,16 +188,20 @@ shell_os_reset_cmd(int argc, char **argv)
 static int
 shell_os_ls_dev(struct os_dev *dev, void *arg)
 {
-    console_printf("%4d %3x %s\n",
-                   dev->od_open_ref, dev->od_flags, dev->od_name);
+    struct streamer *streamer;
+
+    streamer = arg;
+    streamer_printf(streamer, "%4d %3x %s\n",
+                    dev->od_open_ref, dev->od_flags, dev->od_name);
     return 0;
 }
 
 int
-shell_os_ls_dev_cmd(int argc, char **argv)
+shell_os_ls_dev_cmd(const struct shell_cmd *cmd, int argc, char **argv,
+                    struct streamer *streamer)
 {
-    console_printf("%4s %3s %s\n", "ref", "flg", "name");
-    os_dev_walk(shell_os_ls_dev, NULL);
+    streamer_printf(streamer, "%4s %3s %s\n", "ref", "flg", "name");
+    os_dev_walk(shell_os_ls_dev, streamer);
     return 0;
 }
 
@@ -253,42 +262,12 @@ static const struct shell_cmd_help ls_dev_help = {
 #endif
 
 static const struct shell_cmd os_commands[] = {
-    {
-        .sc_cmd = "tasks",
-        .sc_cmd_func = shell_os_tasks_display_cmd,
-#if MYNEWT_VAL(SHELL_CMD_HELP)
-        .help = &tasks_help,
-#endif
-    },
-    {
-        .sc_cmd = "mpool",
-        .sc_cmd_func = shell_os_mpool_display_cmd,
-#if MYNEWT_VAL(SHELL_CMD_HELP)
-        .help = &mpool_help,
-#endif
-    },
-    {
-        .sc_cmd = "date",
-        .sc_cmd_func = shell_os_date_cmd,
-#if MYNEWT_VAL(SHELL_CMD_HELP)
-        .help = &date_help,
-#endif
-    },
-    {
-        .sc_cmd = "reset",
-        .sc_cmd_func = shell_os_reset_cmd,
-#if MYNEWT_VAL(SHELL_CMD_HELP)
-        .help = &reset_help,
-#endif
-    },
-    {
-        .sc_cmd = "lsdev",
-        .sc_cmd_func = shell_os_ls_dev_cmd,
-#if MYNEWT_VAL(SHELL_CMD_HELP)
-        .help = &ls_dev_help,
-#endif
-    },
-    { NULL, NULL, NULL },
+    SHELL_CMD_EXT("tasks", shell_os_tasks_display_cmd, &tasks_help),
+    SHELL_CMD_EXT("mpool", shell_os_mpool_display_cmd, &mpool_help),
+    SHELL_CMD_EXT("date", shell_os_date_cmd, &date_help),
+    SHELL_CMD_EXT("reset", shell_os_reset_cmd, &reset_help),
+    SHELL_CMD_EXT("lsdev", shell_os_ls_dev_cmd, &ls_dev_help),
+    { 0 },
 };
 
 void

Reply via email to