bluetooth: shell: Add shell commands for LE Connection Subrating
Add commands to allow requesting a subrate change via the BT shell. A new build configuration has been added to ensure this is tested in CI. Signed-off-by: Aleksandar Stanoev <aleksandar.stanoev@nordicsemi.no>
This commit is contained in:
parent
db9bcdc05e
commit
52ffbd85c8
2 changed files with 115 additions and 0 deletions
|
@ -974,6 +974,27 @@ void path_loss_threshold_report(struct bt_conn *conn,
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_SUBRATING)
|
||||
void subrate_changed(struct bt_conn *conn,
|
||||
const struct bt_conn_le_subrate_changed *params)
|
||||
{
|
||||
if (params->status == BT_HCI_ERR_SUCCESS) {
|
||||
shell_print(ctx_shell, "Subrate parameters changed: "
|
||||
"Subrate Factor: %d "
|
||||
"Continuation Number: %d "
|
||||
"Peripheral latency: 0x%04x "
|
||||
"Supervision timeout: 0x%04x (%d ms)",
|
||||
params->factor,
|
||||
params->continuation_number,
|
||||
params->peripheral_latency,
|
||||
params->supervision_timeout,
|
||||
params->supervision_timeout * 10);
|
||||
} else {
|
||||
shell_print(ctx_shell, "Subrate change failed (HCI status 0x%02x)", params->status);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct bt_conn_cb conn_callbacks = {
|
||||
.connected = connected,
|
||||
.disconnected = disconnected,
|
||||
|
@ -1000,6 +1021,9 @@ static struct bt_conn_cb conn_callbacks = {
|
|||
#if defined(CONFIG_BT_PATH_LOSS_MONITORING)
|
||||
.path_loss_threshold_report = path_loss_threshold_report,
|
||||
#endif
|
||||
#if defined(CONFIG_BT_SUBRATING)
|
||||
.subrate_changed = subrate_changed,
|
||||
#endif
|
||||
};
|
||||
#endif /* CONFIG_BT_CONN */
|
||||
|
||||
|
@ -3019,6 +3043,74 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_SUBRATING)
|
||||
static int cmd_subrate_set_defaults(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
for (size_t argn = 1; argn < argc; argn++) {
|
||||
(void)shell_strtoul(argv[argn], 10, &err);
|
||||
|
||||
if (err) {
|
||||
shell_help(sh);
|
||||
shell_error(sh, "Could not parse input number %d", argn);
|
||||
return SHELL_CMD_HELP_PRINTED;
|
||||
}
|
||||
}
|
||||
|
||||
const struct bt_conn_le_subrate_param params = {
|
||||
.subrate_min = shell_strtoul(argv[1], 10, &err),
|
||||
.subrate_max = shell_strtoul(argv[2], 10, &err),
|
||||
.max_latency = shell_strtoul(argv[3], 10, &err),
|
||||
.continuation_number = shell_strtoul(argv[4], 10, &err),
|
||||
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
|
||||
};
|
||||
|
||||
err = bt_conn_le_subrate_set_defaults(¶ms);
|
||||
if (err) {
|
||||
shell_error(sh, "bt_conn_le_subrate_set_defaults returned error %d", err);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_subrate_request(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (default_conn == NULL) {
|
||||
shell_error(sh, "Conn handle error, at least one connection is required.");
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
for (size_t argn = 1; argn < argc; argn++) {
|
||||
(void)shell_strtoul(argv[argn], 10, &err);
|
||||
|
||||
if (err) {
|
||||
shell_help(sh);
|
||||
shell_error(sh, "Could not parse input number %d", argn);
|
||||
return SHELL_CMD_HELP_PRINTED;
|
||||
}
|
||||
}
|
||||
|
||||
const struct bt_conn_le_subrate_param params = {
|
||||
.subrate_min = shell_strtoul(argv[1], 10, &err),
|
||||
.subrate_max = shell_strtoul(argv[2], 10, &err),
|
||||
.max_latency = shell_strtoul(argv[3], 10, &err),
|
||||
.continuation_number = shell_strtoul(argv[4], 10, &err),
|
||||
.supervision_timeout = shell_strtoul(argv[5], 10, &err) * 100, /* 10ms units */
|
||||
};
|
||||
|
||||
err = bt_conn_le_subrate_request(default_conn, ¶ms);
|
||||
if (err) {
|
||||
shell_error(sh, "bt_conn_le_subrate_request returned error %d", err);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_CONN)
|
||||
#if defined(CONFIG_BT_CENTRAL)
|
||||
|
@ -3315,6 +3407,12 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
|
|||
info.le.data_len->tx_max_time,
|
||||
info.le.data_len->rx_max_len,
|
||||
info.le.data_len->rx_max_time);
|
||||
#endif
|
||||
#if defined(CONFIG_BT_SUBRATING)
|
||||
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
|
||||
" Continuation Number: %d",
|
||||
info.le.subrate->factor,
|
||||
info.le.subrate->continuation_number);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -4716,6 +4814,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
|
|||
SHELL_CMD_ARG(path-loss-monitoring-enable, NULL, "<enable: true, false>",
|
||||
cmd_set_path_loss_reporting_enable, 2, 0),
|
||||
#endif
|
||||
#if defined(CONFIG_BT_SUBRATING)
|
||||
SHELL_CMD_ARG(subrate-set-defaults, NULL,
|
||||
"<min subrate factor> <max subrate factor> <max peripheral latency> "
|
||||
"<min continuation number> <supervision timeout (seconds)>",
|
||||
cmd_subrate_set_defaults, 6, 0),
|
||||
SHELL_CMD_ARG(subrate-request, NULL,
|
||||
"<min subrate factor> <max subrate factor> <max peripheral latency> "
|
||||
"<min continuation number> <supervision timeout (seconds)>",
|
||||
cmd_subrate_request, 6, 0),
|
||||
#endif
|
||||
#if defined(CONFIG_BT_BROADCASTER)
|
||||
SHELL_CMD_ARG(advertise, NULL,
|
||||
"<type: off, on, nconn> [mode: discov, non_discov] "
|
||||
|
|
|
@ -29,6 +29,13 @@ tests:
|
|||
platform_allow:
|
||||
- native_posix
|
||||
build_only: true
|
||||
bluetooth.shell.subrating:
|
||||
extra_configs:
|
||||
- CONFIG_BT_SUBRATING=y
|
||||
- CONFIG_BT_CTLR=n
|
||||
platform_allow:
|
||||
- native_posix
|
||||
build_only: true
|
||||
bluetooth.shell.cdc_acm:
|
||||
extra_args:
|
||||
- OVERLAY_CONFIG=cdc_acm.conf
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue