Skip to content

Commit 9add5a1

Browse files
Damian-Nordicrlubos
authored andcommitted
logging: rpc: add RPC command to stop log history transfer
Add the support for pausing or cancelling the ongoing log history transfer. Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
1 parent 889f929 commit 9add5a1

File tree

5 files changed

+96
-36
lines changed

5 files changed

+96
-36
lines changed

include/logging/log_rpc.h

+17-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef LOG_RPC_H_
88
#define LOG_RPC_H_
99

10+
#include <stdbool.h>
1011
#include <stddef.h>
1112
#include <stdint.h>
1213

@@ -62,12 +63,9 @@ typedef void (*log_rpc_history_threshold_reached_handler_t)(void);
6263
* This function issues an nRF RPC command that configures the remote device to
6364
* stream log messages whose level is less than or equal to the specified level.
6465
*
65-
* @param level Logging level, see @ref log_rpc_level.
66-
*
67-
* @retval 0 On success.
68-
* @retval -errno On failure.
66+
* @param level Logging level, see @ref log_rpc_level.
6967
*/
70-
int log_rpc_set_stream_level(enum log_rpc_level level);
68+
void log_rpc_set_stream_level(enum log_rpc_level level);
7169

7270
/**
7371
* @brief Sets the log history verbosity level.
@@ -79,12 +77,9 @@ int log_rpc_set_stream_level(enum log_rpc_level level);
7977
* This function issues an nRF RPC command that configures the remote device to
8078
* save log messages whose level is less than or equal to the specified level.
8179
*
82-
* @param level Logging level, see @ref log_rpc_level.
83-
*
84-
* @retval 0 On success.
85-
* @retval -errno On failure.
80+
* @param level Logging level, see @ref log_rpc_level.
8681
*/
87-
int log_rpc_set_history_level(enum log_rpc_level level);
82+
void log_rpc_set_history_level(enum log_rpc_level level);
8883

8984
/**
9085
* @brief Gets the current history usage threshold.
@@ -135,6 +130,18 @@ void log_rpc_set_history_usage_threshold(log_rpc_history_threshold_reached_handl
135130
*/
136131
int log_rpc_fetch_history(log_rpc_history_handler_t handler);
137132

133+
/**
134+
* @brief Stops the log history transfer.
135+
*
136+
* This function issues an nRF RPC command that stops the log history transfer.
137+
*
138+
* @param pause Indicates that the transfer should be put on hold rather
139+
* than cancelled, which means that the history overwriting
140+
* is kept disabled and the transfer position is retained
141+
* so that the transfer can be resumed later on.
142+
*/
143+
void log_rpc_stop_fetch_history(bool pause);
144+
138145
/**
139146
* @brief Retrieves the crash log retained on the remote device.
140147
*

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

+30-20
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ static int cmd_log_rpc_stream_level(const struct shell *sh, size_t argc, char *a
1818

1919
level = (enum log_rpc_level)shell_strtol(argv[1], 10, &rc);
2020

21-
if (rc) {
21+
if (rc || level < LOG_RPC_LEVEL_NONE || level > LOG_RPC_LEVEL_DBG) {
2222
shell_error(sh, "Invalid argument: %d", rc);
2323
return -EINVAL;
2424
}
2525

26-
rc = log_rpc_set_stream_level(level);
27-
28-
if (rc) {
29-
shell_error(sh, "Error: %d", rc);
30-
return -ENOEXEC;
31-
}
26+
log_rpc_set_stream_level(level);
3227

3328
return 0;
3429
}
@@ -40,17 +35,12 @@ static int cmd_log_rpc_history_level(const struct shell *sh, size_t argc, char *
4035

4136
level = (enum log_rpc_level)shell_strtol(argv[1], 10, &rc);
4237

43-
if (rc) {
38+
if (rc || level < LOG_RPC_LEVEL_NONE || level > LOG_RPC_LEVEL_DBG) {
4439
shell_error(sh, "Invalid argument: %d", rc);
4540
return -EINVAL;
4641
}
4742

48-
rc = log_rpc_set_history_level(level);
49-
50-
if (rc) {
51-
shell_error(sh, "Error: %d", rc);
52-
return -ENOEXEC;
53-
}
43+
log_rpc_set_history_level(level);
5444

5545
return 0;
5646
}
@@ -99,6 +89,23 @@ static int cmd_log_rpc_history_fetch(const struct shell *sh, size_t argc, char *
9989
return 0;
10090
}
10191

92+
static int cmd_log_rpc_history_stop_fetch(const struct shell *sh, size_t argc, char *argv[])
93+
{
94+
int rc = 0;
95+
bool pause;
96+
97+
pause = shell_strtobool(argv[1], 0, &rc);
98+
99+
if (rc) {
100+
shell_error(sh, "Invalid argument: %d", rc);
101+
return -EINVAL;
102+
}
103+
104+
log_rpc_stop_fetch_history(pause);
105+
106+
return 0;
107+
}
108+
102109
static void history_threshold_reached_handler(void)
103110
{
104111
shell_print(shell, "History usage threshold reached");
@@ -177,15 +184,18 @@ static int cmd_log_rpc_echo(const struct shell *sh, size_t argc, char *argv[])
177184

178185
SHELL_STATIC_SUBCMD_SET_CREATE(
179186
log_rpc_cmds,
180-
SHELL_CMD_ARG(stream_level, NULL, "Set log streaming level", cmd_log_rpc_stream_level, 2,
181-
0),
182-
SHELL_CMD_ARG(history_level, NULL, "Set log history level", cmd_log_rpc_history_level, 2,
183-
0),
187+
SHELL_CMD_ARG(stream_level, NULL, "Set log streaming level <0-4>", cmd_log_rpc_stream_level,
188+
2, 0),
189+
SHELL_CMD_ARG(history_level, NULL, "Set log history level <0-4>", cmd_log_rpc_history_level,
190+
2, 0),
184191
SHELL_CMD_ARG(history_fetch, NULL, "Fetch log history", cmd_log_rpc_history_fetch, 1, 0),
185-
SHELL_CMD_ARG(history_threshold, NULL, "Get or set history usage threshold",
192+
SHELL_CMD_ARG(history_stop_fetch, NULL, "Stop log history transfer <pause?>",
193+
cmd_log_rpc_history_stop_fetch, 2, 0),
194+
SHELL_CMD_ARG(history_threshold, NULL, "Get or set history usage threshold [0-100]",
186195
cmd_log_rpc_history_threshold, 1, 1),
187196
SHELL_CMD_ARG(crash, NULL, "Retrieve remote device crash log", cmd_log_rpc_crash, 1, 0),
188-
SHELL_CMD_ARG(echo, NULL, "Generate log message on remote", cmd_log_rpc_echo, 3, 0),
197+
SHELL_CMD_ARG(echo, NULL, "Generate log message on remote <0-4> <msg>", cmd_log_rpc_echo, 3,
198+
0),
189199
SHELL_SUBCMD_SET_END);
190200

191201
SHELL_CMD_ARG_REGISTER(log_rpc, &log_rpc_cmds, "RPC logging commands", NULL, 1, 0);

subsys/logging/log_backend_rpc.c

+32
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ static void history_transfer_task(struct k_work *work)
488488
NRF_RPC_CBOR_ALLOC(&log_rpc_group, ctx, CONFIG_LOG_BACKEND_RPC_HISTORY_UPLOAD_CHUNK_SIZE);
489489

490490
k_mutex_lock(&history_transfer_mtx, K_FOREVER);
491+
492+
if (history_transfer_id == 0) {
493+
/* History transfer has been stopped */
494+
k_mutex_unlock(&history_transfer_mtx);
495+
return;
496+
}
497+
491498
nrf_rpc_encode_uint(&ctx, history_transfer_id);
492499

493500
while (true) {
@@ -564,6 +571,31 @@ static void log_rpc_fetch_history_handler(const struct nrf_rpc_group *group,
564571
NRF_RPC_CBOR_CMD_DECODER(log_rpc_group, log_rpc_fetch_history_handler, LOG_RPC_CMD_FETCH_HISTORY,
565572
log_rpc_fetch_history_handler, NULL);
566573

574+
static void log_rpc_stop_fetch_history_handler(const struct nrf_rpc_group *group,
575+
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
576+
{
577+
bool pause;
578+
579+
pause = nrf_rpc_decode_bool(ctx);
580+
581+
if (!nrf_rpc_decoding_done_and_check(group, ctx)) {
582+
nrf_rpc_err(-EBADMSG, NRF_RPC_ERR_SRC_RECV, group, LOG_RPC_CMD_STOP_FETCH_HISTORY,
583+
NRF_RPC_PACKET_TYPE_CMD);
584+
return;
585+
}
586+
587+
k_mutex_lock(&history_transfer_mtx, K_FOREVER);
588+
history_transfer_id = 0;
589+
log_rpc_history_set_overwriting(!pause);
590+
history_threshold_active = history_threshold > 0;
591+
k_mutex_unlock(&history_transfer_mtx);
592+
593+
nrf_rpc_rsp_send_void(group);
594+
}
595+
596+
NRF_RPC_CBOR_CMD_DECODER(log_rpc_group, log_rpc_stop_fetch_history_handler,
597+
LOG_RPC_CMD_STOP_FETCH_HISTORY, log_rpc_stop_fetch_history_handler, NULL);
598+
567599
static void log_rpc_get_history_usage_threshold_handler(const struct nrf_rpc_group *group,
568600
struct nrf_rpc_cbor_ctx *ctx,
569601
void *handler_data)

subsys/logging/log_forwarder_rpc.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,24 @@ static void log_rpc_msg_handler(const struct nrf_rpc_group *group, struct nrf_rp
6666
NRF_RPC_CBOR_EVT_DECODER(log_rpc_group, log_rpc_msg_handler, LOG_RPC_EVT_MSG, log_rpc_msg_handler,
6767
NULL);
6868

69-
int log_rpc_set_stream_level(enum log_rpc_level level)
69+
void log_rpc_set_stream_level(enum log_rpc_level level)
7070
{
7171
struct nrf_rpc_cbor_ctx ctx;
7272

7373
NRF_RPC_CBOR_ALLOC(&log_rpc_group, ctx, 1 + sizeof(level));
7474
nrf_rpc_encode_uint(&ctx, level);
7575
nrf_rpc_cbor_cmd_no_err(&log_rpc_group, LOG_RPC_CMD_SET_STREAM_LEVEL, &ctx,
7676
nrf_rpc_rsp_decode_void, NULL);
77-
78-
return 0;
7977
}
8078

81-
int log_rpc_set_history_level(enum log_rpc_level level)
79+
void log_rpc_set_history_level(enum log_rpc_level level)
8280
{
8381
struct nrf_rpc_cbor_ctx ctx;
8482

8583
NRF_RPC_CBOR_ALLOC(&log_rpc_group, ctx, 1 + sizeof(level));
8684
nrf_rpc_encode_uint(&ctx, level);
8785
nrf_rpc_cbor_cmd_no_err(&log_rpc_group, LOG_RPC_CMD_SET_HISTORY_LEVEL, &ctx,
8886
nrf_rpc_rsp_decode_void, NULL);
89-
90-
return 0;
9187
}
9288

9389
int log_rpc_fetch_history(log_rpc_history_handler_t handler)
@@ -108,6 +104,20 @@ int log_rpc_fetch_history(log_rpc_history_handler_t handler)
108104
return 0;
109105
}
110106

107+
void log_rpc_stop_fetch_history(bool pause)
108+
{
109+
struct nrf_rpc_cbor_ctx ctx;
110+
111+
k_mutex_lock(&history_transfer_mtx, K_FOREVER);
112+
history_handler = NULL;
113+
k_mutex_unlock(&history_transfer_mtx);
114+
115+
NRF_RPC_CBOR_ALLOC(&log_rpc_group, ctx, 1);
116+
nrf_rpc_encode_bool(&ctx, pause);
117+
nrf_rpc_cbor_cmd_no_err(&log_rpc_group, LOG_RPC_CMD_STOP_FETCH_HISTORY, &ctx,
118+
nrf_rpc_rsp_decode_void, NULL);
119+
}
120+
111121
static void log_rpc_put_history_chunk_handler(const struct nrf_rpc_group *group,
112122
struct nrf_rpc_cbor_ctx *ctx, void *handler_data)
113123
{

subsys/logging/log_rpc_group.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ enum log_rpc_cmd_backend {
4242
LOG_RPC_CMD_GET_HISTORY_USAGE_THRESHOLD,
4343
LOG_RPC_CMD_SET_HISTORY_USAGE_THRESHOLD,
4444
LOG_RPC_CMD_FETCH_HISTORY,
45+
LOG_RPC_CMD_STOP_FETCH_HISTORY,
4546
LOG_RPC_CMD_GET_CRASH_LOG,
4647
LOG_RPC_CMD_ECHO,
4748
};

0 commit comments

Comments
 (0)