Skip to content

Commit ddb957b

Browse files
committed
sys/shell: integrate OpenThread CLI into RIOT shell
Until now OpenThread CLI and RIOT shell could not be used at the same time. Now it is possible to use all CLI command with the prefix "ot". To get an overview use "ot help".
1 parent 0a25bdb commit ddb957b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

makefiles/pseudomodules.inc.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ PSEUDOMODULES += shell_cmd_nice
429429
PSEUDOMODULES += shell_cmd_nimble_netif
430430
PSEUDOMODULES += shell_cmd_nimble_statconn
431431
PSEUDOMODULES += shell_cmd_opendsme
432+
PSEUDOMODULES += shell_cmd_openthread
432433
PSEUDOMODULES += shell_cmd_openwsn
433434
PSEUDOMODULES += shell_cmd_pm
434435
PSEUDOMODULES += shell_cmd_ps

sys/shell/Makefile.dep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ ifneq (,$(filter shell_cmds_default,$(USEMODULE)))
9393
ifneq (,$(filter opendsme,$(USEPKG)))
9494
USEMODULE += shell_cmd_opendsme
9595
endif
96+
ifneq (,$(filter openthread-cli-%,$(USEMODULE)))
97+
USEMODULE += shell_cmd_openthread
98+
endif
9699
ifneq (,$(filter openwsn,$(USEPKG)))
97100
USEMODULE += shell_cmd_openwsn
98101
endif

sys/shell/cmds/openthread.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 TU Dresden
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
/**
7+
* @ingroup sys_shell_commands
8+
* @{
9+
*
10+
* @file
11+
* @brief Shell command implementation for OpenThread
12+
*
13+
* @author Moritz Voigt <[email protected]>
14+
*
15+
* @}
16+
*/
17+
#include <stdio.h>
18+
#include <string.h>
19+
20+
#include "shell.h"
21+
#include "openthread/cli.h"
22+
23+
static int ot_console_cb(const char *abuf, uint16_t bufsize, void *context)
24+
{
25+
(void) context;
26+
if (bufsize > 0)
27+
{
28+
printf("%.*s", bufsize, abuf);
29+
}
30+
return 0;
31+
}
32+
33+
static int ot_cmd(int argc, char **argv)
34+
{
35+
char command[SHELL_DEFAULT_BUFSIZE];
36+
for (int i = 1; i < argc; i++){
37+
if (i == 1)
38+
{
39+
strncpy(command, argv[i], SHELL_DEFAULT_BUFSIZE-1);
40+
}
41+
else
42+
{
43+
strncat(command, " ", SHELL_DEFAULT_BUFSIZE-strlen(command)-1);
44+
strncat(command, argv[i], SHELL_DEFAULT_BUFSIZE-strlen(command)-1);
45+
}
46+
}
47+
48+
if (strlen(command) != 0)
49+
{
50+
otCliConsoleInputLine(command, SHELL_DEFAULT_BUFSIZE);
51+
}
52+
return 0;
53+
}
54+
55+
SHELL_COMMAND(ot, "Use commands from OpenThread CLI", ot_cmd);
56+
57+
void ot_shell_init(otInstance *aInstance)
58+
{
59+
otCliConsoleInit(aInstance, ot_console_cb, NULL);
60+
}

0 commit comments

Comments
 (0)