I’m issuing commands over the UART, which is the normal use case. And I need this functionality. In addition, it would be really helpful to be able to call these same custom shell commands from the app itself. That is what I mean by “inject” commands. A better description would be that I am circumventing the command input and parsing pieces and calling the command handlers directly.
When custom commands have command “handlers”, those handling routines are required to implement a particular signature.
I initially modeled my code after the example at this Goliath article: https://blog.golioth.io/how-to-add-custom-shell-commands-in-zephyr/#putting-it-all-together.
The custom commands are defined like the following:
static int custom_command(const struct shell *shell, size_t argc, char *argv[])
. . . but the Zephyr shell facility does not appear to expose the instance of the shell that’s created by, I am guessing, a combination of the macros SHELL_STATIC_SUBCMD_SET_CREATE() and SHELL_CMD_REGISTER().
If I were able to create a const struct shell *shell_ptr
and assign it the address of the particular shell my application creates, then I would be able to call my custom shell functions from the app. Without a pointer to the run time struct shell
instance, I have no way to call my custom commands programmatically. That first parameter in the signature is not a simple data type. It’s peculiar to the shell subsystem, and specific to the code to which Zephyr shell macros expand.
I don’t think Zephyr developers have set things up to support this notion, but I figure someone here may likely have used Zephyr shell and come to the same need. Maybe someone has figured out if this can be achieved, or if a different approach altogether is required.