Part 1
요약·해설
QEMU·hardware build와 demo·dynamic command tree 전체 출력을 보존합니다.
Static · Conditional · Dynamic
Dictionary · Demo
Bypass · Login · Obscure
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
5A071500F9CA86ABFE61219C53C636EAB8F5C8F8204CA933CAE0824E8ED0D662
.. zephyr:code-sample:: shell-module
:name: Custom Shell module
:relevant-api: shell_api
Register shell commands using the Shell API
Overview
********
This is a simple application demonstrating how to write and register commands
using the :ref:`Shell API <shell_api>`:
Register Static commands
``version`` is a static command that prints the kernel version.
Conditionally Register commands
``login`` and ``logout`` are conditionally registered commands depending
on :kconfig:option:`CONFIG_SHELL_START_OBSCURED`.
Register Dynamic commands
See ``dynamic`` command and :zephyr_file:`samples/subsys/shell/shell_module/src/dynamic_cmd.c`
for details on how dynamic commands are implemented.
Register Dictionary commands
``dictionary`` implements subsect of dictionary commands.
Set a Bypass callback
``bypass`` implements the bypass callback.
Set a Login command
``login`` and ``logout`` implement the login and logout mechanism, respectively.
Obscure user-input with asterisks
``login`` and ``logout`` implement the feature of enabling and disabling
this functionality, respectively.
Requirements
************
* A target configured with the shell interface, exposed through any of
its :ref:`backends <backends>`.
Building and Running
********************
This sample can be found under :zephyr_file:`samples/subsys/shell/shell_module`
in the Zephyr tree.
The sample can be built for several platforms.
Emulation Targets
=================
The sample may run on emulation targets. The following commands build the
application for the qemu_x86.
.. zephyr-app-commands::
:zephyr-app: samples/subsys/shell/shell_module
:host-os: unix
:board: qemu_x86
:goals: run
:compact:
After running the application, the console displays the shell interface, and
shows the shell prompt, at which point the user may start the interaction.
On-Hardware
===========
.. zephyr-app-commands::
:zephyr-app: samples/subsys/shell/shell_module
:host-os: unix
:board: nrf52840dk/nrf52840
:goals: flash
:compact:
Sample Output
*************
.. code-block:: console
uart:~$
bypass clear date
demo device devmem
dynamic help history
kernel log log_test
rem resize retval
section_cmd shell shell_uart_release
stats version
uart:~$ demo
demo - Demo commands
Subcommands:
dictionary : Dictionary commands
hexdump : Hexdump params command.
params : Print params command.
ping : Ping command.
board : Show board name command.
uart:~$ dynamic
dynamic - Demonstrate dynamic command usage.
Subcommands:
add : Add a new dynamic command.
Example usage: [ dynamic add test ] will add a dynamic command
'test'.
In this example, command name length is limited to 32 chars. You can
add up to 20 commands. Commands are automatically sorted to ensure
correct shell completion.
execute : Execute a command.
remove : Remove a command.
show : Show all added dynamic commands.
uart:~$
Details on Shell Subsystem
==========================
For more details on the Shell subsystem, check the general :ref:`Shell documentation <shell_api>`.
Part 3
한국어 전문 번역
개요
Shell API로 command를 작성하고 등록하는 방법을 보여 주는 application입니다.
- Static command 등록
version은 kernel version을 출력하는 static command입니다.- 조건부 command 등록
login과logout은CONFIG_SHELL_START_OBSCURED에 따라 조건부로 등록됩니다.- Dynamic command 등록
dynamiccommand와samples/subsys/shell/shell_module/src/dynamic_cmd.c가 runtime command 구현을 보여 줍니다.- Dictionary command 등록
dictionary가 dictionary subcommand 집합을 구현합니다.- Bypass callback 설정
bypass가 shell bypass callback을 구현합니다.- Login command 설정
login과logout이 login/logout mechanism을 구현합니다.- 입력을 별표로 가리기
login은 user input obscuring을 활성화하고logout은 비활성화합니다.
요구 사항
사용 가능한 backend 가운데 하나를 통해 shell interface를 노출하도록 설정된 target이 필요합니다.
빌드 및 실행
Sample은 Zephyr tree의 samples/subsys/shell/shell_module에 있으며 여러 platform에서 build할 수 있습니다.
Emulation Target
다음 command로 qemu_x86에서 application을 build하고 실행합니다. 실행 후 console에 shell prompt가 나타나면 interaction을 시작할 수 있습니다.
west build -b qemu_x86 samples/subsys/shell/shell_module
west build -t run
실제 하드웨어
다음 command로 nrf52840dk/nrf52840용 application을 build하고 flash합니다.
west build -b nrf52840dk/nrf52840 samples/subsys/shell/shell_module
west flash
샘플 출력
Top-level help에는 demo, dynamic, version 등 등록된 command가 나타납니다. demo 아래에는 dictionary, hexdump, params, ping, board subcommand가 표시됩니다.
dynamic 아래에는 add, execute, remove, show가 있습니다. Add는 최대 32-character 이름의 dynamic command를 최대 20개 만들며 shell completion이 올바르게 동작하도록 자동 정렬합니다.
uart:~$
bypass clear date
demo device devmem
dynamic help history
kernel log log_test
rem resize retval
section_cmd shell shell_uart_release
stats version
uart:~$ demo
demo - Demo commands
Subcommands:
dictionary : Dictionary commands
hexdump : Hexdump params command.
params : Print params command.
ping : Ping command.
board : Show board name command.
uart:~$ dynamic
dynamic - Demonstrate dynamic command usage.
Subcommands:
add : Add a new dynamic command.
Example usage: [ dynamic add test ] will add a dynamic command
'test'.
In this example, command name length is limited to 32 chars. You can
add up to 20 commands. Commands are automatically sorted to ensure
correct shell completion.
execute : Execute a command.
remove : Remove a command.
show : Show all added dynamic commands.
uart:~$
Shell Subsystem 상세 정보
더 자세한 내용은 일반 Shell subsystem 및 Shell API 문서를 참조합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.