You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/08/25 20:19:27 UTC
[1/3] incubator-mynewt-core git commit: shell prompt in own files
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 5fa1a912e -> f95bda8c2
shell prompt in own files
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/2617a917
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2617a917
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2617a917
Branch: refs/heads/develop
Commit: 2617a91776de019ff6aefb630493e9d17d27668c
Parents: 51294d5
Author: David G. Simmons <sa...@mac.com>
Authored: Fri Aug 12 12:51:19 2016 -0400
Committer: David G. Simmons <sa...@mac.com>
Committed: Fri Aug 12 12:51:19 2016 -0400
----------------------------------------------------------------------
libs/console/full/include/console/console.h | 1 +
libs/console/full/include/console/prompt.h | 35 ++++++++++
libs/console/full/src/cons_tty.c | 6 +-
libs/console/full/src/prompt.c | 40 ++++++++++++
.../stub/include/console/console_prompt.h | 35 ++++++++++
libs/shell/include/shell/shell.h | 3 +
libs/shell/include/shell/shell_prompt.h | 23 +++++++
libs/shell/src/shell.c | 24 ++++++-
libs/shell/src/shell_prompt.c | 69 ++++++++++++++++++++
9 files changed, 232 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/console/full/include/console/console.h
----------------------------------------------------------------------
diff --git a/libs/console/full/include/console/console.h b/libs/console/full/include/console/console.h
index a196f01..4f3f946 100644
--- a/libs/console/full/include/console/console.h
+++ b/libs/console/full/include/console/console.h
@@ -20,6 +20,7 @@
#define __CONSOLE_H__
#include <stdarg.h>
+//#include "console/prompt.h"
typedef void (*console_rx_cb)(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/console/full/include/console/prompt.h
----------------------------------------------------------------------
diff --git a/libs/console/full/include/console/prompt.h b/libs/console/full/include/console/prompt.h
new file mode 100644
index 0000000..87ace35
--- /dev/null
+++ b/libs/console/full/include/console/prompt.h
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
+#include <stdarg.h>
+
+
+/* print console prompt */
+void console_print_prompt();
+/* set the console prompt character */
+void console_set_prompt(char);
+
+
+extern char console_prompt[2];
+
+
+#endif /* __CONSOLE_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index 9c576e2..83bc843 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -21,7 +21,9 @@
#include "os/os.h"
#include "hal/hal_uart.h"
#include "bsp/bsp.h"
+
#include "console/console.h"
+#include "console/prompt.h"
int g_console_is_init;
@@ -43,6 +45,7 @@ int console_is_midline;
#define CONSOLE_TAIL_INC(cr) (((cr)->cr_tail + 1) & ((cr)->cr_size - 1))
typedef void (*console_write_char)(char);
+void console_print_prompt(void);
struct console_ring {
uint8_t cr_head;
@@ -392,6 +395,7 @@ console_init(console_rx_cb rx_cb)
}
g_console_is_init = 1;
-
+ console_print_prompt();
+
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/console/full/src/prompt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c
new file mode 100644
index 0000000..421d937
--- /dev/null
+++ b/libs/console/full/src/prompt.c
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include "console/console.h"
+#include "console/prompt.h"
+
+/* console prompt, always followed by a space */
+char console_prompt[3] = {' ', '>', ' '};
+
+
+/* set the prompt character, leave the space */
+void
+console_set_prompt(char p)
+{
+ console_prompt[1] = p;
+}
+
+/* print the prompt to the console */
+void
+console_print_prompt(void)
+{
+ console_printf(console_prompt);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/console/stub/include/console/console_prompt.h
----------------------------------------------------------------------
diff --git a/libs/console/stub/include/console/console_prompt.h b/libs/console/stub/include/console/console_prompt.h
new file mode 100644
index 0000000..8cbda7c
--- /dev/null
+++ b/libs/console/stub/include/console/console_prompt.h
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __CONSOLE_H__
+#define __CONSOLE_H__
+
+#include <stdarg.h>
+
+
+/* print console prompt */
+void console_print_prompt(void);
+/* set the console prompt character */
+void console_set_prompt(char);
+
+
+extern char console_prompt[2];
+
+
+#endif /* __CONSOLE_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/libs/shell/include/shell/shell.h b/libs/shell/include/shell/shell.h
index 53c890d..1d98148 100644
--- a/libs/shell/include/shell/shell.h
+++ b/libs/shell/include/shell/shell.h
@@ -43,4 +43,7 @@ void shell_console_rx_cb(void);
int shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size,
int max_input_length);
+int shell_cmd_list_lock(void);
+int shell_cmd_list_unlock(void);
+
#endif /* __SHELL_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/shell/include/shell/shell_prompt.h
----------------------------------------------------------------------
diff --git a/libs/shell/include/shell/shell_prompt.h b/libs/shell/include/shell/shell_prompt.h
new file mode 100644
index 0000000..2b6b2fa
--- /dev/null
+++ b/libs/shell/include/shell/shell_prompt.h
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+
+int shell_prompt_cmd(int argc, char **argv);
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
index d38573c..0de277e 100644
--- a/libs/shell/src/shell.c
+++ b/libs/shell/src/shell.c
@@ -20,9 +20,11 @@
#include <os/os.h>
#include <console/console.h>
+#include <console/prompt.h>
#include "shell/shell.h"
#include "shell_priv.h"
+#include "shell/shell_prompt.h"
#include <os/endian.h>
#include <util/base64.h>
@@ -44,6 +46,9 @@ static struct os_mqueue g_shell_nlip_mq;
static int shell_echo_cmd(int argc, char **argv);
static int shell_help_cmd(int argc, char **argv);
+void console_print_prompt(void);
+void console_set_prompt(char p);
+int shell_prompt_cmd(int argc, char **argv);
static struct shell_cmd g_shell_echo_cmd = {
.sc_cmd = "echo",
@@ -53,6 +58,10 @@ static struct shell_cmd g_shell_help_cmd = {
.sc_cmd = "?",
.sc_cmd_func = shell_help_cmd
};
+static struct shell_cmd g_shell_prompt_cmd = {
+ .sc_cmd = "prompt",
+ .sc_cmd_func = shell_prompt_cmd
+};
static struct shell_cmd g_shell_os_tasks_display_cmd = {
.sc_cmd = "tasks",
.sc_cmd_func = shell_os_tasks_display_cmd
@@ -83,7 +92,7 @@ static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
static struct os_mbuf *g_nlip_mbuf;
static uint16_t g_nlip_expected_len;
-static int
+int
shell_cmd_list_lock(void)
{
int rc;
@@ -101,7 +110,7 @@ err:
return (rc);
}
-static int
+int
shell_cmd_list_unlock(void)
{
int rc;
@@ -197,6 +206,10 @@ shell_process_command(char *line, int len)
if (argc) {
(void) shell_cmd(argv[0], argv, argc);
}
+ else {
+ console_printf("\n");
+ }
+ console_print_prompt();
return (0);
}
@@ -507,7 +520,7 @@ shell_help_cmd(int argc, char **argv)
if (rc != 0) {
return -1;
}
-
+ console_printf("Commands:\n");
STAILQ_FOREACH(sc, &g_shell_cmd_list, sc_next) {
console_printf("%9s ", sc->sc_cmd);
if (i++ % SHELL_HELP_PER_LINE == SHELL_HELP_PER_LINE - 1) {
@@ -554,6 +567,11 @@ shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size,
goto err;
}
+ rc = shell_cmd_register(&g_shell_prompt_cmd);
+ if (rc != 0) {
+ goto err;
+ }
+
rc = shell_cmd_register(&g_shell_os_tasks_display_cmd);
if (rc != 0) {
goto err;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2617a917/libs/shell/src/shell_prompt.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell_prompt.c b/libs/shell/src/shell_prompt.c
new file mode 100644
index 0000000..d1402ad
--- /dev/null
+++ b/libs/shell/src/shell_prompt.c
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include "shell/shell.h"
+#include <console/console.h>
+
+static char shell_prompt = '>';
+
+void console_set_prompt(char p);
+
+/**
+ * Handles the 'prompt' command
+ * with set argument, sets the prompt to the provided char
+ * with the show argument, echos the current prompt
+ * otherwise echos the prompt and the usage message
+ */
+int
+shell_prompt_cmd(int argc, char **argv)
+{
+ int rc;
+
+ rc = shell_cmd_list_lock();
+ if (rc != 0) {
+ return -1;
+ }
+ if(argc > 1){
+ if(!strcmp(argv[1], "show")){
+ console_printf("Prompt character: %c\n", shell_prompt);
+ }
+ else if (!strcmp(argv[1],"set")){
+ shell_prompt = argv[2][0];
+ console_printf("Prompt set to: %c\n", argv[2][0]);
+ console_set_prompt(argv[2][0]);
+ }
+ else {
+ goto usage;
+ }
+
+ }
+ else {
+ goto usage;
+
+ }
+usage:
+ console_printf("Usage: prompt [set|show] [prompt_char]\n");
+
+ shell_cmd_list_unlock();
+
+ return (0);
+
+}
+
\ No newline at end of file
[2/3] incubator-mynewt-core git commit: shell prompt in own files
Posted by ma...@apache.org.
shell prompt in own files
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/1f523179
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1f523179
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1f523179
Branch: refs/heads/develop
Commit: 1f523179bea61de2f35e5cd8415e551984a2b24a
Parents: 2617a91
Author: David G. Simmons <sa...@mac.com>
Authored: Fri Aug 12 12:56:13 2016 -0400
Committer: David G. Simmons <sa...@mac.com>
Committed: Fri Aug 12 12:56:13 2016 -0400
----------------------------------------------------------------------
libs/console/full/include/console/console.h | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1f523179/libs/console/full/include/console/console.h
----------------------------------------------------------------------
diff --git a/libs/console/full/include/console/console.h b/libs/console/full/include/console/console.h
index 4f3f946..a196f01 100644
--- a/libs/console/full/include/console/console.h
+++ b/libs/console/full/include/console/console.h
@@ -20,7 +20,6 @@
#define __CONSOLE_H__
#include <stdarg.h>
-//#include "console/prompt.h"
typedef void (*console_rx_cb)(void);
[3/3] incubator-mynewt-core git commit: This closes #93
Posted by ma...@apache.org.
This closes #93
Merge branch 'console_shell' of https://github.com/davidgs/incubator-mynewt-core into develop
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/f95bda8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f95bda8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f95bda8c
Branch: refs/heads/develop
Commit: f95bda8c2a3674cc8f39837d2c339963576e294a
Parents: 5fa1a91 1f52317
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Aug 25 11:45:38 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Aug 25 11:45:38 2016 -0700
----------------------------------------------------------------------
libs/console/full/include/console/prompt.h | 35 ++++++++++
libs/console/full/src/cons_tty.c | 6 +-
libs/console/full/src/prompt.c | 40 ++++++++++++
.../stub/include/console/console_prompt.h | 35 ++++++++++
libs/shell/include/shell/shell.h | 3 +
libs/shell/include/shell/shell_prompt.h | 23 +++++++
libs/shell/src/shell.c | 24 ++++++-
libs/shell/src/shell_prompt.c | 69 ++++++++++++++++++++
8 files changed, 231 insertions(+), 4 deletions(-)
----------------------------------------------------------------------