Skip to content

Commit

Permalink
Integrated Zephyr shell with the CHIP lib shell (project-chip#7848)
Browse files Browse the repository at this point in the history
Currently there was a standalone CHIP shell example using
CHIP lib shell and there was a Zephyr shell used only by
nrfconnect platform with some specific commands. The goal
is to use for Zephyr based platforms the CHIP lib shell
but with Zephyr shell backend integrated and be able to use it
in every example, not only standalone shell app.

For nrfconnect:
* Removed custom Zephyr-based ChipShell.cpp
and CONFIG_CHIP_ZEPHYR_SHELL option.
* Renamed CONFIG_CHIP_STANDALONE_SHELL to the CONFIG_CHIP_LIB_SHELL.
* Aligned console docs to the new commands.

For all:
* Extended existing shell commands by ble adv <state>,
onboardingcodes <qrcode|qrcodeurl|manualpairingcode>,
nfc <start|stop|state> and device factoryreset.
* Added MainLoopZephyr.cpp file for Zephyr-based platforms,
that enables Zephyr shell and is kind of integration layer
between CHIP shell and Zephyr shell.
* Removed from streamer_zephyr.cpp part not using Zephyr shell.
  • Loading branch information
kkasperczyk-no authored Jun 24, 2021
1 parent 45ed9f8 commit 2f0c691
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 347 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
"${chip_root}/src/lib",
"${chip_root}/src/lib/asn1",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/shell",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging",
"${chip_root}/src/protocols",
Expand Down
5 changes: 0 additions & 5 deletions config/nrfconnect/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ assert(current_os == "zephyr")

declare_args() {
chip_build_pw_rpc_lib = false
chip_build_zephyr_shell = false
}

group("nrfconnect") {
Expand All @@ -31,10 +30,6 @@ group("nrfconnect") {
deps += [ "${chip_root}/src:tests" ]
}

if (chip_build_zephyr_shell) {
deps += [ "${chip_root}/src/platform/nrfconnect/shell:chip-zephyr-shell" ]
}

# Building PW_RPC lib with GN may go obsolete after getting full CMake
# support in Pigweed.
if (chip_build_pw_rpc_lib) {
Expand Down
18 changes: 7 additions & 11 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ if (NOT CHIP_LIBRARIES)
set(CHIP_LIBRARIES -lCHIP)
endif()

if (CONFIG_CHIP_STANDALONE_SHELL)
list(APPEND CHIP_LIBRARIES -lCHIPShell)
endif()

if (CONFIG_CHIP_ZEPHYR_SHELL)
set(CHIP_ZEPHYR_SHELL_LIBRARY -lCHIPZephyrShell)
endif()

if (CONFIG_CHIP_PW_RPC)
list(APPEND CHIP_LIBRARIES -lPwRpc)
endif()
Expand Down Expand Up @@ -206,8 +198,7 @@ chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TE
chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_STANDALONE_SHELL)
chip_gn_arg_bool ("chip_build_zephyr_shell" CONFIG_CHIP_ZEPHYR_SHELL)
chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)

if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
Expand Down Expand Up @@ -266,7 +257,12 @@ target_include_directories(chip INTERFACE
${CMAKE_CURRENT_BINARY_DIR}/gen/include
)
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
target_link_libraries(chip INTERFACE -Wl,--whole-archive ${CHIP_ZEPHYR_SHELL_LIBRARY} -Wl,--no-whole-archive,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
if (CONFIG_CHIP_LIB_SHELL)
target_link_options(chip INTERFACE -Wl,--whole-archive -lCHIPShell -Wl,--no-whole-archive)
endif()

target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)

add_dependencies(chip chip-gn)

endif() # CONFIG_CHIP
11 changes: 2 additions & 9 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ config CHIP_OPENTHREAD_CONFIG
This option can be used to replace Zephyr-supplied OpenThread
configuration file with a custom one.

config CHIP_ZEPHYR_SHELL
bool "Enable Zephyr-based CHIP shell"
default n
imply SHELL
help
Add CHIP commands to the Zephyr shell.

config CHIP_STANDALONE_SHELL
config CHIP_LIB_SHELL
bool "Enable CHIP shell library"
default n
depends on !CHIP_ZEPHYR_SHELL
imply SHELL
help
Link the application with the library containing CHIP shell commands.

Expand Down
200 changes: 153 additions & 47 deletions docs/guides/nrfconnect_examples_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,114 +90,220 @@ Done

The nRF Connect SDK examples let you use several CHIP-specific CLI commands.

These commands are not available in the standard Zephyr shell.
These commands are not available by default and to enable using them, set the
`CONFIG_CHIP_LIB_SHELL=y` Kconfig option in the `prj.conf` file of the given
example.

They are currently used for testing purposes and allow only to get some
information about CHIP stack state, but not to modify it.
Every invoked command must be preceded by the `matter` prefix.

To enable using CHIP commands, set the `CONFIG_CHIP_ZEPHYR_SHELL=y` Kconfig
option in the `prj.conf` file of the given example.
See the following subsections for the description of each CHIP-specific command.

### device

### Listing CHIP-specific commands
Handles a group of commands that are used to manage the device. You must use
this command together with one of the additional subcommands listed below.

To list all available CHIP-specific commands, enter `chip` in the command line
and press the Tab key. This will list the available commands:
#### factoryreset

Performs device factory reset that is hardware reset preceded by erasing of the
whole CHIP settings stored in a non-volatile memory.

```shell
uart:~$ chip
qrcode qrcodeurl setuppincode discriminator
vendorid productid manualpairingcode bleadvertising
nfcemulation
uart:~$ matter factoryreset
Performing factory reset ...
```

See the following subsections for the description of each CHIP-specific command.
### onboardingcodes

Handles a group of commands that are used to view information about device
onboarding codes. You can use this command without any subcommand to print all
available onboarding codes or to add a specific subcommand.

```shell
uart:~$ matter onboardingcodes
QRCode: MT:W0GU2OTB00KA0648G00
QRCodeUrl: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00
ManualPairingCode: 34970112332
```

#### `qrcode`
The `onboardingcodes` command can also take the subcommands listed below.

#### qrcode

Prints the device
[onboarding QR code payload](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/nrfconnect_android_commissioning.md#preparing-accessory-device).
Takes no arguments.

```shell
uart:~$ chip qrcode
uart:~$ matter onboardingcodes qrcode
MT:W0GU2OTB00KA0648G00
```

#### `qrcodeurl`
#### qrcodeurl

Prints the URL to view the
[device onboarding QR code](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/nrfconnect_android_commissioning.md#preparing-accessory-device)
in a web browser. Takes no arguments.

```shell
uart:~$ chip qrcodeurl
https://dhrishi.github.io/connectedhomeip/qrcode.html?data=CH%3AH34.GHY00%200C9SS0
uart:~$ matter onboardingcodes qrcodeurl
https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00
```

#### manualpairingcode

Prints the pairing code for the manual onboarding of a device. Takes no
arguments.

```shell
uart:~$ matter onboardingcodes manualpairingcode
34970112332
```

### config

Handles a group of commands that are used to view device configuration
information. You can use this command without any subcommand to print all
available configuration data or to add a specific subcommand.

```shell
VendorId: 9050 (0x235A)
ProductId: 20043 (0x4E4B)
ProductRevision: 1 (0x1)
FabricId:
PinCode: 020202021
Discriminator: f00
DeviceId:
```

#### `setuppincode`
The `config` command can also take the subcommands listed below.

#### pincode

Prints the PIN code for device setup. Takes no arguments.

```shell
uart:~$ chip setuppincode
12345678
uart:~$ matter config pincode
020202021
```

#### `discriminator`
#### discriminator

Prints the device setup discriminator. Takes no arguments.

```shell
uart:~$ chip discriminator
3840
uart:~$ matter config discriminator
f00
```

#### `vendorid`
#### vendorid

Prints the vendor ID of the device. Takes no arguments.

```shell
uart:~$ chip vendorid
9050
uart:~$ matter config vendorid
9050 (0x235A)
```

#### `productid`
#### productid

Prints the product ID of the device. Takes no arguments.

```shell
uart:~$ chip productid
20043
uart:~$ matter config productid
20043 (0x4E4B)
```

#### `manualpairingcode`
#### productrev

Prints the pairing code for the manual onboarding of a device. Takes no
arguments.
Prints the product revision of the device. Takes no arguments.

```shell
uart:~$ chip manualpairingcode
35767807533
uart:~$ matter config productrev
1 (0x1)
```

#### `bleadvertising`
#### deviceid

Prints the information about the Bluetooth LE advertising status, either `0` if
the advertising is disabled on the device or `1` if it is enabled. Takes no
arguments.
Prints the device identifier. Takes no arguments.

#### fabricid

Prints the fabric identifier. Takes no arguments.

### ble

Handles a group of commands that are used to control the device Bluetooth LE
transport state. You must use this command together with one of the additional
subcommands listed below.

#### help

Prints help information about `ble` commands group.

```shell
uart:~$ chip bleadvertising
0
uart:~$ matter ble help
help Usage: ble <subcommand>
adv Enable or disable advertisement. Usage: ble adv <start|stop|state>
```

#### `nfcemulation`
#### adv start

Prints the information about the NFC tag emulation status, either `0` if the
emulation is disabled on the device or `1` if it is enabled (1). Takes no
arguments.
Enables Bluetooth LE advertising.

```shell
uart:~$ matter ble adv start
Starting BLE advertising
```

#### adv stop

Disables Bluetooth LE advertising.

```shell
uart:~$ matter ble adv stop
Stopping BLE advertising
```

#### adv status

Prints the information about the current Bluetooth LE advertising status.

```shell
uart:~$ matter ble adv state
BLE advertising is disabled

```

### nfc

Handles a group of commands that are used to control the device NFC tag
emulation state. You must use this command together with one of the additional
subcommands listed below.

#### start

Starts the NFC tag emulation.

```shell
uart:~$ matter nfc start
NFC tag emulation started
```

#### stop

Stops the NFC tag emulation.

```shell
uart:~$ matter nfc stop
NFC tag emulation stopped
```

#### state

Prints the information about the NFC tag emulation status.

```shell
uart:~$ chip nfcemulation
0
uart:~$ matter nfc state
NFC tag emulation is disabled
```
5 changes: 1 addition & 4 deletions examples/shell/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
CONFIG_DK_LIBRARY=y

# Configure CHIP shell
CONFIG_CHIP_STANDALONE_SHELL=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_SHELL=n
CONFIG_CHIP_LIB_SHELL=y
CONFIG_OPENTHREAD_SHELL=n

# Some shell commands require OpenThread FTD configuration
Expand Down
2 changes: 2 additions & 0 deletions src/lib/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static_library("shell") {
"MainLoopDefault.cpp",
"streamer_k32w.cpp",
]
} else if (current_os == "zephyr") {
sources += [ "MainLoopZephyr.cpp" ]
} else {
sources += [ "MainLoopDefault.cpp" ]
}
Expand Down
Loading

0 comments on commit 2f0c691

Please sign in to comment.