subsys: shell: add handlers diagnostic function

Added function: shell_execute_cmd that can be called
for command diagnostic purposes.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2018-10-02 09:37:19 +02:00 committed by Carles Cufí
commit 61ca8c17c8
2 changed files with 32 additions and 0 deletions

View file

@ -585,6 +585,20 @@ bool shell_cmd_precheck(const struct shell *shell,
void shell_print_stream(const void *user_ctx, const char *data, void shell_print_stream(const void *user_ctx, const char *data,
size_t data_len); size_t data_len);
/** @brief Execute command.
*
* Pass command line to shell to execute.
*
* Note: This by no means makes any of the commands a stable interface, so
* this function should only be used for debugging/diagnostic.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] cmd Command to be executed.
*
* @returns Result of the execution
*/
int shell_execute_cmd(const struct shell *shell, const char *cmd);
/** /**
* @} * @}
*/ */

View file

@ -1720,3 +1720,21 @@ bool shell_cmd_precheck(const struct shell *shell,
return true; return true;
} }
int shell_execute_cmd(const struct shell *shell, const char *cmd)
{
u16_t cmd_len = shell_strlen(cmd);
if ((cmd == NULL) || (shell == NULL)) {
return -ENOEXEC;
}
if (cmd_len > (CONFIG_SHELL_CMD_BUFF_SIZE - 1)) {
return -ENOEXEC;
}
strcpy(shell->ctx->cmd_buff, cmd);
shell->ctx->cmd_buff_len = cmd_len;
return shell_execute(shell);
}