Skip to content

Commit 4c80bb5

Browse files
Vudentznashif
authored andcommitted
Bluetooth: Shell: Add GATT command get
This introduces get command to GATT which can be used to read the local attributes: uart:~$ gatt get 0x000b attr 0x004235a8 uuid 2a00 perm 0x09 00000000: 74 65 73 74 20 73 68 65 6C 6C Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 090f95d commit 4c80bb5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

subsys/bluetooth/shell/gatt.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,41 @@ static int cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
834834
return err;
835835
}
836836

837+
static u8_t get_cb(const struct bt_gatt_attr *attr, void *user_data)
838+
{
839+
struct shell *shell = user_data;
840+
u8_t buf[256];
841+
ssize_t ret;
842+
843+
shell_print(shell, "attr %p uuid %s perm 0x%02x", attr,
844+
bt_uuid_str(attr->uuid), attr->perm);
845+
846+
if (!attr->read) {
847+
return BT_GATT_ITER_CONTINUE;
848+
}
849+
850+
ret = attr->read(NULL, attr, (void *)buf, sizeof(buf), 0);
851+
if (ret < 0) {
852+
shell_print(shell, "Failed to read: %d", ret);
853+
return BT_GATT_ITER_STOP;
854+
}
855+
856+
shell_hexdump(shell, buf, ret);
857+
858+
return BT_GATT_ITER_CONTINUE;
859+
}
860+
861+
static int cmd_get(const struct shell *shell, size_t argc, char *argv[])
862+
{
863+
u16_t handle;
864+
865+
handle = strtoul(argv[1], NULL, 16);
866+
867+
bt_gatt_foreach_attr(handle, handle, get_cb, (void *)shell);
868+
869+
return 0;
870+
}
871+
837872
#define HELP_NONE "[none]"
838873

839874
SHELL_STATIC_SUBCMD_SET_CREATE(gatt_cmds,
@@ -876,6 +911,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(gatt_cmds,
876911
SHELL_CMD_ARG(unregister, NULL,
877912
"unregister pre-predefined test service",
878913
cmd_unregister_test_svc, 1, 0),
914+
SHELL_CMD_ARG(get, NULL, "<handle>", cmd_get, 2, 0),
879915
SHELL_SUBCMD_SET_END
880916
);
881917

0 commit comments

Comments
 (0)