Instead of using 32 bit enum values for event numbers, convert
the code to use 64 bit long bit fields. This means that the
user API is changed to use 64 bit event values instead of 32
bit event values.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The 50 ms TX mutex timeouts introduced in commit b0a0feb cause
dropped messages when used with the shell log backend. This
commit makes time timeout configurable using the
CONFIG_SHELL_TX_TIMEOUT_MS Kconfig option and makes the
default timeout longer when shell log backend is enabled.
Link: #90215
Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
In order to enable better and more consistent help messages for shell
commands, this commit introduces a new SHELL_HELP macro that allows to
document a command's description and usage in a more structured way.
This will allow to get rid of inconsistent (and duplicated!) variations
of "Syntax: ...", "Syntax:\n ...", "Usage: ...", in the commands, and
formatting of the description+usage will be taken care of by the shell
when it detects the help message is using the "structured" format.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Lines following newlines in shell help text were not properly indented.
For example, in "abc def\ndef ghi\njkl mno", the lines "def ghi" and
"jkl mno" would appear without the expected left margin.
The issue was that after processing a newline and setting proper cursor
position, the function would fall through to z_shell_raw_fprintf() which
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The `sh_mqtt_rx_rb_flush` function was intended to flush `rx_rb` when
get an error return from `mqtt_read_publish_payload_blocking`.
Instead of retrieving values from `rx_rb` one by one, calling
`ring_buf_reset` achieves the same result more efficiently.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Introduce a local pointer, `struct shell_mqtt *sh`, to minimize access
to the module-scoped `sh_mqtt` variable.
This allows `sh` to be stored in a CPU register, resulting in more
compact code and improved execution efficiency.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
For testing purposes only. Testing the fatal error handler or
a coredump backend. Or just out of curiosity.
Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
Add support for DICONNECT message specified in MQTT 5.0.
As with MQTT 5.0, the disconnect can now also be initiated by the
broker, it was needed to add decoder support for the message.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Set the default maximum argument count for the shell to 30
when the Wi-Fi shell is enabled, to ensure all Wi-Fi
commands work without failure.
Signed-off-by: Triveni Danda <triveni.danda@nordicsemi.no>
If the RTT shell backend is selected and the "down" buffer size
has been selected, the shell bypass functionality should instead
use the buffer size specified by the configuration.
Signed-off-by: Christopher Clingerman <christopher.clingerman@sensorfy.ai>
PR #84651 introduced new shell commands that don't compile if
CONFIG_THREAD_MONITOR=n
Add THREAD_MONITOR to new shell commands.
Signed-off-by: Jeremy Bettis <jbettis@google.com>
This commit extends the shell command functionality by
adding three new operations for thread management.
kernel thread suspend <thread_id>:
Suspends any thread based on its identifier.
kernel thread resume <thread_id>:
Resumes the thread that was previously suspended.
kernel thread kill <thread_id>:
Terminates any thread based on its identifier
These extended commands are useful for controlling
any threads through Zephyr Shell.
Signed-off-by: S Swetha <s.swetha@intel.com>
When reprinting the shell command buffer with long user inputs, the
reprinted buffer may cross a line boundary, and require a newline to be
printed. For these cases, print the command buffer character by
character, inserting newlines as appropriate.
Fixes#82155
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
Fixes an issue where the shell API could block indefinitely when called
from threads other than the shell's processing thread, especially when
the transport (e.g. USB CDC ACM) was unavailable or inactive.
Replaced `k_mutex_lock` calls with an indefinite timeout (`K_FOREVER`)
by using a fixed timeout (`K_MSEC(SHELL_TX_MTX_TIMEOUT_MS)`) in shell
API functions to prevent indefinite blocking.
Link: https://github.com/zephyrproject-rtos/zephyr/issues/84274
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Introduced a new Kconfig option `SHELL_PRINTF_AUTOFLUSH` to allow
configuring the autoflush behavior of shell printing functions.
Updated `Z_SHELL_FPRINTF_DEFINE` to use the
`CONFIG_SHELL_PRINTF_AUTOFLUSH` setting instead of hardcoding
the autoflush behavior to `true`.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
Log_level command is a duplicate of 'log enable' command from
the logging command set (enabled by CONFIG_LOG_CMDS=y). Adding
warning about deprecation as 'log enable' is recommended since
it has more features (e.g. autocompletion).
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
fix coverity issue about deadcode, there is no code path which would
lead to the code that is being deleted with this commit
Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
In case websocket logger is disabled, the websocket shell backend should
still build, fix that.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
In case websocket logging is enabled, the websocket shell should not be
configured as a logger backend, otherwise logs are duplicated.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Wrong symbol was used for log level when registering logger instance for
websocket shell, causing misconfiguration and in result unexpected
crashes.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Mostly a revert of commit b1def7145f ("arch: deprecate `_current`").
This commit was part of PR #80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.
The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.
Hence this revert.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Passing HTTP upgrade request context to the user callback allows the
user to decide whether to accept or reject the websocket connection
based on the HTTP headers in the request. The primary reason for this is
to enable authentication of the websocket connection (e.g. via cookies
or Authorization header).
Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
This commit includes cleanups to `kernel_service`:
- `shell_tdata_dump()`:
Adjust formatting to align with `.clang-format`.
- `shell_stack_dump()`:
Update to pass `sh` directly instead of `user_data` since
it is already assigned.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Switch from using direct `strtoul` calls to `shell_strtoul`.
This change leverages the extensive error handling provided
by `shell_strtoul`.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
As `strtoul`, `strtoll`, and `strtol` guarantee to set `endptr`,
the initial `NULL` can be omitted.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
RTT backend can only be called from thread context and immediate
logging might lead to interrupt context use. Previously this limitation
was implied in different way and commit (c88a9ef27) got reverted.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Added shell_device_get_binding() that wraps device_get_binding() plus
device_get_by_dt_nodelabel() so that a shell can easily get a device by
its full name or label.
Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Addresses in cmd_load() should always be unsigned. Previously, strtol()
was used, which is limited to signed long values, causing issues with
addresses >= 0x80000000. This commit replaces strtol() with strtoul(),
ensuring proper handling of the full 32-bit address space.
Fixes#81343
Signed-off-by: Aaron Fontaine <aaron.fontaine@dojofive.com>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
The NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC() macro was changed
earlier but the compilation error was missed. Fixing the macro
call.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
remove k_work related code and change
the argument of the callback to `struct net_socket_service_event`.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Shell is capable of acting as the logging backend and multiplex
logging messages with shell content. It expects that logging
messages goes through the logging backend. However, there is an
option that logs go only to the custom logging frontend. In
that case this default approach does not work and logging
frontend cannot be easily integrated with the shell (due to
its custom nature). Add Kconfig option SHELL_LOG_BACKEND_OOB
which prevent compilation of the default shell log backend.
When enabled, application can provide frontend specific
implementation to integrate shell with the logging.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This creates a websocket based shell backend that is used to
implement a websocket console that can be connected using a browser.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The code in shell_ops.c that calls telnet_write will assert if it
returns non-zero. For a telnet shell it's normal that the
network might disconnect unexepectedly, so that should not
trigger an assert.
Fixes#67637
Link: https://github.com/zephyrproject-rtos/zephyr/issues/67637
Signed-off-by: Kevin ORourke <kevin.orourke@ferroamp.se>
Remove the `work_q` parameter from `NET_SOCKET_SERVICE_SYNC_DEFINE` and
`NET_SOCKET_SERVICE_SYNC_DEFINE_STATIC` as this feature was dropped
during review but the removal was not 100% complete.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Added a generic function `z_shell_backend_rx_buffer_flush` to clear
the RX buffer when resuming the shell. The function repeatedly calls
the backend's `read` API until the buffer is empty or a maximum of
1000 iterations is reached. This prevents unintended command
execution after `shell_start`.
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@verkada.com>
For code clarity, this commit adjusts the use of `return` statements
in functions with a void return type as follows:
- Transform `return foo();` into separate statements:
`foo();`
`return;`
- Remove unnecessary `return` statements when
they don't affect control flow.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Add the "kernel_shell.h" header which is required but missing,
causing build error.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Parts related to the thread runtime stats are somewhat
standalone, refactor it out instead of having two #ifdef
and two places.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Split the `kernel_service.c` into multiple subcommand files,
each file would register with the main `kernel` cmd based on
the dependencies in Kconfig/CMakeLists.txt.
This greatly reduces the number of precompiler directives.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Since the `_impl` naming convention is intended for internal use only,
renaming these functions to the `shell_fprintf_xxx` variant is
more suitable for calls outside the module:
- `shell_info_impl` to `shell_fprintf_info`
- `shell_print_impl` to `shell_fprintf_normal`
- `shell_warn_impl` to `shell_fprintf_warn`
- `shell_error_impl` to `shell_fprintf_error`
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Move the network buffer header file from zephyr/net/buf.h to
zephyr/net_buf.h as the implementation now lives outside of the networking
subsystem.
Add (deprecated) zephyr/net/buf.h header to maintain compatibility with old
file path.
Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>