Commit f390f7d0 authored by Joakim Andersson's avatar Joakim Andersson Committed by Carles Cufi
Browse files

bluetooth: shell: Use helper function to convert string to int

Use helper function to convert string to int for appearance value.
This makes the code more clear, as the big-endian conversion function
gives the wrong impression about the byte order of advertising data.

Signed-off-by: default avatarJoakim Andersson <joakim.andersson@nordicsemi.no>
parent 352980be
Loading
Loading
Loading
Loading
+8 −4
Changes for subsys/bluetooth/shell/bt.c: 8 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -1196,17 +1196,21 @@ static int cmd_appearance(const struct shell *sh, size_t argc, char *argv[])

#if defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC)
	uint16_t app;
	int err;
	int err = 0;
	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))) {

	if (strlen(val) != 6 || strncmp(val, "0x", 2)) {
		shell_error(sh, "Argument must be 0x followed by exactly 4 hex digits.");
		return -EINVAL;
	}

	app = sys_be16_to_cpu(app);
	app = shell_strtoul(val, 16, &err);
	if (err) {
		shell_error(sh, "Argument must be 0x followed by exactly 4 hex digits.");
		return -EINVAL;
	}

	err = bt_set_appearance(app);
	if (err) {