mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
Merge pull request #21862 from morigawa/pr/integrate-openthread-into-shell
sys/shell: add shell wrapper for openthread cli
This commit is contained in:
commit
f8a0c986ae
@ -20,6 +20,7 @@ BOARD_WHITELIST := \
|
||||
openmote-cc2538 \
|
||||
nrf52840dk \
|
||||
nrf52840-mdk \
|
||||
adafruit-feather-nrf52840-sense \
|
||||
reel \
|
||||
#
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ open source implementation of [Thread](https://threadgroup.org/) on RIOT.
|
||||
The [Command Line Interface](https://github.com/openthread/openthread/blob/master/examples/apps/cli/README.md) of
|
||||
OpenThread was ported. Please check the
|
||||
[full documentation](https://github.com/openthread/openthread/blob/master/src/cli/README.md)
|
||||
of the CLI for usage information.
|
||||
of the CLI for usage information. Commands start with prefix 'ot'.
|
||||
|
||||
You can either build a FTD or MTD firmware:
|
||||
- MTD: A Minimal Thread Device does not have router functionality compiled in.
|
||||
@ -40,13 +40,13 @@ make BOARD=<target> clean all flash OPENTHREAD_TYPE=mtd
|
||||
make BOARD=<target> clean all flash OPENTHREAD_TYPE=ftd
|
||||
```
|
||||
|
||||
2. Check the state of the node with `state`. In the beginning, it should be
|
||||
2. Check the state of the node with `ot state`. In the beginning, it should be
|
||||
`detached`, but after some seconds it should become `leader`
|
||||
|
||||
3. Start another node and check that it becomes `router`. There is only one
|
||||
leader in a Thread network.
|
||||
|
||||
4. Get the mesh IP address of a node with `ipaddr`.
|
||||
4. Get the mesh IP address of a node with `ot ipaddr`.
|
||||
```
|
||||
ipaddr
|
||||
fdde:ad00:beef::ff:fe00:8000
|
||||
@ -59,9 +59,9 @@ ipaddr
|
||||
ping fdde:ad00:beef:0:946a:c722:a5d9:848
|
||||
```
|
||||
|
||||
6. You can try IEEE802.15.4 scan with `scan` command
|
||||
6. You can try IEEE802.15.4 scan with `ot scan` command
|
||||
|
||||
7. You can also check other commands with `help`
|
||||
7. You can also check other commands with `ot help`
|
||||
|
||||
|
||||
## OpenThread port on RIOT status
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#include "ot.h"
|
||||
#include "openthread/thread.h"
|
||||
|
||||
@ -45,5 +47,8 @@ int main(void)
|
||||
*/
|
||||
event_post(openthread_get_evq(), &event_panid);
|
||||
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -429,6 +429,7 @@ PSEUDOMODULES += shell_cmd_nice
|
||||
PSEUDOMODULES += shell_cmd_nimble_netif
|
||||
PSEUDOMODULES += shell_cmd_nimble_statconn
|
||||
PSEUDOMODULES += shell_cmd_opendsme
|
||||
PSEUDOMODULES += shell_cmd_openthread
|
||||
PSEUDOMODULES += shell_cmd_openwsn
|
||||
PSEUDOMODULES += shell_cmd_pm
|
||||
PSEUDOMODULES += shell_cmd_ps
|
||||
|
||||
@ -81,5 +81,6 @@ $(PKG_BUILD_DIR)/Makefile:
|
||||
-DOT_PLATFORM=NO \
|
||||
-DOT_CONFIG="$(RIOTBASE)/pkg/openthread/include/platform_config.h" \
|
||||
-DOT_APP_CLI=$(OT_APP_CLI) \
|
||||
-DOT_CLI_TRANSPORT=CONSOLE \
|
||||
-DOT_JOINER=$(OT_JOINER) \
|
||||
-DOT_COAP=$(OT_COAP)
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
USEMODULE += openthread_contrib
|
||||
|
||||
USEMODULE += netdev
|
||||
USEMODULE += openthread_contrib_netdev
|
||||
USEMODULE += event
|
||||
USEMODULE += l2util
|
||||
USEMODULE += netdev
|
||||
USEMODULE += openthread_contrib
|
||||
USEMODULE += openthread_contrib_netdev
|
||||
|
||||
ifneq (,$(filter openthread-cli-%,$(USEMODULE)))
|
||||
USEMODULE += shell_cmds_default
|
||||
endif
|
||||
|
||||
USEMODULE += ztimer
|
||||
USEMODULE += ztimer_msec
|
||||
USEMODULE += event
|
||||
|
||||
FEATURES_REQUIRED += cpp
|
||||
|
||||
@ -96,7 +96,7 @@ static void *_openthread_event_loop(void *arg)
|
||||
sInstance = otInstanceInitSingle();
|
||||
|
||||
#if defined(MODULE_OPENTHREAD_CLI_FTD) || defined(MODULE_OPENTHREAD_CLI_MTD)
|
||||
otCliUartInit(sInstance);
|
||||
ot_shell_init(sInstance);
|
||||
/* Init default parameters */
|
||||
otPanId panid = OPENTHREAD_PANID;
|
||||
uint8_t channel = OPENTHREAD_CHANNEL;
|
||||
|
||||
@ -163,6 +163,11 @@ int openthread_netdev_init(char *stack, int stacksize, char priority, const char
|
||||
*/
|
||||
void ot_random_init(void);
|
||||
|
||||
/**
|
||||
* @brief Init shell for OpenThread CLI
|
||||
*/
|
||||
void ot_shell_init(otInstance *aInstance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -93,6 +93,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
|
||||
ifneq (,$(filter opendsme,$(USEPKG)))
|
||||
USEMODULE += shell_cmd_opendsme
|
||||
endif
|
||||
ifneq (,$(filter openthread-cli-%,$(USEMODULE)))
|
||||
USEMODULE += shell_cmd_openthread
|
||||
endif
|
||||
ifneq (,$(filter openwsn,$(USEPKG)))
|
||||
USEMODULE += shell_cmd_openwsn
|
||||
endif
|
||||
|
||||
55
sys/shell/cmds/openthread.c
Normal file
55
sys/shell/cmds/openthread.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 TU Dresden
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_shell_commands
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Shell command implementation for OpenThread
|
||||
*
|
||||
* @author Moritz Voigt <moritz.voigt@mailbox.tu-dresden.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "shell.h"
|
||||
#include "openthread/cli.h"
|
||||
|
||||
static int ot_console_cb(const char *abuf, uint16_t bufsize, void *context)
|
||||
{
|
||||
(void) context;
|
||||
if (bufsize > 0) {
|
||||
printf("%.*s", bufsize, abuf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ot_cmd(int argc, char **argv)
|
||||
{
|
||||
/* Join all arguments after "ot" into a single space-separated string */
|
||||
for (int i = 1; i < argc - 1; i++) {
|
||||
char *arg = argv[i];
|
||||
arg += strlen(arg);
|
||||
*arg = ' ';
|
||||
}
|
||||
|
||||
if (strlen(argv[1]) != 0) {
|
||||
otCliConsoleInputLine(argv[1], strlen(argv[1]));
|
||||
}
|
||||
else {
|
||||
otCliConsoleInputLine("help", strlen("help"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_COMMAND(ot, "Use commands from OpenThread CLI", ot_cmd);
|
||||
|
||||
void ot_shell_init(otInstance *aInstance)
|
||||
{
|
||||
otCliConsoleInit(aInstance, ot_console_cb, NULL);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user