shell: Add option to bypass shell

Added api call that can set a callback that is called whenever
data is received on shell. When callback is set, shell processing
is bypassed and data is passed to that callback.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-06-09 10:53:53 +02:00 committed by Anas Nashif
commit e05aa6dc3e
2 changed files with 51 additions and 3 deletions

View file

@ -501,6 +501,16 @@ typedef void (*shell_transport_handler_t)(enum shell_transport_evt evt,
typedef void (*shell_uninit_cb_t)(const struct shell *shell, int res);
/** @brief Bypass callback.
*
* @param shell Shell instance.
* @param data Raw data from transport.
* @param len Data length.
*/
typedef void (*shell_bypass_cb_t)(const struct shell *shell,
uint8_t *data,
size_t len);
struct shell_transport;
/**
@ -663,6 +673,9 @@ struct shell_ctx {
*/
shell_uninit_cb_t uninit_cb;
/*!< When bypass is set, all incoming data is passed to the callback. */
shell_bypass_cb_t bypass;
#if defined CONFIG_SHELL_GETOPT
/*!< getopt context for a shell backend. */
struct getopt_state getopt_state;
@ -1044,6 +1057,16 @@ int shell_execute_cmd(const struct shell *shell, const char *cmd);
*/
int shell_set_root_cmd(const char *cmd);
/** @brief Set bypass callback.
*
* Bypass callback is called whenever data is received. Shell is bypassed and
* data is passed directly to the callback. Use null to disable bypass functionality.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] bypass Bypass callback or null to disable.
*/
void shell_set_bypass(const struct shell *shell, shell_bypass_cb_t bypass);
/**
* @brief Allow application to control text insert mode.
* Value is modified atomically and the previous value is returned.