shell: parsing output LF character

Some terminals literally interprets shell output data. Hence to print
a message in new line shell needs to send `\r\n` each time. To minimize
flash usage user can now send `\n` as a line delimiter and shell will
automatically add missing CR character.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2018-10-05 10:49:08 +02:00 committed by Carles Cufí
commit b0571746e2
7 changed files with 69 additions and 47 deletions

View file

@ -166,7 +166,6 @@ enum shell_receive_state {
SHELL_RECEIVE_TILDE_EXP
};
/**
* @internal @brief Internal shell state.
*/
@ -346,6 +345,14 @@ struct shell_ctx {
extern const struct log_backend_api log_backend_shell_api;
/**
* @brief Flags for setting shell output newline sequence.
*/
enum shell_flag {
SHELL_FLAG_CRLF_DEFAULT = (1<<0), /* Do not map CR or LF */
SHELL_FLAG_OLF_CRLF = (1<<1) /* Map LF to CRLF on output */
};
/**
* @brief Shell instance internals.
*/
@ -357,6 +364,8 @@ struct shell {
struct shell_history *history;
const enum shell_flag shell_flag;
const struct shell_fprintf *fprintf_ctx;
struct shell_stats *stats;
@ -376,9 +385,10 @@ struct shell {
* @param[in] _prompt Shell prompt string.
* @param[in] transport_iface Pointer to the transport interface.
* @param[in] log_queue_size Logger processing queue size.
* @param[in] _shell_flag Shell output newline sequence.
*/
#define SHELL_DEFINE(_name, _prompt, transport_iface, \
log_queue_size) \
log_queue_size, _shell_flag) \
static const struct shell _name; \
static struct shell_ctx UTIL_CAT(_name, _ctx); \
static char _name##prompt[CONFIG_SHELL_PROMPT_LENGTH + 1] = _prompt; \
@ -386,7 +396,7 @@ struct shell {
SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \
CONFIG_SHELL_PRINTF_BUFF_SIZE); \
SHELL_HISTORY_DEFINE(_name, 128, 8);/*todo*/ \
SHELL_FPRINTF_DEFINE(_name## _fprintf, &_name, _name##_out_buffer, \
SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _name##_out_buffer, \
CONFIG_SHELL_PRINTF_BUFF_SIZE, \
true, shell_print_stream); \
LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
@ -398,6 +408,7 @@ struct shell {
.iface = transport_iface, \
.ctx = &UTIL_CAT(_name, _ctx), \
.history = SHELL_HISTORY_PTR(_name), \
.shell_flag = _shell_flag, \
.fprintf_ctx = &_name##_fprintf, \
.stats = SHELL_STATS_PTR(_name), \
.log_backend = SHELL_LOG_BACKEND_PTR(_name), \