You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by be...@apache.org on 2021/02/24 17:20:41 UTC
[mynewt-core] branch master updated: sys/console: Add syscfg to
allow restoring echo state after NLIP commands
This is an automated email from the ASF dual-hosted git repository.
benmccrea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 6781372 sys/console: Add syscfg to allow restoring echo state after NLIP commands
new 3f49303 Merge pull request #2496 from benmccrea/console-restore-echo-setting
6781372 is described below
commit 678137282349d7145cdbd60bbc36553a4673e9a7
Author: Ben McCrea <bm...@juul.com>
AuthorDate: Mon Feb 22 14:18:12 2021 -0800
sys/console: Add syscfg to allow restoring echo state after NLIP commands
---
sys/console/full/src/console.c | 28 +++++++++++++++++++++++++---
sys/console/full/syscfg.yml | 3 +++
sys/console/minimal/src/console.c | 31 ++++++++++++++++++++++++++-----
sys/console/minimal/syscfg.yml | 3 +++
4 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 0ed9ef5..b271c08 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -87,6 +87,9 @@ static int nlip_state;
static int echo = MYNEWT_VAL(CONSOLE_ECHO);
static unsigned int ansi_val, ansi_val_2;
static bool rx_stalled;
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+static uint8_t restore_echo;
+#endif
/* Cursor position in input line */
static uint16_t cur;
@@ -115,6 +118,25 @@ static uint16_t prompt_len;
/* Current history line, 0 no history line */
static history_handle_t history_line;
+static void
+console_nlip_disable_echo(void)
+{
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+ restore_echo = echo;
+#endif
+ console_echo(0);
+}
+
+static void
+console_nlip_enable_echo(void)
+{
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+ console_echo(restore_echo);
+#else
+ console_echo(1);
+#endif
+}
+
/*
* Default implementation in case all consoles are disabled - we just ignore any
* output to console.
@@ -981,7 +1003,7 @@ handle_nlip(uint8_t byte)
insert_char(&input->line[cur], byte);
if (byte == '\n') {
input->line[cur] = '\0';
- console_echo(1);
+ console_nlip_enable_echo();
nlip_state = 0;
console_handle_line();
@@ -991,7 +1013,7 @@ handle_nlip(uint8_t byte)
if (byte == CONSOLE_NLIP_PKT_START2) {
nlip_state = NLIP_PKT_START2;
/* Disable echo to not flood the UART */
- console_echo(0);
+ console_nlip_disable_echo();
insert_char(&input->line[cur], CONSOLE_NLIP_PKT_START1);
insert_char(&input->line[cur], CONSOLE_NLIP_PKT_START2);
} else {
@@ -1003,7 +1025,7 @@ handle_nlip(uint8_t byte)
if (byte == CONSOLE_NLIP_DATA_START2) {
nlip_state = NLIP_DATA_START2;
/* Disable echo to not flood the UART */
- console_echo(0);
+ console_nlip_disable_echo();
insert_char(&input->line[cur], CONSOLE_NLIP_DATA_START1);
insert_char(&input->line[cur], CONSOLE_NLIP_DATA_START2);
} else {
diff --git a/sys/console/full/syscfg.yml b/sys/console/full/syscfg.yml
index f8fcb84..ee81710 100644
--- a/sys/console/full/syscfg.yml
+++ b/sys/console/full/syscfg.yml
@@ -41,6 +41,9 @@ syscfg.defs:
CONSOLE_ECHO:
description: 'Default console echo'
value: 1
+ CONSOLE_NLIP_RESTORE_ECHO:
+ description: 'Restore echo setting after NLIP commands'
+ value: 0
CONSOLE_COMPAT:
description: 'Console backward compatibility'
value: 1
diff --git a/sys/console/minimal/src/console.c b/sys/console/minimal/src/console.c
index d44f447..3b7c28f 100644
--- a/sys/console/minimal/src/console.c
+++ b/sys/console/minimal/src/console.c
@@ -53,6 +53,9 @@ static struct os_eventq compat_lines_queue;
static int nlip_state;
static int echo = MYNEWT_VAL(CONSOLE_ECHO);
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+static uint8_t restore_echo;
+#endif
static uint8_t cur, end;
static struct os_eventq *avail_queue;
@@ -68,6 +71,25 @@ console_out_nolock(int c)
return c;
}
+static void
+console_nlip_disable_echo(void)
+{
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+ restore_echo = echo;
+#endif
+ console_echo(0);
+}
+
+static void
+console_nlip_enable_echo(void)
+{
+#if MYNEWT_VAL(CONSOLE_NLIP_RESTORE_ECHO)
+ console_echo(restore_echo);
+#else
+ console_echo(1);
+#endif
+}
+
void
console_echo(int on)
{
@@ -165,7 +187,7 @@ console_write(const char *str, int cnt)
/* If the byte string is non nlip and we are silencing non nlip bytes,
* do not let it go out on the console
- */
+ */
if (!g_is_output_nlip && g_console_silence_non_nlip) {
goto done;
}
@@ -310,19 +332,18 @@ console_handle_char(uint8_t byte)
console_compat_rx_cb();
}
#endif
-
input = NULL;
ev = NULL;
- console_echo(1);
+ console_nlip_enable_echo();
return 0;
/* Ignore characters if there's no more buffer space */
} else if (byte == CONSOLE_NLIP_PKT_START2) {
/* Disable echo to not flood the UART */
- console_echo(0);
+ console_nlip_disable_echo();
insert_char(&input->line[cur], CONSOLE_NLIP_PKT_START1, end);
} else if (byte == CONSOLE_NLIP_DATA_START2) {
/* Disable echo to not flood the UART */
- console_echo(0);
+ console_nlip_disable_echo();
insert_char(&input->line[cur], CONSOLE_NLIP_DATA_START1, end);
}
diff --git a/sys/console/minimal/syscfg.yml b/sys/console/minimal/syscfg.yml
index 5a8dc01..d51900d 100644
--- a/sys/console/minimal/syscfg.yml
+++ b/sys/console/minimal/syscfg.yml
@@ -29,6 +29,9 @@ syscfg.defs:
CONSOLE_ECHO:
description: 'Default console echo'
value: 1
+ CONSOLE_NLIP_RESTORE_ECHO:
+ description: 'Restore echo setting after NLIP commands'
+ value: 0
CONSOLE_COMPAT:
description: 'Console backward compatibility'
value: 1