Skip to content

Commit 6147ddf

Browse files
Damian-Nordicnordicjm
authored andcommitted
samples: nrf_rpc: ps: fix shell commands after server restart
When server restarts, clear the flag indicating that the CLI has already been initialized on the server, so that it is re-initialized before the next otCliInputLine(). Signed-off-by: Damian Krolik <[email protected]>
1 parent 1d0c321 commit 6147ddf

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

samples/nrf_rpc/protocols_serialization/client/src/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include "ot_shell.h"
8+
79
#include <zephyr/logging/log.h>
810

911
#include <nrf_rpc.h>
@@ -25,6 +27,7 @@ static void bound_handler(const struct nrf_rpc_group *group)
2527
if (group == &ot_group) {
2628
if (ot_group_initialized) {
2729
LOG_WRN("OT RPC peer reset detected");
30+
ot_shell_server_restarted();
2831
/* The code to restore the state of OT on the server can be added here */
2932
} else {
3033
ot_group_initialized = true;

samples/nrf_rpc/protocols_serialization/client/src/ot_shell.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include "ot_shell.h"
8+
79
#include <zephyr/shell/shell.h>
810
#include <zephyr/net/net_ip.h>
911

@@ -18,6 +20,7 @@
1820

1921
#include <string.h>
2022

23+
static bool ot_cli_is_initialized;
2124
static otUdpSocket udp_socket;
2225
static const char udp_payload[] = "Hello OpenThread World!";
2326
#define PORT 1212
@@ -33,14 +36,12 @@ static int ot_cli_output_cb(void *context, const char *format, va_list arg)
3336

3437
static void ot_cli_lazy_init(const struct shell *sh)
3538
{
36-
static bool is_initialized;
37-
38-
if (is_initialized) {
39+
if (ot_cli_is_initialized) {
3940
return;
4041
}
4142

4243
otCliInit(NULL, ot_cli_output_cb, (void *)sh);
43-
is_initialized = true;
44+
ot_cli_is_initialized = true;
4445
}
4546

4647
typedef otError(*ot_cli_command_handler_t)(const struct shell *, size_t argc, char *argv[]);
@@ -764,3 +765,8 @@ SHELL_CMD_ARG_REGISTER(ot, &ot_cmds,
764765
"OpenThread subcommands\n"
765766
"Use \"ot help\" to get the list of subcommands",
766767
cmd_ot, 2, 255);
768+
769+
void ot_shell_server_restarted(void)
770+
{
771+
ot_cli_is_initialized = false;
772+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef OT_SHELL_H_
8+
#define OT_SHELL_H_
9+
10+
void ot_shell_server_restarted(void);
11+
12+
#endif

0 commit comments

Comments
 (0)