You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/22 04:54:12 UTC
[4/4] incubator-mynewt-larva git commit: bleshell - set advertisement
data.
bleshell - set advertisement data.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/9bbdfc58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/9bbdfc58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/9bbdfc58
Branch: refs/heads/master
Commit: 9bbdfc582d7d2077567cbf3aed26562a2c215c92
Parents: 20097b7
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 21 19:53:27 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 21 19:53:27 2016 -0800
----------------------------------------------------------------------
project/bleshell/src/bleshell_priv.h | 2 +
project/bleshell/src/cmd.c | 70 ++++++++++++++++++++++++++++++-
project/bleshell/src/main.c | 11 ++++-
3 files changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index 977bf29..3cd944e 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -6,6 +6,7 @@
#include "host/ble_gatt.h"
struct ble_gap_white_entry;
+struct ble_hs_adv_fields;
#define BLESHELL_MAX_CONNS 8
@@ -109,5 +110,6 @@ int bleshell_wl_set(struct ble_gap_white_entry *white_list,
int white_list_count);
int bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
uint8_t filter_policy);
+int bleshell_set_adv_data(struct ble_hs_adv_fields *adv_fields);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index 569e2fc..0b8b374 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -664,6 +664,68 @@ cmd_show(int argc, char **argv)
* $set *
*****************************************************************************/
+#define CMD_ADV_DATA_MAX_UUIDS16 8
+//#define CMD_ADV_DATA_MAX_UUIDS128 8
+
+static int
+cmd_set_adv_data(void)
+{
+ static uint16_t uuids16[8];
+ //static uint8_t uuids128[8][16];
+ struct ble_hs_adv_fields adv_fields;
+ uint16_t uuid16;
+ int tmp;
+ int rc;
+
+ memset(&adv_fields, 0, sizeof adv_fields);
+
+ while (1) {
+ uuid16 = parse_arg_uint16("uuid16", &rc);
+ if (rc == 0) {
+ if (adv_fields.num_uuids16 >= CMD_ADV_DATA_MAX_UUIDS16) {
+ return EINVAL;
+ }
+ uuids16[adv_fields.num_uuids16] = uuid16;
+ adv_fields.num_uuids16++;
+ } else if (rc == ENOENT) {
+ break;
+ } else {
+ return rc;
+ }
+ }
+ if (adv_fields.num_uuids16 > 0) {
+ adv_fields.uuids16 = uuids16;
+ }
+
+ tmp = parse_arg_long("uuids16_is_complete", &rc);
+ if (rc == 0) {
+ adv_fields.uuids16_is_complete = !!tmp;
+ } else if (rc != ENOENT) {
+ return rc;
+ }
+
+ adv_fields.name = (uint8_t *)parse_arg_find("name");
+ if (adv_fields.name != NULL) {
+ adv_fields.name_len = strlen((char *)adv_fields.name);
+ }
+
+ tmp = parse_arg_long_bounds("le_role", 0, 0xff, &rc);
+ if (rc == 0) {
+ adv_fields.le_role = tmp;
+ adv_fields.le_role_is_present = 1;
+ } else if (rc != ENOENT) {
+ return rc;
+ }
+
+ rc = bleshell_set_adv_data(&adv_fields);
+ if (rc != 0) {
+ console_printf("error setting advertisement data; rc=%d\n", rc);
+ return rc;
+ }
+
+ return 0;
+}
+
static int
cmd_set(int argc, char **argv)
{
@@ -672,6 +734,11 @@ cmd_set(int argc, char **argv)
int good;
int rc;
+ if (argc > 1 && strcmp(argv[1], "adv_data") == 0) {
+ rc = cmd_set_adv_data();
+ return rc;
+ }
+
good = 0;
rc = parse_arg_mac("addr", addr);
@@ -688,8 +755,7 @@ cmd_set(int argc, char **argv)
if (rc == 0) {
good = 1;
}
- }
- if (rc != ENOENT) {
+ } else if (rc != ENOENT) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/9bbdfc58/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index ad2a08a..b5160a7 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -913,7 +913,16 @@ bleshell_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
int rc;
rc = ble_gap_conn_disc(dur_ms, disc_mode, scan_type, filter_policy,
- bleshell_on_disc, NULL);
+ bleshell_on_scan, NULL);
+ return rc;
+}
+
+int
+bleshell_set_adv_data(struct ble_hs_adv_fields *adv_fields)
+{
+ int rc;
+
+ rc = ble_gap_conn_set_adv_fields(adv_fields);
return rc;
}