Bluetooth: Shell: Add command "bt appearance [new appearance]"

Extend the command "bt appearance" to take an optional argument, which
is used to set the appearance.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
This commit is contained in:
Aleksander Wasaznik 2021-11-24 12:56:15 +01:00 committed by Carles Cufí
commit 3bdf582172

View file

@ -754,6 +754,27 @@ static int cmd_appearance(const struct shell *sh, size_t argc, char *argv[])
return 0;
}
#if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC)
uint16_t app;
int err;
const char *val;
val = argv[1];
if (strlen(val) != 6 || strncmp(val, "0x", 2) ||
!hex2bin(&val[2], strlen(&val[2]), ((uint8_t *)&app), sizeof(app))) {
shell_error(sh, "Argument must be 0x followed by exactly 4 hex digits.");
return -EINVAL;
}
app = sys_be16_to_cpu(app);
err = bt_set_appearance(app);
if (err) {
shell_error(sh, "bt_set_appearance(0x%04x) failed with err %d", app, err);
return err;
}
#endif /* defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC) */
return 0;
}
@ -3255,7 +3276,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
SHELL_CMD_ARG(id-show, NULL, HELP_NONE, cmd_id_show, 1, 0),
SHELL_CMD_ARG(id-select, NULL, "<id>", cmd_id_select, 2, 0),
SHELL_CMD_ARG(name, NULL, "[name]", cmd_name, 1, 1),
SHELL_CMD_ARG(appearance, NULL, HELP_NONE, cmd_appearance, 1, 0),
#if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC)
SHELL_CMD_ARG(appearance, NULL, "[new appearance value]", cmd_appearance, 1, 1),
#else
SHELL_CMD_ARG(appearance, NULL, "", cmd_appearance, 1, 0),
#endif /* CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC */
#if defined(CONFIG_BT_OBSERVER)
SHELL_CMD_ARG(scan, NULL,
"<value: on, passive, off> [filter: dups, nodups] [fal]"