subsys: shell: fix accept either CR or LF as as line delimiter

1. Shell will accept CR or LF as line delimiter.
2. Macro SHELL_DEFINE simplified - it no longer requires
   new line character.
3. Fixes: #10207.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2018-10-02 11:48:40 +02:00 committed by Anas Nashif
commit c471614cb6
4 changed files with 4 additions and 13 deletions

View file

@ -365,9 +365,6 @@ struct shell {
LOG_INSTANCE_PTR_DECLARE(log); LOG_INSTANCE_PTR_DECLARE(log);
/*!< New line character, only allowed values: \\n and \\r.*/
const char newline_char;
struct k_thread *thread; struct k_thread *thread;
k_thread_stack_t *stack; k_thread_stack_t *stack;
}; };
@ -378,12 +375,10 @@ struct shell {
* @param[in] _name Instance name. * @param[in] _name Instance name.
* @param[in] _prompt Shell prompt string. * @param[in] _prompt Shell prompt string.
* @param[in] transport_iface Pointer to the transport interface. * @param[in] transport_iface Pointer to the transport interface.
* @param[in] newline_ch New line character - only allowed values are
* '\\n' or '\\r'.
* @param[in] log_queue_size Logger processing queue size. * @param[in] log_queue_size Logger processing queue size.
*/ */
#define SHELL_DEFINE(_name, _prompt, transport_iface, \ #define SHELL_DEFINE(_name, _prompt, transport_iface, \
newline_ch, log_queue_size) \ log_queue_size) \
static const struct shell _name; \ static const struct shell _name; \
static struct shell_ctx UTIL_CAT(_name, _ctx); \ static struct shell_ctx UTIL_CAT(_name, _ctx); \
static char _name##prompt[CONFIG_SHELL_PROMPT_LENGTH + 1] = _prompt; \ static char _name##prompt[CONFIG_SHELL_PROMPT_LENGTH + 1] = _prompt; \
@ -407,7 +402,6 @@ struct shell {
.stats = SHELL_STATS_PTR(_name), \ .stats = SHELL_STATS_PTR(_name), \
.log_backend = SHELL_LOG_BACKEND_PTR(_name), \ .log_backend = SHELL_LOG_BACKEND_PTR(_name), \
LOG_INSTANCE_PTR_INIT(log, shell, _name) \ LOG_INSTANCE_PTR_INIT(log, shell, _name) \
.newline_char = newline_ch, \
.thread = &_name##_thread, \ .thread = &_name##_thread, \
.stack = _name##_stack \ .stack = _name##_stack \
} }

View file

@ -15,7 +15,7 @@
LOG_MODULE_REGISTER(app); LOG_MODULE_REGISTER(app);
SHELL_UART_DEFINE(shell_transport_uart); SHELL_UART_DEFINE(shell_transport_uart);
SHELL_DEFINE(uart_shell, "uart:~$ ", &shell_transport_uart, '\r', 10); SHELL_DEFINE(uart_shell, "uart:~$ ", &shell_transport_uart, 10);
extern void foo(void); extern void foo(void);

View file

@ -759,8 +759,7 @@ static void shell_state_collect(const struct shell *shell)
switch (shell->ctx->receive_state) { switch (shell->ctx->receive_state) {
case SHELL_RECEIVE_DEFAULT: case SHELL_RECEIVE_DEFAULT:
if (data == shell->newline_char) { if ((data == '\r') || (data == '\n')) {
if (!shell->ctx->cmd_buff_len) { if (!shell->ctx->cmd_buff_len) {
history_mode_exit(shell); history_mode_exit(shell);
cursor_next_line_move(shell); cursor_next_line_move(shell);
@ -1150,8 +1149,6 @@ static int shell_instance_init(const struct shell *shell, const void *p_config,
{ {
__ASSERT_NO_MSG(shell); __ASSERT_NO_MSG(shell);
__ASSERT_NO_MSG(shell->ctx && shell->iface && shell->prompt); __ASSERT_NO_MSG(shell->ctx && shell->iface && shell->prompt);
__ASSERT_NO_MSG((shell->newline_char == '\n') ||
(shell->newline_char == '\r'));
int err; int err;

View file

@ -29,7 +29,7 @@
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
SHELL_UART_DEFINE(shell_transport_uart); SHELL_UART_DEFINE(shell_transport_uart);
SHELL_DEFINE(uart_shell, "uart:~$ ", &shell_transport_uart, '\r', 10); SHELL_DEFINE(uart_shell, "uart:~$ ", &shell_transport_uart, 10);
#if defined(CONFIG_BT_CONN) #if defined(CONFIG_BT_CONN)
static bool hrs_simulate; static bool hrs_simulate;