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/05/25 20:12:00 UTC
[1/2] incubator-mynewt-core git commit: console;
change the API for read to return whether it's partial. Remove the
argument to RX callback.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8f78cd3bc -> b6fa07ad9
console; change the API for read to return whether it's partial.
Remove the argument to RX callback.
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/524192c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/524192c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/524192c4
Branch: refs/heads/develop
Commit: 524192c4e7a409009071c02f6461ca6389fdc026
Parents: 8f78cd3
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 25 13:09:30 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed May 25 13:09:30 2016 -0700
----------------------------------------------------------------------
libs/console/full/include/console/console.h | 4 ++--
libs/console/full/src/cons_tty.c | 10 ++++++----
libs/console/stub/include/console/console.h | 7 ++++---
3 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/524192c4/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 2f062f9..a196f01 100644
--- a/libs/console/full/include/console/console.h
+++ b/libs/console/full/include/console/console.h
@@ -21,12 +21,12 @@
#include <stdarg.h>
-typedef void (*console_rx_cb)(int full_line);
+typedef void (*console_rx_cb)(void);
int console_init(console_rx_cb rx_cb);
int console_is_init(void);
void console_write(const char *str, int cnt);
-int console_read(char *str, int cnt);
+int console_read(char *str, int cnt, int *newline);
void console_blocking_mode(void);
void console_echo(int on);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/524192c4/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 a50f1a6..7dfd0b7 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -185,7 +185,7 @@ console_write(const char *str, int cnt)
}
int
-console_read(char *str, int cnt)
+console_read(char *str, int cnt, int *newline)
{
struct console_tty *ct = &console_tty;
struct console_ring *cr = &ct->ct_rx;
@@ -193,6 +193,7 @@ console_read(char *str, int cnt)
int i;
uint8_t ch;
+ *newline = 0;
OS_ENTER_CRITICAL(sr);
for (i = 0; i < cnt; i++) {
if (cr->cr_head == cr->cr_tail) {
@@ -210,12 +211,13 @@ console_read(char *str, int cnt)
ch = console_pull_char(cr);
if (ch == '\n') {
*str = '\0';
+ *newline = 1;
break;
}
*str++ = ch;
}
OS_EXIT_CRITICAL(sr);
- if (i >= 0) {
+ if (i > 0 || *newline) {
hal_uart_start_rx(CONSOLE_UART);
}
return i;
@@ -263,7 +265,7 @@ console_rx_char(void *arg, uint8_t data)
* RX queue full. Reader must drain this.
*/
if (ct->ct_rx_cb) {
- ct->ct_rx_cb(0);
+ ct->ct_rx_cb();
}
return -1;
}
@@ -280,7 +282,7 @@ console_rx_char(void *arg, uint8_t data)
tx_space = 2;
console_add_char(rx, '\n');
if (ct->ct_rx_cb) {
- ct->ct_rx_cb(1);
+ ct->ct_rx_cb();
}
break;
case CONSOLE_ESC:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/524192c4/libs/console/stub/include/console/console.h
----------------------------------------------------------------------
diff --git a/libs/console/stub/include/console/console.h b/libs/console/stub/include/console/console.h
index d0858e2..99db457 100644
--- a/libs/console/stub/include/console/console.h
+++ b/libs/console/stub/include/console/console.h
@@ -6,7 +6,7 @@
* 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,
@@ -21,7 +21,7 @@
#include <stdarg.h>
-typedef void (*console_rx_cb)(int full_line);
+typedef void (*console_rx_cb)(void);
static int inline
console_is_init(void)
@@ -36,8 +36,9 @@ console_init(console_rx_cb rxcb)
}
static int inline
-console_read(char *str, int cnt)
+console_read(char *str, int cnt, int *newline)
{
+ *newline = 0;
return 0;
}
[2/2] incubator-mynewt-core git commit: shell;
fix issues with partial reads and multiple lines of input being
handled in a single event.
Posted by ma...@apache.org.
shell; fix issues with partial reads and multiple lines of input being
handled in a single event.
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/b6fa07ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b6fa07ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b6fa07ad
Branch: refs/heads/develop
Commit: b6fa07ad928de4d8cd1dd37d419d8f9e3bc33b1b
Parents: 524192c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 25 13:10:30 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed May 25 13:10:30 2016 -0700
----------------------------------------------------------------------
libs/shell/include/shell/shell.h | 2 +-
libs/shell/src/shell.c | 74 +++++++++++++----------------------
2 files changed, 29 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b6fa07ad/libs/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/libs/shell/include/shell/shell.h b/libs/shell/include/shell/shell.h
index 29ff2dc..53c890d 100644
--- a/libs/shell/include/shell/shell.h
+++ b/libs/shell/include/shell/shell.h
@@ -39,7 +39,7 @@ typedef int (*shell_nlip_input_func_t)(struct os_mbuf *, void *arg);
int shell_nlip_input_register(shell_nlip_input_func_t nf, void *arg);
int shell_nlip_output(struct os_mbuf *m);
-void shell_console_rx_cb(int full_line);
+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);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b6fa07ad/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
index f46b433..95ddcb0 100644
--- a/libs/shell/src/shell.c
+++ b/libs/shell/src/shell.c
@@ -70,21 +70,20 @@ static struct os_task shell_task;
static struct os_eventq shell_evq;
static struct os_event console_rdy_ev;
-static struct os_mutex g_shell_cmd_list_lock;
+static struct os_mutex g_shell_cmd_list_lock;
static char *shell_line;
static int shell_line_capacity;
static int shell_line_len;
static char *argv[SHELL_MAX_ARGS];
-static uint8_t shell_full_line;
-static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
+static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
STAILQ_HEAD_INITIALIZER(g_shell_cmd_list);
static struct os_mbuf *g_nlip_mbuf;
static uint16_t g_nlip_expected_len;
-static int
+static int
shell_cmd_list_lock(void)
{
int rc;
@@ -102,7 +101,7 @@ err:
return (rc);
}
-static int
+static int
shell_cmd_list_unlock(void)
{
int rc;
@@ -143,7 +142,7 @@ err:
return (rc);
}
-static int
+static int
shell_cmd(char *cmd, char **argv, int argc)
{
struct shell_cmd *sc;
@@ -395,7 +394,7 @@ shell_nlip_input_register(shell_nlip_input_func_t nf, void *arg)
return (0);
}
-int
+int
shell_nlip_output(struct os_mbuf *m)
{
int rc;
@@ -410,25 +409,21 @@ err:
return (rc);
}
-static int
+static void
shell_read_console(void)
{
int rc;
+ int full_line;
while (1) {
rc = console_read(shell_line + shell_line_len,
- shell_line_capacity - shell_line_len);
- if (rc < 0) {
- goto err;
- }
- if (rc == 0) {
+ shell_line_capacity - shell_line_len, &full_line);
+ if (rc <= 0 && !full_line) {
break;
}
-
- if (shell_full_line) {
- shell_line_len = 0;
- shell_full_line = 0;
- if (rc > 2) {
+ shell_line_len += rc;
+ if (full_line) {
+ if (shell_line_len > 2) {
if (shell_line[0] == SHELL_NLIP_PKT_START1 &&
shell_line[1] == SHELL_NLIP_PKT_START2) {
if (g_nlip_mbuf) {
@@ -437,35 +432,24 @@ shell_read_console(void)
}
g_nlip_expected_len = 0;
- rc = shell_nlip_process(&shell_line[2], rc-2);
+ rc = shell_nlip_process(&shell_line[2], shell_line_len - 2);
} else if (shell_line[0] == SHELL_NLIP_DATA_START1 &&
shell_line[1] == SHELL_NLIP_DATA_START2) {
- rc = shell_nlip_process(&shell_line[2], rc-2);
+ rc = shell_nlip_process(&shell_line[2], shell_line_len - 2);
} else {
- rc = shell_process_command(shell_line, rc);
- if (rc != 0) {
- goto err;
- }
+ shell_process_command(shell_line, shell_line_len);
}
} else {
- rc = shell_process_command(shell_line, rc);
- if (rc != 0) {
- goto err;
- }
+ shell_process_command(shell_line, shell_line_len);
}
- } else {
- shell_line_len += rc;
+ shell_line_len = 0;
}
}
-
- return (0);
-err:
- return (rc);
}
static void
-shell_task_func(void *arg)
+shell_task_func(void *arg)
{
struct os_event *ev;
@@ -476,9 +460,9 @@ shell_task_func(void *arg)
assert(ev != NULL);
switch (ev->ev_type) {
- case OS_EVENT_T_CONSOLE_RDY:
+ case OS_EVENT_T_CONSOLE_RDY:
// Read and process all available lines on the console.
- (void) shell_read_console();
+ shell_read_console();
break;
case OS_EVENT_T_MQUEUE_DATA:
shell_nlip_mqueue_process();
@@ -488,22 +472,20 @@ shell_task_func(void *arg)
}
/**
- * This function is called from the console APIs when data is available
- * to be read. This is either a full line (full_line = 1), or when the
- * console buffer (default = 128) is full. At the moment, we assert()
- * when the buffer is filled to avoid double buffering this data.
+ * This function is called from the console APIs when data is available
+ * to be read. This is either a full line, or when the
+ * console buffer (default = 128) is full.
*/
void
-shell_console_rx_cb(int full_line)
+shell_console_rx_cb(void)
{
- shell_full_line = full_line;
os_eventq_put(&shell_evq, &console_rdy_ev);
}
static int
shell_echo_cmd(int argc, char **argv)
{
- int i;
+ int i;
for (i = 1; i < argc; i++) {
console_write(argv[i], strlen(argv[i]));
@@ -540,7 +522,7 @@ shell_help_cmd(int argc, char **argv)
return (0);
}
-int
+int
shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size,
int max_input_length)
{
@@ -590,7 +572,7 @@ shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size,
os_eventq_init(&shell_evq);
os_mqueue_init(&g_shell_nlip_mq, NULL);
- rc = os_task_init(&shell_task, "shell", shell_task_func,
+ rc = os_task_init(&shell_task, "shell", shell_task_func,
NULL, prio, OS_WAIT_FOREVER, stack, stack_size);
if (rc != 0) {
goto err;