bluetooth: shell: replace ctx_shell with sh where applicable

Limit the usage of `ctx_shell` to cases where printing requires it
and `sh` is not available.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit is contained in:
Pisit Sawangvonganan 2024-11-10 22:49:12 +07:00 committed by Benjamin Cabé
commit 471feb2094

View file

@ -1753,7 +1753,7 @@ static int cmd_scan_filter_set_name(const struct shell *sh, size_t argc,
const char *name_arg = argv[1];
if (strlen(name_arg) >= sizeof(scan_filter.name)) {
shell_error(ctx_shell, "Name is too long (max %zu): %s\n",
shell_error(sh, "Name is too long (max %zu): %s\n",
sizeof(scan_filter.name), name_arg);
return -ENOEXEC;
}
@ -1773,8 +1773,7 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc,
/* Validate length including null terminator. */
if (len > max_cpy_len) {
shell_error(ctx_shell, "Invalid address string: %s\n",
addr_arg);
shell_error(sh, "Invalid address string: %s\n", addr_arg);
return -ENOEXEC;
}
@ -1784,9 +1783,7 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc,
uint8_t tmp;
if (c != ':' && char2hex(c, &tmp) < 0) {
shell_error(ctx_shell,
"Invalid address string: %s\n",
addr_arg);
shell_error(sh, "Invalid address string: %s\n", addr_arg);
return -ENOEXEC;
}
}
@ -2499,7 +2496,7 @@ static int cmd_adv_delete(const struct shell *sh, size_t argc, char *argv[])
err = bt_le_ext_adv_delete(adv);
if (err) {
shell_error(ctx_shell, "Failed to delete advertiser set");
shell_error(sh, "Failed to delete advertiser set");
return err;
}
@ -3494,11 +3491,11 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
err = bt_conn_get_info(conn, &info);
if (err) {
shell_print(ctx_shell, "Failed to get info");
shell_print(sh, "Failed to get info");
goto done;
}
shell_print(ctx_shell, "Type: %s, Role: %s, Id: %u",
shell_print(sh, "Type: %s, Role: %s, Id: %u",
get_conn_type_str(info.type),
get_conn_role_str(info.role),
info.id);
@ -3509,20 +3506,20 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
print_le_addr("Remote on-air", info.le.remote);
print_le_addr("Local on-air", info.le.local);
shell_print(ctx_shell, "Interval: 0x%04x (%u us)",
shell_print(sh, "Interval: 0x%04x (%u us)",
info.le.interval,
BT_CONN_INTERVAL_TO_US(info.le.interval));
shell_print(ctx_shell, "Latency: 0x%04x",
shell_print(sh, "Latency: 0x%04x",
info.le.latency);
shell_print(ctx_shell, "Supervision timeout: 0x%04x (%d ms)",
shell_print(sh, "Supervision timeout: 0x%04x (%d ms)",
info.le.timeout, info.le.timeout * 10);
#if defined(CONFIG_BT_USER_PHY_UPDATE)
shell_print(ctx_shell, "LE PHY: TX PHY %s, RX PHY %s",
shell_print(sh, "LE PHY: TX PHY %s, RX PHY %s",
phy2str(info.le.phy->tx_phy),
phy2str(info.le.phy->rx_phy));
#endif
#if defined(CONFIG_BT_USER_DATA_LEN_UPDATE)
shell_print(ctx_shell, "LE data len: TX (len: %d time: %d)"
shell_print(sh, "LE data len: TX (len: %d time: %d)"
" RX (len: %d time: %d)",
info.le.data_len->tx_max_len,
info.le.data_len->tx_max_time,
@ -3530,7 +3527,7 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
info.le.data_len->rx_max_time);
#endif
#if defined(CONFIG_BT_SUBRATING)
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
shell_print(sh, "LE Subrating: Subrate Factor: %d"
" Continuation Number: %d",
info.le.subrate->factor,
info.le.subrate->continuation_number);
@ -3542,7 +3539,7 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
char addr_str[BT_ADDR_STR_LEN];
bt_addr_to_str(info.br.dst, addr_str, sizeof(addr_str));
shell_print(ctx_shell, "Peer address %s", addr_str);
shell_print(sh, "Peer address %s", addr_str);
}
#endif /* defined(CONFIG_BT_CLASSIC) */
@ -3633,8 +3630,6 @@ static int cmd_conn_data_len_update(const struct shell *sh, size_t argc,
shell_print(sh, "Calculated tx time: %d", param.tx_max_time);
}
err = bt_conn_le_data_len_update(default_conn, &param);
if (err) {
shell_error(sh, "data len update failed (err %d).", err);