You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ko...@apache.org on 2023/08/24 08:27:05 UTC
[mynewt-nimble] 05/16: btshell: Add support for read multi variable
This is an automated email from the ASF dual-hosted git repository.
kopyscinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit d5f1d55222724250c06ad55b78e5cf071fb4e283
Author: Ćukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Thu Mar 12 13:23:49 2020 +0100
btshell: Add support for read multi variable
---
apps/btshell/src/btshell.h | 10 +++++-----
apps/btshell/src/cmd.c | 1 +
apps/btshell/src/cmd_gatt.c | 9 ++++++++-
apps/btshell/src/main.c | 43 ++++++++++++++++++++++++++++++++++++++-----
4 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h
index 134eb016..021f54c8 100644
--- a/apps/btshell/src/btshell.h
+++ b/apps/btshell/src/btshell.h
@@ -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,
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 4148b8e8..22819219 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -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}
};
diff --git a/apps/btshell/src/cmd_gatt.c b/apps/btshell/src/cmd_gatt.c
index ba3799e5..4c57b42d 100644
--- a/apps/btshell/src/cmd_gatt.c
+++ b/apps/btshell/src/cmd_gatt.c
@@ -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);
@@ -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++) {
@@ -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;
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index 2df37191..4c4a6bb7 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -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,
@@ -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