sys/shell: add backwards compatible API

This patch adds missing API that is used by some apps. It adds
'compat' module to the shell and assigns commands added from existing
apps to this module. With this change all existing apps can be used with
new shell.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/31d56fcd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/31d56fcd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/31d56fcd

Branch: refs/heads/master
Commit: 31d56fcdd1baeb80c3a9cefa3433bf3b86a01761
Parents: 1151ca8
Author: Michał Narajowski <michal.narajow...@codecoup.pl>
Authored: Wed May 3 10:53:31 2017 +0200
Committer: Michał Narajowski <michal.narajow...@codecoup.pl>
Committed: Wed May 3 11:37:52 2017 +0200

----------------------------------------------------------------------
 sys/shell/include/shell/shell.h |  4 ++++
 sys/shell/src/shell.c           | 27 +++++++++++++++++++++++++++
 sys/shell/syscfg.yml            |  6 ++++++
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/31d56fcd/sys/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/sys/shell/include/shell/shell.h b/sys/shell/include/shell/shell.h
index d056e65..fdb263a 100644
--- a/sys/shell/include/shell/shell.h
+++ b/sys/shell/include/shell/shell.h
@@ -101,6 +101,10 @@ void shell_register_prompt_handler(shell_prompt_function_t 
handler);
  */
 void shell_register_default_module(const char *name);
 
+#if MYNEWT_VAL(SHELL_COMPAT)
+int shell_cmd_register(struct shell_cmd *sc);
+#endif
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/31d56fcd/sys/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index c91dd42..f33f4ba 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -449,6 +449,33 @@ shell_register(const char *module_name, const struct 
shell_cmd *commands)
     return 0;
 }
 
+#if MYNEWT_VAL(SHELL_COMPAT)
+#define SHELL_COMPAT_MODULE_NAME "compat"
+static struct shell_cmd compat_commands[MYNEWT_VAL(SHELL_MAX_COMPAT_COMMANDS)];
+static int num_compat_commands;
+static int module_registered = 0;
+
+int
+shell_cmd_register(struct shell_cmd *sc)
+{
+    if (num_compat_commands >= MYNEWT_VAL(SHELL_MAX_COMPAT_COMMANDS)) {
+        console_printf("Max number of compat commands reached");
+        assert(0);
+    }
+
+    if (!module_registered) {
+        shell_register(SHELL_COMPAT_MODULE_NAME, compat_commands);
+        set_default_module(SHELL_COMPAT_MODULE_NAME);
+        module_registered = 0;
+    }
+
+    compat_commands[num_compat_commands].sc_cmd = sc->sc_cmd;
+    compat_commands[num_compat_commands].sc_cmd_func = sc->sc_cmd_func;
+    ++num_compat_commands;
+    return 0;
+}
+#endif
+
 void
 shell_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/31d56fcd/sys/shell/syscfg.yml
----------------------------------------------------------------------
diff --git a/sys/shell/syscfg.yml b/sys/shell/syscfg.yml
index 8a53bff..4b841fe 100644
--- a/sys/shell/syscfg.yml
+++ b/sys/shell/syscfg.yml
@@ -35,3 +35,9 @@ syscfg.defs:
     SHELL_MAX_CMD_QUEUED:
         description: 'Max number of command lines queued'
         value: 1
+    SHELL_COMPAT:
+        description: 'Enable compatibility module'
+        value: 1
+    SHELL_MAX_COMPAT_COMMANDS:
+        description: 'Max number of compatibility commands'
+        value: 10

Reply via email to