shell: Add warning about not initialized backend
Shell will display a warning message if there was a request to print a message on the not initialized shell backend. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
This commit is contained in:
parent
920e64cfd4
commit
dac8728856
3 changed files with 20 additions and 1 deletions
|
@ -541,8 +541,9 @@ struct shell_flags {
|
||||||
uint32_t tx_rdy :1;
|
uint32_t tx_rdy :1;
|
||||||
uint32_t mode_delete :1; /*!< Operation mode of backspace key */
|
uint32_t mode_delete :1; /*!< Operation mode of backspace key */
|
||||||
uint32_t history_exit:1; /*!< Request to exit history mode */
|
uint32_t history_exit:1; /*!< Request to exit history mode */
|
||||||
uint32_t cmd_ctx :1; /*!< Shell is executing command */
|
uint32_t cmd_ctx :1; /*!< Shell is executing command */
|
||||||
uint32_t last_nl :8; /*!< Last received new line character */
|
uint32_t last_nl :8; /*!< Last received new line character */
|
||||||
|
uint32_t print_noinit:1; /*!< Print request from not initialized shell*/
|
||||||
};
|
};
|
||||||
|
|
||||||
BUILD_ASSERT((sizeof(struct shell_flags) == sizeof(uint32_t)),
|
BUILD_ASSERT((sizeof(struct shell_flags) == sizeof(uint32_t)),
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SHELL_MSG_CMD_NOT_FOUND ": command not found"
|
#define SHELL_MSG_CMD_NOT_FOUND ": command not found"
|
||||||
|
#define SHELL_MSG_BACKEND_NOT_ACTIVE \
|
||||||
|
"WARNING: A print request was detected on not active shell backend.\n"
|
||||||
|
|
||||||
#define SHELL_INIT_OPTION_PRINTER (NULL)
|
#define SHELL_INIT_OPTION_PRINTER (NULL)
|
||||||
|
|
||||||
|
@ -85,6 +87,11 @@ static void state_set(const struct shell *shell, enum shell_state state)
|
||||||
|
|
||||||
if (state == SHELL_STATE_ACTIVE) {
|
if (state == SHELL_STATE_ACTIVE) {
|
||||||
cmd_buffer_clear(shell);
|
cmd_buffer_clear(shell);
|
||||||
|
if (flag_print_noinit_get(shell)) {
|
||||||
|
shell_internal_fprintf(shell, SHELL_WARNING, "%s",
|
||||||
|
SHELL_MSG_BACKEND_NOT_ACTIVE);
|
||||||
|
flag_print_noinit_set(shell, false);
|
||||||
|
}
|
||||||
shell_print_prompt_and_cmd(shell);
|
shell_print_prompt_and_cmd(shell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1354,6 +1361,7 @@ void shell_vfprintf(const struct shell *shell, enum shell_vt100_color color,
|
||||||
|
|
||||||
/* Sending a message to a non-active shell leads to a dead lock. */
|
/* Sending a message to a non-active shell leads to a dead lock. */
|
||||||
if (shell->ctx->state != SHELL_STATE_ACTIVE) {
|
if (shell->ctx->state != SHELL_STATE_ACTIVE) {
|
||||||
|
flag_print_noinit_set(shell, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,16 @@ static inline void flag_last_nl_set(const struct shell *shell, uint8_t val)
|
||||||
shell->ctx->internal.flags.last_nl = val;
|
shell->ctx->internal.flags.last_nl = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool flag_print_noinit_get(const struct shell *shell)
|
||||||
|
{
|
||||||
|
return shell->ctx->internal.flags.print_noinit == 1 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flag_print_noinit_set(const struct shell *shell, bool val)
|
||||||
|
{
|
||||||
|
shell->ctx->internal.flags.print_noinit = val ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void shell_op_cursor_vert_move(const struct shell *shell, int32_t delta);
|
void shell_op_cursor_vert_move(const struct shell *shell, int32_t delta);
|
||||||
void shell_op_cursor_horiz_move(const struct shell *shell, int32_t delta);
|
void shell_op_cursor_horiz_move(const struct shell *shell, int32_t delta);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue