Skip to content

Commit

Permalink
[nrfconnect] Added CHIP Zephyr shell for testing purposes.
Browse files Browse the repository at this point in the history
* Added option enabling using Zephyr based CHIP shell in examples.
* Implemented ChipShell module allowing to call chip test commands
to get information about CHIP stack state.
* Extended nrfconnect CLI docs about CHIP commands.
* Renamed src/lib/shell/shell.h and .cpp files to shell_core due
to name conflicts with Zephyr shell/shell.h.
* Added to OnboardingCodesUtil method allowing to get encoded
QR code url.
  • Loading branch information
kkasperczyk-no committed Apr 15, 2021
1 parent f348eb4 commit 2175232
Show file tree
Hide file tree
Showing 25 changed files with 440 additions and 65 deletions.
5 changes: 5 additions & 0 deletions config/nrfconnect/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ assert(current_os == "zephyr")
declare_args() {
chip_build_libshell = false
chip_build_pw_rpc_lib = false
chip_build_zephyr_shell = false
}

group("nrfconnect") {
Expand All @@ -35,6 +36,10 @@ group("nrfconnect") {
deps += [ "${chip_root}/src/lib/shell" ]
}

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
11 changes: 8 additions & 3 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ if (NOT CHIP_LIBRARIES)
set(CHIP_LIBRARIES -lCHIP)
endif()

if (CONFIG_CHIP_LIB_SHELL)
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 @@ -201,7 +205,8 @@ 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_LIB_SHELL)
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_pw_rpc_lib" CONFIG_CHIP_PW_RPC)

if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
Expand Down Expand Up @@ -264,7 +269,7 @@ target_include_directories(chip INTERFACE
${CMAKE_CURRENT_BINARY_DIR}/gen/third_party/connectedhomeip/src/app/include
)
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
target_link_libraries(chip INTERFACE -Wl,--whole-archive ${CHIP_ZEPHYR_SHELL_LIBRARY} -Wl,--no-whole-archive,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
add_dependencies(chip chip-gn)

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

config CHIP_LIB_SHELL
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
bool "Enable CHIP shell library"
default n
depends on !CHIP_ZEPHYR_SHELL
help
Link the application with the library containing CHIP shell commands.

Expand Down
105 changes: 105 additions & 0 deletions docs/guides/nrfconnect_examples_cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,108 @@ uart:~$ ot masterkey
00112233445566778899aabbccddeeff
Done
```

## Using CHIP-specific commands

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

These commands are not available in the standard Zephyr shell.

They are currently used for testing purposes and allow only to get some information about
CHIP stack state, but not to modify it.

To enable using CHIP commands, set the `CONFIG_CHIP_ZEPHYR_SHELL=y` Kconfig option in the `prj.conf` file of the given example.

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

```shell
uart:~$ chip
qrcode qrcodeurl setuppincode discriminator
vendorid productid manualpairingcode bleadvertising
nfcemulation
```

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

#### `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
CH:H34.GHY00 0C9SS0
```

#### `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
```

#### `setuppincode`

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

```shell
uart:~$ chip setuppincode
12345678
```

#### `discriminator`

Prints the device setup discriminator. Takes no arguments.

```shell
uart:~$ chip discriminator
3840
```

#### `vendorid`

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

```shell
uart:~$ chip vendorid
9050
```

#### `productid`

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

```shell
uart:~$ chip productid
20043
```

#### `manualpairingcode`

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

```shell
uart:~$ chip manualpairingcode
35767807533
```

#### `bleadvertising`

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.

```shell
uart:~$ chip bleadvertising
0
```

#### `nfcemulation`

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.

```shell
uart:~$ chip nfcemulation
0
```
2 changes: 1 addition & 1 deletion examples/shell/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
CONFIG_DK_LIBRARY=y

# Configure CHIP shell
CONFIG_CHIP_LIB_SHELL=y
CONFIG_CHIP_STANDALONE_SHELL=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
CONFIG_SHELL=n
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>

#include <lib/core/CHIPCore.h>
#include <lib/support/Base64.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_btp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <platform/CHIPDeviceLayer.h>
#endif

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>
#include <support/CHIPArgParser.hpp>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <inttypes.h>

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>

#include <lib/core/CHIPCore.h>
#include <lib/support/Base64.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_otcli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <stdio.h>

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/shell_common/cmd_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stdlib.h>

#include <lib/core/CHIPCore.h>
#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ErrorStr.h>
#include <messaging/ExchangeMgr.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/standalone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include <lib/shell/shell.h>
#include <lib/shell/shell_core.h>

#include <lib/core/CHIPCore.h>
#include <lib/support/Base64.h>
Expand Down
Loading

0 comments on commit 2175232

Please sign in to comment.