Skip to content

Commit

Permalink
btshell: Add support for read multi variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rymanluk authored and KKopyscinski committed Jul 17, 2023
1 parent d4c9b51 commit 9cc5083
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
10 changes: 5 additions & 5 deletions apps/btshell/src/btshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,22 @@ int btshell_exchange_mtu(uint16_t conn_handle);
int btshell_disc_svcs(uint16_t conn_handle);
int btshell_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid);
int btshell_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle);
uint16_t end_handle);
int btshell_disc_all_chrs_in_svc(uint16_t conn_handle, struct btshell_svc *svc);
int btshell_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle, const ble_uuid_t *uuid);
uint16_t end_handle, const ble_uuid_t *uuid);
int btshell_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle);
int btshell_disc_full(uint16_t conn_handle);
int btshell_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle);
uint16_t end_handle);
int btshell_read(uint16_t conn_handle, uint16_t attr_handle);
int btshell_read_long(uint16_t conn_handle, uint16_t attr_handle,
uint16_t offset);
int btshell_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
uint16_t end_handle, const ble_uuid_t *uuid);
uint16_t end_handle, const ble_uuid_t *uuid);
int btshell_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
int num_attr_handles);
int num_attr_handles, bool variable);
int btshell_write(uint16_t conn_handle, uint16_t attr_handle,
struct os_mbuf *om);
int btshell_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
Expand Down
1 change: 1 addition & 0 deletions apps/btshell/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,7 @@ static const struct shell_param gatt_read_params[] = {
{"uuid", "read by uuid, usage: =[UUID]"},
{"start", "start handle, usage: =<UINT16>"},
{"end", "end handle, usage: =<UINT16>"},
{"variable", "used in case of multi read, usage: =[0-1], default=0"},
{NULL, NULL}
};

Expand Down
9 changes: 8 additions & 1 deletion apps/btshell/src/cmd_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ cmd_gatt_read(int argc, char **argv)
uint8_t num_attr_handles;
int is_uuid;
int is_long;
bool is_var;
int rc;

rc = parse_arg_all(argc - 1, argv + 1);
Expand All @@ -259,6 +260,12 @@ cmd_gatt_read(int argc, char **argv)
return rc;
}

is_var = parse_arg_bool_dflt("variable", 0, &rc);
if (rc != 0) {
console_printf("invalid 'variable' parameter\n");
return rc;
}

for (num_attr_handles = 0;
num_attr_handles < CMD_READ_MAX_ATTRS;
num_attr_handles++) {
Expand Down Expand Up @@ -313,7 +320,7 @@ cmd_gatt_read(int argc, char **argv)
rc = btshell_read(conn_handle, attr_handles[0]);
}
} else if (num_attr_handles > 1) {
rc = btshell_read_mult(conn_handle, attr_handles, num_attr_handles);
rc = btshell_read_mult(conn_handle, attr_handles, num_attr_handles, is_var);
} else if (is_uuid) {
if (start == 0 || end == 0) {
rc = EINVAL;
Expand Down
43 changes: 38 additions & 5 deletions apps/btshell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,35 @@ btshell_on_disc_d(uint16_t conn_handle, const struct ble_gatt_error *error,

return 0;
}
static int
btshell_on_read_var(uint16_t conn_handle, const struct ble_gatt_error *error,
struct ble_gatt_attr *attr, uint8_t num_attrs, void *arg)
{
int i;

switch (error->status) {
case 0:
console_printf("characteristic read; conn_handle=%d , number of attributes=%d\n", conn_handle, num_attrs);

for (i = 0; i < num_attrs; i++) {
console_printf("\t attr_handle=%d, len=%d value=",
attr[i].handle, OS_MBUF_PKTLEN(attr[i].om));
print_mbuf(attr[i].om);
console_printf("\n");
}
break;

case BLE_HS_EDONE:
console_printf("characteristic read complete\n");
break;

default:
btshell_print_error(NULL, conn_handle, error);
break;
}

return 0;
}

static int
btshell_on_read(uint16_t conn_handle, const struct ble_gatt_error *error,
Expand Down Expand Up @@ -1670,13 +1699,17 @@ btshell_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,

int
btshell_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
int num_attr_handles)
int num_attr_handles, bool variable)
{
int rc;
if (variable) {
return ble_gattc_read_mult_var(conn_handle, attr_handles, num_attr_handles,
btshell_on_read_var, NULL);
}

return ble_gattc_read_mult(conn_handle, attr_handles,
num_attr_handles,
btshell_on_read, NULL);

rc = ble_gattc_read_mult(conn_handle, attr_handles, num_attr_handles,
btshell_on_read, NULL);
return rc;
}

int
Expand Down

0 comments on commit 9cc5083

Please sign in to comment.