From dce1b15358c31e789d93a3b629c728b0a05ac3e1 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 15 Nov 2021 15:26:25 -0500 Subject: [PATCH 1/2] Make output buffer size easily set by user This PR creates a macro CONFIG_SHELL_OUT_BUFFER_LEN which defines the length of the output buffer. This should be large enough to accommodate most large writes via the shell_print functions, but still small enough to fit in a single shell_bwriter call (ie, for Telnet, smaller than the TCP Maximum Transmission Unit, 1500 bytes). This buffer is also statically allocated, and should not be so large that it uses all the available RAM in the system. The macro is set to the original output buffer size (30 bytes). --- Shell.c | 2 +- Shell.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Shell.c b/Shell.c index 5286bd4..e258bc7 100644 --- a/Shell.c +++ b/Shell.c @@ -158,7 +158,7 @@ void shell_putc(char c) // Keep track of last byte obhandle->buffertimer = millis(); // Empty buffer if it´s full before storing anything else - if (obhandle->buffercount >= 30) { + if (obhandle->buffercount >= CONFIG_SHELL_OUT_BUFFER_LEN) { // Write output... if (obhandle->shell_bwriter != 0) obhandle->shell_bwriter(obhandle->outbuffer, obhandle->buffercount); diff --git a/Shell.h b/Shell.h index 1f1980f..709a0a3 100644 --- a/Shell.h +++ b/Shell.h @@ -71,6 +71,16 @@ #define CONFIG_SHELL_FMT_BUFFER 70 #endif +/** + * This macro defines the length of the output buffer. This should be large + * enough to accommodate most large writes via the shell_print functions, but + * still small enough to fit in a single shell_bwriter call (ie, for Telnet, + * smaller than the TCP Maximum Transmission Unit, 1500 bytes). This buffer is + * also statically allocated, and should not be so large that it uses all the + * available RAM in the system. + */ +#define CONFIG_SHELL_OUT_BUFFER_LEN 30 + /** * End of user configurable parameters, do not touch anything below this line */ @@ -158,7 +168,7 @@ struct shell_command_entry { }; struct shell_outbuffer_data { - char outbuffer[30]; + char outbuffer[CONFIG_SHELL_OUT_BUFFER_LEN]; shell_bwriter_t shell_bwriter; uint32_t buffertimer; uint8_t buffercount; From 204ff7576248e1629baf530da861d425fcaa65bf Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 15 Nov 2021 16:41:32 -0500 Subject: [PATCH 2/2] Output buffer length must fit in a uint8_t to avoid breaking old buffer_writers --- Shell.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Shell.h b/Shell.h index 709a0a3..674862c 100644 --- a/Shell.h +++ b/Shell.h @@ -74,10 +74,9 @@ /** * This macro defines the length of the output buffer. This should be large * enough to accommodate most large writes via the shell_print functions, but - * still small enough to fit in a single shell_bwriter call (ie, for Telnet, - * smaller than the TCP Maximum Transmission Unit, 1500 bytes). This buffer is - * also statically allocated, and should not be so large that it uses all the - * available RAM in the system. + * still small enough to fit in a single shell_bwriter call (ie, UINT_8T_MAX, + * 255 bytes). This buffer is also statically allocated, and should not be so + * large that it uses all the available RAM in the system. */ #define CONFIG_SHELL_OUT_BUFFER_LEN 30