Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsys: shell rework #9362

Merged
merged 10 commits into from
Sep 19, 2018
Merged

subsys: shell rework #9362

merged 10 commits into from
Sep 19, 2018

Conversation

jakub-uC
Copy link
Contributor

@jakub-uC jakub-uC commented Aug 9, 2018

Me and @nordic-krch have reworked Zephyr shell Task 8872.
New one has a lot of useful features that were missing in the old one.

We have changed commands concept.

  1. Shell commands are now organized in a tree structure and grouped into the following types:
  • Root command (level 0): Kept in the section variable area. Root command is always static.
  • Static subcommand (level > 0): Number and syntax must be known during compile time. Kept in the software module.
  • Dynamic subcommand (level > 0): Number and syntax does not need to be known during compile time. Created in the software module.

On one command level all commands must be the same type: static or dynamic.
An example usage of dynamic commands concept is described here:
https://devzone.nordicsemi.com/b/blog/posts/new-command-line-interface-part-1

  1. Commands execution
    Each command or subcommand on each level can either have or not have a handler. Shell executes the handler that is found deepest in the command tree and further subcommands (without a handler) are passed as arguments. Characters within parentheses are treated as one argument. Each command or subcommand without a handler can be treated as an argument, or it can still have a subcommand with a handler and there is no problem for the user to execute it.
    It is recommended to use subcommands over options. Options apply mainly in the case when an argument with '-' or "--" is requested.

  2. Commands help
    Every user-defined command, subcommand, or option can have its own help description. The help for commands and subcommands can be created with respective macros: SHELL_CMD_REGISTER, SHELL_CMD. In addition, you can define options for commands or subcommands using the macro SHELL_OPT. By default, each and every command or subcommand has these two options implemented: "-h" and "--help".
    In order to add help functionality to a command or subcommand, you must call the help function shell_help_print inside of a command handler.

New features:

  • Multi-instance - you can have independent shells on different transmission mediums

  • Multiline commands - Shell will correctly print and allow to edit commands longer than 1 line.

  • Integration with Log module - you can read logs on the shell screen, filter them dynamically (activate logs only for needed modules), suspend or resume. At the same time you can type, edit or execute a command.

  • Smart completion with the Tab key. One can prompt and partially/fully complete commands or its subcommands.

  • Commands history - Executed commands can be listed by history command or recalled with up / down arrows.

  • Built-in commands - Shell related commands already implemented and available for the user:

  1. clear - clears the screen
  2. history - prints recently called commands
  3. resize - command shall be called each time terminal width has changed. It will ensure correct text formatting (currently it is only working with UART flow control on)
  4. shell colors - switch on / off colored syntax
  5. shell echo - switch on / off shell echo
  6. shell backspace_mode - allows to adjust backspace escape code during runtime.
  7. shell stats - gives an information about lost (not printed) logs
  • Easy command edition with buttons: Tab/Backspace/Delete/Arrows/Home/End

  • Meta Keys:

  1. ctrl + a - Moves the cursor to the beginning of the line.
  2. ctrl + c - Preserves the last command on the screen and starts a new command in a new line.
  3. ctrl + e - Moves the cursor to the end of the line.
  4. ctrl + l - Clears the screen and leaves the currently typed command at the top of the screen.
  5. ctrl + u - Clears the currently typed command.
  6. ctrl + w - Removes the word or part of the word to the left of the cursor. Words separated by period instead of space are treated as one word.
  • Wildcards support for: * and ?

  • Kconfig configuration to optimize resources usage.

@jakub-uC
Copy link
Contributor Author

jakub-uC commented Aug 9, 2018

@carlescufi FYI

@nordic-krch
Copy link
Contributor

@jukkar @jhedberg please take a look. Shell is ready thus bluetooth and network commands adaptation can start. Checkout samples/subsys/shell to see how to port.

@codecov-io
Copy link

codecov-io commented Aug 9, 2018

Codecov Report

Merging #9362 into master will decrease coverage by 0.76%.
The diff coverage is 38.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9362      +/-   ##
==========================================
- Coverage   52.94%   52.18%   -0.77%     
==========================================
  Files         214      212       -2     
  Lines       26163    25924     -239     
  Branches     5639     5570      -69     
==========================================
- Hits        13853    13528     -325     
- Misses      10037    10133      +96     
+ Partials     2273     2263      -10
Impacted Files Coverage Δ
subsys/shell/shell_service.c 100% <ø> (ø) ⬆️
include/misc/dlist.h 92.59% <ø> (ø) ⬆️
subsys/logging/log_core.c 67.66% <0%> (-2.57%) ⬇️
subsys/logging/log_output.c 2.64% <0%> (-62.96%) ⬇️
subsys/shell/legacy_shell.c 47.16% <47.16%> (ø)
subsys/random/rand32_timer.c 0% <0%> (-100%) ⬇️
lib/cmsis_rtos_v1/cmsis_kernel.c 0% <0%> (-80%) ⬇️
lib/cmsis_rtos_v1/cmsis_msgq.c 35.89% <0%> (-39.72%) ⬇️
lib/cmsis_rtos_v1/cmsis_mailq.c 50% <0%> (-30.77%) ⬇️
subsys/net/ip/ipv6.c 37.09% <0%> (-21.85%) ⬇️
... and 91 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 732b45c...9b8682c. Read the comment docs.

Copy link
Collaborator

@Qbicz Qbicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. I like the dynamic command sample. Some minor comments from me.

u32_t dynamic_lvl;
u32_t compiled_lvl;
u32_t i;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excess empty line, please also check between functions.

for (i = 0; i < modules_cnt; i++) {
p_tmp_name = log_source_name_get(CONFIG_LOG_DOMAIN_ID, i);

if (strncmp(p_tmp_name, p_name, 64) == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you name this 64?

static void cmd_log_backends_list(const struct shell *shell,
size_t argc, char **argv)
{
int backend_count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsigned or size_t

@carlescufi carlescufi added DNM This PR should not be merged (Do Not Merge) area: Console labels Aug 9, 2018
@jakub-uC jakub-uC force-pushed the shell_rework branch 2 times, most recently from cedc5e8 to 0d14a8b Compare August 10, 2018 08:16
@jakub-uC jakub-uC changed the title Shell rework subsys: shell rework Aug 10, 2018
@nashif nashif added the area: Shell Shell subsystem label Aug 10, 2018
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -33,3 +33,89 @@ config CONSOLE_SHELL_MAX_CMD_QUEUED
source "subsys/shell/modules/Kconfig"

endif

config SHELL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried this with make menuconfig and the shell support looks really bad as all the config options are in the "root". The Kconfig seems to be missing menu "Shell support" or similar command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jukkar : done

New shell implementation is on the way. For now old one and all
references are kept to be gradually replaced by new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
New shell support features like:
- multi-instance
- command tree
- static and dynamic commands
- multiline
- help print function
- smart tab (autocompletion)
- meta-keys
- history, wildcards etc.
- generic transport (initially, uart present)

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
Ported shell sample to use new shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added function for peeking into previous item in the list.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Extending shell with terminal-like  history feature.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added optional shell commands:
- clear - for clearing terminal
- history - commands history
- resize - terminal resize
- shell - controling echo and colors

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Initial logger backend support added to shell.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added commands for getting current status and controlling which log
messages are forwared to available backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Library will be used by new shell implementation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Extended shell to support wildcard characters: * and ? and expand
commands accordingly.
Increased default stack size.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
@nashif nashif merged commit 68249ce into zephyrproject-rtos:master Sep 19, 2018
aescolar added a commit to aescolar/zephyr that referenced this pull request Sep 24, 2018
Fix merge error introduced in:
ba01a39
(as part of zephyrproject-rtos#9362)
which deleted the native_posix backend for the logger.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
carlescufi pushed a commit that referenced this pull request Sep 24, 2018
Fix merge error introduced in:
ba01a39
(as part of #9362)
which deleted the native_posix backend for the logger.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
@jakub-uC jakub-uC deleted the shell_rework branch October 4, 2018 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants