vrahane closed pull request #1341: sys/console: add support for silencing 
output from the console
URL: https://github.com/apache/mynewt-core/pull/1341
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/console/full/include/console/console.h 
b/sys/console/full/include/console/console.h
index ab1af6ed67..bb9f11ad97 100644
--- a/sys/console/full/include/console/console.h
+++ b/sys/console/full/include/console/console.h
@@ -65,6 +65,22 @@ int console_handle_char(uint8_t byte);
 void console_line_queue_set(struct os_eventq *evq);
 /* Put (handled) line event to console */
 void console_line_event_put(struct os_event *ev);
+/**
+ * Global indicating whether console is silent or not
+ */
+extern bool g_silence_console;
+
+/**
+ * Silences console output, input is still active
+ *
+ * @param silent Let console know if it needs to be silent,
+ *        true for silence, false otherwise
+ */
+static void inline
+console_silence(bool silent)
+{
+    g_silence_console = silent;
+}
 
 extern int console_is_midline;
 extern int console_out(int character);
diff --git a/sys/console/full/src/ble_monitor_console.c 
b/sys/console/full/src/ble_monitor_console.c
index d25bfdbd12..12cd44f56c 100644
--- a/sys/console/full/src/ble_monitor_console.c
+++ b/sys/console/full/src/ble_monitor_console.c
@@ -27,6 +27,10 @@
 int
 console_out(int c)
 {
+    if (g_silence_console) {
+        return c;
+    }
+
     console_is_midline = (c != '\n');
 
     return ble_monitor_out(c);
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 78bf9cc89c..6f996cf5a1 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -82,6 +82,7 @@ static uint16_t cur, end;
 static struct os_eventq avail_queue;
 static struct os_eventq *lines_queue;
 static completion_cb completion;
+bool g_silence_console;
 
 /*
  * Default implementation in case all consoles are disabled - we just ignore 
any
diff --git a/sys/console/full/src/rtt_console.c 
b/sys/console/full/src/rtt_console.c
index fa3c6929c5..0191372205 100644
--- a/sys/console/full/src/rtt_console.c
+++ b/sys/console/full/src/rtt_console.c
@@ -37,6 +37,10 @@ console_out(int character)
 {
     char c = (char)character;
 
+    if (g_silence_console) {
+        return c;
+    }
+
     if ('\n' == c) {
         SEGGER_RTT_WriteWithOverwriteNoLock(0, &CR, 1);
         console_is_midline = 0;
diff --git a/sys/console/full/src/uart_console.c 
b/sys/console/full/src/uart_console.c
index aa25790521..252d576dae 100644
--- a/sys/console/full/src/uart_console.c
+++ b/sys/console/full/src/uart_console.c
@@ -154,6 +154,10 @@ uart_console_non_blocking_mode(void)
 int
 console_out(int c)
 {
+    if (g_silence_console) {
+        return c;
+    }
+
     /* Assure that there is a write cb installed; this enables to debug
      * code that is faulting before the console was initialized.
      */
diff --git a/sys/console/minimal/include/console/console.h 
b/sys/console/minimal/include/console/console.h
index 5e8eeb21ce..6c82006e58 100644
--- a/sys/console/minimal/include/console/console.h
+++ b/sys/console/minimal/include/console/console.h
@@ -63,6 +63,23 @@ console_set_completion_cb(uint8_t (*completion)(char *str, 
uint8_t len))
 {
 }
 
+/**
+ * Global indicating whether console is silent or not
+ */
+extern bool g_silence_console;
+
+/**
+ * Silences console output, input is still active
+ *
+ * @param silent Let console know if it needs to be silent,
+ *        true for silence, false otherwise
+ */
+static void inline
+console_silence(bool silent)
+{
+    g_silence_console = silent;
+}
+
 int console_handle_char(uint8_t byte);
 
 extern int console_is_midline;
diff --git a/sys/console/minimal/src/console.c 
b/sys/console/minimal/src/console.c
index d0fc786913..9f50e90422 100644
--- a/sys/console/minimal/src/console.c
+++ b/sys/console/minimal/src/console.c
@@ -56,6 +56,7 @@ static int echo = MYNEWT_VAL(CONSOLE_ECHO);
 static uint8_t cur, end;
 static struct os_eventq *avail_queue;
 static struct os_eventq *lines_queue;
+bool g_silence_console;
 
 int __attribute__((weak))
 console_out(int c)
diff --git a/sys/console/minimal/src/rtt_console.c 
b/sys/console/minimal/src/rtt_console.c
index b678e965b7..085690df2d 100644
--- a/sys/console/minimal/src/rtt_console.c
+++ b/sys/console/minimal/src/rtt_console.c
@@ -37,6 +37,10 @@ console_out(int character)
 {
     char c = (char)character;
 
+    if (g_silence_console) {
+        return c;
+    }
+
     if ('\n' == c) {
         SEGGER_RTT_WriteWithOverwriteNoLock(0, &CR, 1);
         console_is_midline = 0;
diff --git a/sys/console/minimal/src/uart_console.c 
b/sys/console/minimal/src/uart_console.c
index 7c3a72e5a7..0f9b00bdb3 100644
--- a/sys/console/minimal/src/uart_console.c
+++ b/sys/console/minimal/src/uart_console.c
@@ -132,6 +132,10 @@ uart_console_non_blocking_mode(void)
 int
 console_out(int c)
 {
+    if (g_silence_console) {
+        return c;
+    }
+
     if ('\n' == c) {
         write_char_cb(uart_dev, '\r');
         console_is_midline = 0;
diff --git a/sys/console/stub/include/console/console.h 
b/sys/console/stub/include/console/console.h
index f1e27a3b38..57c5ab072d 100644
--- a/sys/console/stub/include/console/console.h
+++ b/sys/console/stub/include/console/console.h
@@ -20,6 +20,7 @@
 #define __CONSOLE_H__
 
 #include <inttypes.h>
+#include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -111,6 +112,11 @@ console_out(int character)
     return 0;
 }
 
+static void inline
+console_silence(bool silent)
+{
+}
+
 #define console_is_midline  (0)
 
 #ifdef __cplusplus
diff --git a/util/parse/src/parse.c b/util/parse/src/parse.c
index 626a97eabb..e403203512 100644
--- a/util/parse/src/parse.c
+++ b/util/parse/src/parse.c
@@ -54,11 +54,13 @@ parse_ll_bounds(const char *sval, long long min, long long 
max,
     char *endptr;
     long long llval;
 
-    llval = strtoll(sval, &endptr, parse_num_base(sval));
-    if (sval[0] != '\0' && *endptr == '\0' &&
-        llval >= min && llval <= max) {
+    *out_status = SYS_EOK;
 
-        *out_status = 0;
+    llval = strtoll(sval, &endptr, parse_num_base(sval));
+    if (sval[0] != '\0' && *endptr == '\0') {
+        if (llval < min || llval > max) {
+            *out_status = SYS_ERANGE;
+        }
         return llval;
     }
 
@@ -74,11 +76,13 @@ parse_ull_bounds(const char *sval,
     char *endptr;
     unsigned long long ullval;
 
-    ullval = strtoull(sval, &endptr, parse_num_base(sval));
-    if (sval[0] != '\0' && *endptr == '\0' &&
-        ullval >= min && ullval <= max) {
+    *out_status = SYS_EOK;
 
-        *out_status = 0;
+    ullval = strtoull(sval, &endptr, parse_num_base(sval));
+    if (sval[0] != '\0' && *endptr == '\0') {
+        if (ullval < min || ullval > max) {
+            *out_status = SYS_ERANGE;
+        }
         return ullval;
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to