The previous behavior of the CONFIG_SHELL_AUTOSTART option, where setting
it to 'n' disabled shell interaction at startup but kept the logger
active as a shell backend, was inconsistent.
Now, when CONFIG_SHELL_AUTOSTART is set to 'n', both the shell and the
logger are inactive at startup. Calling the shell_start function will
activate them and print any pending logs. This change ensures a more
consistent and logical behavior regarding shell and logger activity at
startup.
Additionally, now when the shell_stop function is called, both the shell
and the logger are halted. This enhancement ensures that stopping
the shell also effectively stops the associated logger.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Added some new APIs to get the backend instances more easily,
so that dev does not need to rely on `shell_backend_*_get_ptr`,
which looks more like a hack to access a local variable.
These APIs are basically copied from the log backend
implementation.
Added testcase for the APIs.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Rename the shell backend `thread_name` variable to just `name`,
to be used for other things not specific to thread later.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Compiler can't tell that k_thread_abort() won't return and issues a
warning unless we tell it that control never gets this far.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Without this fix, for every call to shell_vfprintf,
a prompt string and vt100 codes are printed too,
resulting in mangled log output.
Signed-off-by: Lars Knudsen <lakd@demant.com>
This change to the shell API enables the user to retrieve the
return code of the most recently run shell command. This is
useful both for users wanting specific information beyond the print
statements in a command, but especially for automated users
that prefer a simple return code to parsing human readable text.
This was tested using all default shell commands, as well as
eeprom, flash, and i2c, where specific errors could be forced.
In all cases, the correct return value was returned by the new
retval command.
Signed-off-by: Hunter Searle <hsearle@xes-inc.com>
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
We get compile warnings of the form:
error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
[-Werror,-Wint-in-bool-context]
if (!isprint(byte)) {
^
Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
We get compile warnings of the form:
drivers/console/uart_console.c:508:8: error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
[-Werror,-Wint-in-bool-context]
if (!isprint(byte)) {
^
Since isprint returns an int, change check to an explicit test against
the return value.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
If bypass mode is left outside of the registered bypass handler, the
command buffer was not cleared, basically containig leftovers from the
processing of the previous command. This resulted in undefined behaviour
on consecutive shell operations.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In some applications, there is a need to don't start the shell by
default, but run it later on some special condition.
When SHELL_AUTOSTART is set to n, the shell is not started after
boot but can be enabled later from the application code.
Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
Tests with shell commands will fail if they are started
before the shell backend is initialized or started.
Adding API function: shell_ready indicating shell readiness.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Previous code provided incorrect argc value to handlers when a command
used SHELL_OPT_ARG_RAW option.
Fixes#48380
Signed-off-by: Eric Johnson <eric.johnson2@walgreens.com>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Fixed the issue when sometimes "update" is not called for the
last RXRDY signal. First, need to reset the signal and only
after that need to call the "update" function.
Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
Reduced logging mode selection to deferred, immediate, minimal and
frontend. Decoupled logging version from mode and created CONFIG_LOG1
which can be used to explicitly select deprecated version.
From now on, chosing CONFIG_LOG_MODE_{IMMEDIATE,DEFERRED} will result
in version2.
Deprecated CONFIG_LOG2_MODE_{IMMEDIATE,DEFERRED} with cmake warning.
Codebase adapted to those changes.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Getopt has been rework in this way that calling it does not require
extra state parameter and its execution is thread safe.
Global parameters describing the state of the getopt function have been
made available to ensure full API compatibility in using this library.
However, referencing these global variables directly is not thread
safe. In order to get the state of the getopt function for the thread
that is currently using it, call: getopt_state_get();
Extended the library with getopt_long and getopt_long_only functions.
Moved getopt libary from utils to posix.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Each backend can configure separately features like colors on/off, VT100
handling and so on. This can be very handy for planned MQTT backend.
Shell will not send VT100 commands when VT100 is not enabled globally or
for particular backend.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
The function to execute shell commands: shell_execute_cmd will now
behave similarly to invoking command line commands.
I.e. after the command is executed the command buffer is cleared,
while the cursor is set to the initial position.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Currently, in Zephyr the shell thread is the lowest priority i.e.
K_LOWEST_APPLICATION_THREAD_PRIO. Due to this all the other threads can
preempt the shell thread. Proposed solution is to add Kconfig which
gives the flexibility to change the priority of the shell thread.
This is now implemented using a new Kconfig variable
SHELL_THREAD_PRIORITY_OVERRIDE. By setting this option
SHELL_THREAD_PRIORITY can be set.
Signed-off-by: Uday Ammu <udaykiran@google.com>
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>
If the shell root command shall be set in the application, e.g. for
implementing a login scheme, it is an advantage to set this already
during shell init.
This is now implemented using a new Kconfig variable SHELL_CMD_ROOT.
Signed-off-by: Hans Wilmers <hans@wilmers.no>
The commit adds Kconfig option to configure dummy shell buffer size.
Size of this buffer determines how mutch of command output will be
stored in buffer.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Shell uninitialization is not synchronous, it is deferred to shell
thread so resources used by the shell (e.g. transport resource like
uart) cannot be used until it is completed. Added callback which
notifies when all resources are released and shell is uninitialized.
Callback is called from shell thread just before it is aborted.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Add Z_SHELL_SET_FLAG_ATOMIC macro to use technique from
shell_process() to atomically set and return the previous
value.
Change all void z_flag_*_set() functions to bool z_flag_*_set()
and use macro to return previous value after setting.
Modify shell_process() to use this modified z_flag_processing_set()
function.
Reorder flags to keep last_nl on byte boundary.
Add public setters for insert_mode, echo, and mode_delete for
completeness.
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
Add flag to shell_flags to control echo as obscure
character (for passwords) or not. Add setter and getter
functions. Modify shell echo to use this flag if set.
Also add public setter for color mode and obscure mode.
Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
Building this file with CONFIG_COVERAGE=y and CONFIG_SHELL_LOG_BACKEND=n
fails on the llvm-clang compiler. Swapping the IS_ENABLED and
log_backend allows the compiler to optimize out the if block even with
coverage enabled.
Signed-off-by: Jeremy Bettis <jbettis@chromium.org>
This functionality is is enabled by setting CONFIG_SHELL_GETOPT.
It is not active by default.
User can call following functions inside command handlers:
- shell_getopt - getopt function based on freebsd implementation
- shell_getopt_status_get - returns getopt status
Beware when getopt functionality is enabled shell will not parse
command handler to look for "-h" or "--help" options and print
help message automatically.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Shell will not "steal" by default "-h" and "--help" each time
help functions are enabled.
This change is necessary to implement and use the getopt library.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
The ASSERT order is backwards, where the shell->ctx is being accessed
before it is being checked as valid. Moving the check for the
shell->ctx to before the using it.
Signed-off-by: Dan Kalowsky <dkalowsky@amperecomputing.com>
The help command is needed to list all available commands
when it is not possible to use the tab key.
Previously when build-in commands were deactivated command
help was not compiled as well.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Added IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) to remove a dead code.
Added static inline function that returns pointer to the selected
command.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>