Natural Tiny Shell (NT-Shell) library is a tiny shell library for a small embedded system. The interface is really simple. You should only know ntshell_execute in ntshell.h. So you can port it to any embedded system easily. Please enjoy your small embedded system with it. :)

Dependencies:   mbed NaturalTinyShell

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Sun May 22 02:52:46 2011 +0000
Child:
1:215d60da45d1
Commit message:
Initial version.

Changed in this revision

cmd.c Show annotated file Show diff for this revision Revisions of this file
cmd.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mylib/NaturalTinyShell.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd.c	Sun May 22 02:52:46 2011 +0000
@@ -0,0 +1,47 @@
+/*
+ * ===============================================================
+ *  Natural Tiny Shell (NT-Shell) Application example.
+ *  Version 0.0.6
+ * ===============================================================
+ * Copyright (c) 2010-2011 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#include "cmd.h"
+#include <mbed.h>
+
+void cmd_foo(int argc, char **argv)
+{
+    printf("This is %s\n", __func__);
+}
+
+void cmd_bar(int argc, char **argv)
+{
+    printf("This is %s\n", __func__);
+}
+
+void cmd_baz(int argc, char **argv)
+{
+    printf("This is %s\n", __func__);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd.h	Sun May 22 02:52:46 2011 +0000
@@ -0,0 +1,39 @@
+/*
+ * ===============================================================
+ *  Natural Tiny Shell (NT-Shell) Application example.
+ *  Version 0.0.6
+ * ===============================================================
+ * Copyright (c) 2010-2011 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#ifndef CMD_H
+#define CMD_H
+
+// Please add your commands.
+void cmd_foo(int argc, char **argv);
+void cmd_bar(int argc, char **argv);
+void cmd_baz(int argc, char **argv);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 22 02:52:46 2011 +0000
@@ -0,0 +1,112 @@
+/*
+ * ===============================================================
+ *  Natural Tiny Shell (NT-Shell) Application example.
+ *  Version 0.0.6
+ * ===============================================================
+ * Copyright (c) 2010-2011 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#include "mbed.h"
+#include "ntshell.h"
+#include "ntopt.h"
+#include "cmd.h"
+
+DigitalOut myled(LED1);
+Serial serial(USBTX, USBRX);
+ntshell_t ntshell;
+
+typedef struct {
+    char *command;
+    char *description;
+    void (*func)(int argc, char **argv);
+} command_table_t;
+
+const command_table_t cmdlist[] = {
+    {"foo", "foo command", cmd_foo },
+    {"bar", "bar command", cmd_bar },
+    {"baz", "baz command", cmd_baz },
+    {NULL, NULL, NULL}
+};
+
+int func_read(char *buf, int cnt);
+int func_write(const char *buf, int cnt);
+int func_cb_ntshell(const char *text);
+void func_cb_ntopt(int argc, char **argv);
+
+/**
+ * Serial read function.
+ */
+int func_read(char *buf, int cnt) {
+    for (int i = 0; i < cnt; i++) {
+        buf[i] = serial.getc();
+    }
+    return 0;
+}
+
+/**
+ * Serial write function.
+ */
+int func_write(const char *buf, int cnt) {
+    for (int i = 0; i < cnt; i++) {
+        serial.putc(buf[i]);
+    }
+    return 0;
+}
+
+/**
+ * Callback function for ntshell module.
+ */
+int func_cb_ntshell(const char *text) {
+    return ntopt_parse(text, func_cb_ntopt);
+}
+
+/**
+ * Callback function for ntopt module.
+ */
+void func_cb_ntopt(int argc, char **argv) {
+    if (argc == 0) {
+        return;
+    }    
+    int execnt = 0;
+    const command_table_t *p = &cmdlist[0];
+    while (p->command != NULL) {
+        if (strcmp(argv[0], p->command) == 0) {
+            p->func(argc, argv);
+            execnt++;
+        }
+        p++;
+    }
+    if (execnt == 0) {
+        printf("Command not found.\n");
+    }
+    wait_ms(250);
+}
+
+/**
+ * Application code.
+ */
+int main() {
+    ntshell_execute(&ntshell, func_read, func_write, func_cb_ntshell);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun May 22 02:52:46 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/NaturalTinyShell.lib	Sun May 22 02:52:46 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/NaturalTinyShell/#7147d6024de8