Skip to content

Commit e0f649d

Browse files
Damian-Nordicnordicjm
authored andcommitted
samples: nrf_rpc: ps_client: add throughput service
Make it possible to run BLE throughput tests using the BLE over RPC architecture. 1. Clean BLE configuration of protocols serialization samples by removing unnecessary or default settings. Also, set the device name to "Nordic_PS". 2. Add BLE throughput service to the client sample. This requires enabline BT_SMP for both samples. 3. Add "bt_throughput advertise on" shell command, which is a replacement of "bt advertise on" that advertises the throughput service UUID. Signed-off-by: Damian Krolik <[email protected]>
1 parent 29eba36 commit e0f649d

File tree

4 files changed

+114
-15
lines changed

4 files changed

+114
-15
lines changed

samples/nrf_rpc/protocols_serialization/client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ zephyr_library_sources_ifdef(CONFIG_MPSL_CX_SOFTWARE src/coex_shell.c)
1919
zephyr_library_sources_ifdef(CONFIG_LOG_FORWARDER_RPC src/log_rpc_shell.c)
2020
zephyr_library_sources_ifdef(CONFIG_NFC_RPC src/nfc_shell.c)
2121
zephyr_library_sources_ifdef(CONFIG_NRF_RPC_DEV_INFO src/dev_info_shell.c)
22+
zephyr_library_sources_ifdef(CONFIG_BT_THROUGHPUT src/bt_throughput_shell.c)
2223
# NORDIC SDK APP START

samples/nrf_rpc/protocols_serialization/client/snippets/ble/ble.conf

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2144
1010
CONFIG_BT=y
1111
CONFIG_BT_RPC_STACK=y
1212
CONFIG_BT_RPC_INITIALIZE_NRF_RPC=n
13-
1413
CONFIG_BT_PERIPHERAL=y
15-
CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
16-
CONFIG_BT_DEVICE_APPEARANCE=833
1714
CONFIG_BT_MAX_CONN=1
18-
CONFIG_BT_MAX_PAIRED=1
1915
CONFIG_BT_LL_SOFTDEVICE=n
2016
CONFIG_BT_SHELL=y
2117

18+
# Device name and appearance shall be the same as on the server side
19+
CONFIG_BT_DEVICE_NAME="Nordic_PS"
20+
2221
# Enable the NUS service
2322
CONFIG_BT_NUS=y
2423
CONFIG_BT_NUS_LOG_LEVEL_DBG=y
2524

26-
# Enable bonding
27-
CONFIG_BT_SETTINGS=y
25+
# Enable the Throughput service
26+
CONFIG_BT_THROUGHPUT=y
27+
CONFIG_BT_THROUGHPUT_LOG_LEVEL_DBG=y
28+
29+
# Enable SMP that is required by the Throughput service.
2830
CONFIG_SETTINGS=y
2931
CONFIG_FLASH=y
30-
CONFIG_FLASH_PAGE_LAYOUT=y
3132
CONFIG_FLASH_MAP=y
33+
CONFIG_BT_SETTINGS=y
34+
CONFIG_BT_SMP=y
3235

33-
# TODO check why this is needed when OT is turned on
36+
# Disable HCI-based entropy driver (unavailable for BT_RPC_STACK)
3437
CONFIG_ENTROPY_BT_HCI=n
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <bluetooth/services/throughput.h>
8+
9+
#include <zephyr/bluetooth/bluetooth.h>
10+
#include <zephyr/bluetooth/conn.h>
11+
#include <zephyr/shell/shell.h>
12+
#include <zephyr/sys/__assert.h>
13+
14+
static const struct bt_data ad[] = {
15+
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR),
16+
BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_THROUGHPUT_VAL),
17+
};
18+
19+
static const struct bt_data sd[] = {
20+
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
21+
};
22+
23+
static int advertise(void);
24+
25+
static void connected(struct bt_conn *conn, uint8_t hci_err)
26+
{
27+
int rc;
28+
29+
if (hci_err) {
30+
return;
31+
}
32+
33+
rc = bt_conn_set_security(conn, BT_SECURITY_L2);
34+
__ASSERT(rc == 0, "Failed to set BLE security level: %d", rc);
35+
}
36+
37+
static void disconnected(struct bt_conn *conn, uint8_t reason)
38+
{
39+
ARG_UNUSED(conn);
40+
ARG_UNUSED(reason);
41+
42+
advertise();
43+
}
44+
45+
static struct bt_conn_cb conn_cb = {
46+
.connected = connected,
47+
.disconnected = disconnected,
48+
};
49+
50+
static int advertise(void)
51+
{
52+
int rc;
53+
54+
(void)bt_conn_cb_register(&conn_cb);
55+
rc = bt_le_adv_start(BT_LE_ADV_CONN_FAST_2, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
56+
57+
if (rc) {
58+
(void)bt_conn_cb_unregister(&conn_cb);
59+
}
60+
61+
return rc;
62+
}
63+
64+
static int cmd_advertise(const struct shell *sh, size_t argc, char *argv[])
65+
{
66+
bool start;
67+
int rc;
68+
69+
if (!strcmp(argv[1], "on")) {
70+
start = true;
71+
} else if (!strcmp(argv[1], "off")) {
72+
start = false;
73+
} else {
74+
shell_error(sh, "Invalid argument: %s", argv[1]);
75+
return -EINVAL;
76+
}
77+
78+
if (start) {
79+
rc = advertise();
80+
} else {
81+
rc = bt_le_adv_stop();
82+
(void)bt_conn_cb_unregister(&conn_cb);
83+
}
84+
85+
if (rc < 0) {
86+
shell_error(sh, "Failed to %s advertising: %d", start ? "start" : "stop", rc);
87+
return -ENOEXEC;
88+
}
89+
90+
shell_print(sh, "Advertising %s", start ? "started" : "stopped");
91+
return 0;
92+
}
93+
94+
SHELL_STATIC_SUBCMD_SET_CREATE(bt_throughput_cmds,
95+
SHELL_CMD_ARG(advertise, NULL, "on|off", cmd_advertise, 2, 0),
96+
SHELL_SUBCMD_SET_END);
97+
98+
SHELL_CMD_ARG_REGISTER(bt_throughput, &bt_throughput_cmds, "BLE throughput commands", NULL, 2, 0);

samples/nrf_rpc/protocols_serialization/server/snippets/ble/ble.conf

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ CONFIG_BT_RPC_INITIALIZE_NRF_RPC=n
1212

1313
CONFIG_BT_PERIPHERAL=y
1414
CONFIG_BT_MAX_CONN=1
15-
CONFIG_BT_MAX_PAIRED=1
16-
CONFIG_BT_SMP=n
17-
CONFIG_BT_DEVICE_APPEARANCE=833
1815

19-
# BT Device name must be the same as on the client side
20-
CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
16+
# Device name and appearance shall be the same as on the client side
17+
CONFIG_BT_DEVICE_NAME="Nordic_PS"
2118
# Host side registers all GATT services using dynamic database
2219
CONFIG_BT_GATT_DYNAMIC_DB=y
2320

24-
# Enable bonding
21+
# Enable SMP that is required by the Throughput service.
2522
CONFIG_BT_SETTINGS=y
26-
CONFIG_FLASH_PAGE_LAYOUT=y
23+
CONFIG_BT_SMP=y
2724

2825
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
2926
CONFIG_HEAP_MEM_POOL_SIZE=4096

0 commit comments

Comments
 (0)