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/07/25 20:19:43 UTC
[3/3] incubator-mynewt-core git commit: BLE sample apps - Use new
GATT registration.
BLE sample apps - Use new GATT registration.
Also add some additional comments to main().
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/dd1a3db4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/dd1a3db4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/dd1a3db4
Branch: refs/heads/develop
Commit: dd1a3db44300b31a527d15a739b85647c08bb23c
Parents: fb6b480
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 25 13:12:57 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 25 13:18:40 2016 -0700
----------------------------------------------------------------------
apps/blecent/src/main.c | 19 ++++++--------
apps/bleprph/src/bleprph.h | 3 ++-
apps/bleprph/src/gatt_svr.c | 16 +++++-------
apps/bleprph/src/main.c | 49 ++++++++++++++-----------------------
apps/bletiny/src/bletiny.h | 2 +-
apps/bletiny/src/gatt_svr.c | 2 +-
apps/bletiny/src/main.c | 53 ++++++++++++++++++++--------------------
7 files changed, 64 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index a385e4b..3cc0f24 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -540,13 +540,16 @@ main(void)
log_console_handler_init(&blecent_log_console_handler);
log_register("blecent", &blecent_log, &blecent_log_console_handler);
+ /* Initialize the eventq for the application task. */
+ os_eventq_init(&blecent_evq);
+
+ /* Create the blecent task. All application logic and NimBLE host
+ * operations are performed in this task.
+ */
os_task_init(&blecent_task, "blecent", blecent_task_handler,
NULL, BLECENT_TASK_PRIO, OS_WAIT_FOREVER,
blecent_stack, BLECENT_STACK_SIZE);
- /* Initialize the eventq for the application task. */
- os_eventq_init(&blecent_evq);
-
/* Initialize the BLE LL */
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
@@ -555,14 +558,13 @@ main(void)
cfg = ble_hs_cfg_dflt;
cfg.max_hci_bufs = 3;
cfg.max_gattc_procs = 5;
- cfg.max_l2cap_sig_procs = 1;
cfg.sm_bonding = 1;
cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
- /* Populate config with the required GATT server settings. */
+ /* Initialize GATT services. */
rc = ble_svc_gap_init(&cfg);
assert(rc == 0);
@@ -573,15 +575,10 @@ main(void)
rc = ble_hs_init(&blecent_evq, &cfg);
assert(rc == 0);
+ /* Initialize data structures to track connected peers. */
rc = peer_init(cfg.max_connections, 64, 64, 64);
assert(rc == 0);
- /* Register GATT attributes (services, characteristics, and
- * descriptors).
- */
- ble_svc_gap_register();
- ble_svc_gatt_register();
-
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-blecent");
assert(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bleprph/src/bleprph.h
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/bleprph.h b/apps/bleprph/src/bleprph.h
index 901e885..2e3c539 100644
--- a/apps/bleprph/src/bleprph.h
+++ b/apps/bleprph/src/bleprph.h
@@ -22,6 +22,7 @@
#include "log/log.h"
struct ble_hs_cfg;
+struct ble_gatt_register_ctxt;
extern struct log bleprph_log;
@@ -40,7 +41,7 @@ extern struct log bleprph_log;
#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44
-int gatt_svr_register(void);
+void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
int gatt_svr_init(struct ble_hs_cfg *cfg);
/** Misc. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index a3268d9..061db76 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -283,7 +283,7 @@ gatt_svr_uuid_to_s(const void *uuid128, char *dst)
return dst;
}
-static void
+void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
char buf[40];
@@ -316,15 +316,6 @@ gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
}
int
-gatt_svr_register(void)
-{
- int rc;
-
- rc = ble_gatts_register_svcs(gatt_svr_svcs, gatt_svr_register_cb, NULL);
- return rc;
-}
-
-int
gatt_svr_init(struct ble_hs_cfg *cfg)
{
int rc;
@@ -334,5 +325,10 @@ gatt_svr_init(struct ble_hs_cfg *cfg)
return rc;
}
+ rc = ble_gatts_add_svcs(gatt_svr_svcs);
+ if (rc != 0) {
+ return rc;
+ }
+
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index be8c1c6..3a3d64a 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -277,6 +277,9 @@ bleprph_task_handler(void *unused)
struct os_callout_func *cf;
int rc;
+ /* Activate the host. This causes the host to synchronize with the
+ * controller.
+ */
rc = ble_hs_start();
assert(rc == 0);
@@ -352,11 +355,21 @@ main(void)
rc = os_msys_register(&bleprph_mbuf_pool);
assert(rc == 0);
+ /* Initialize the console (for log output). */
+ rc = console_init(NULL);
+ assert(rc == 0);
+
/* Initialize the logging system. */
log_init();
log_console_handler_init(&bleprph_log_console_handler);
log_register("bleprph", &bleprph_log, &bleprph_log_console_handler);
+ /* Initialize eventq */
+ os_eventq_init(&bleprph_evq);
+
+ /* Create the bleprph task. All application logic and NimBLE host
+ * operations are performed in this task.
+ */
os_task_init(&bleprph_task, "bleprph", bleprph_task_handler,
NULL, BLEPRPH_TASK_PRIO, OS_WAIT_FOREVER,
bleprph_stack, BLEPRPH_STACK_SIZE);
@@ -365,64 +378,40 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
- /* Initialize the BLE host. */
+ /* Initialize the NimBLE host configuration. */
cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = 3;
cfg.max_gattc_procs = 2;
- cfg.max_l2cap_sig_procs = 1;
cfg.sm_bonding = 1;
cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
+ cfg.gatts_register_cb = gatt_svr_register_cb;
- /* Populate config with the required GATT server settings. */
+ /* Initialize GATT services. */
rc = ble_svc_gap_init(&cfg);
assert(rc == 0);
rc = ble_svc_gatt_init(&cfg);
assert(rc == 0);
- rc = gatt_svr_init(&cfg);
- assert(rc == 0);
-
- /* Nmgr ble GATT server initialization */
rc = nmgr_ble_gatt_svr_init(&bleprph_evq, &cfg);
assert(rc == 0);
- /* Initialize eventq */
- os_eventq_init(&bleprph_evq);
-
- rc = ble_hs_init(&bleprph_evq, &cfg);
+ rc = gatt_svr_init(&cfg);
assert(rc == 0);
- /* Initialize the console (for log output). */
- rc = console_init(NULL);
+ /* Initialize NimBLE host. */
+ rc = ble_hs_init(&bleprph_evq, &cfg);
assert(rc == 0);
nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
imgmgr_module_init();
- /* Register GATT attributes (services, characteristics, and
- * descriptors).
- */
- rc = ble_svc_gap_register();
- assert(rc == 0);
-
- rc = ble_svc_gatt_register();
- assert(rc == 0);
-
- rc = gatt_svr_register();
- assert(rc == 0);
-
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-bleprph");
assert(rc == 0);
- /* Nmgr ble GATT server initialization */
- rc = nmgr_ble_svc_register();
- assert(rc == 0);
-
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index b8e4864..c744edb 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -189,7 +189,7 @@ int bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi);
#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45
#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44
-int gatt_svr_register(void);
+void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
int gatt_svr_init(struct ble_hs_cfg *cfg);
/** Misc. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index d0c7a59..6a0176d 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -284,7 +284,7 @@ gatt_svr_uuid_to_s(const void *uuid128, char *dst)
return dst;
}
-static void
+void
gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
char buf[40];
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dd1a3db4/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 020b415..75bf2f7 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1622,6 +1622,7 @@ main(void)
}
srand(seed);
+ /* Allocate some application specific memory pools. */
bletiny_svc_mem = malloc(
OS_MEMPOOL_BYTES(BLETINY_MAX_SVCS, sizeof (struct bletiny_svc)));
assert(bletiny_svc_mem != NULL);
@@ -1649,6 +1650,7 @@ main(void)
"bletiny_dsc_pool");
assert(rc == 0);
+ /* Initialize msys mbufs. */
rc = os_mempool_init(&default_mbuf_mpool, MBUF_NUM_MBUFS,
MBUF_MEMBLOCK_SIZE, default_mbuf_mpool_data,
"default_mbuf_data");
@@ -1661,35 +1663,46 @@ main(void)
rc = os_msys_register(&default_mbuf_pool);
assert(rc == 0);
+ /* Initialize the console (for shell and logging). */
+ rc = console_init(shell_console_rx_cb);
+ assert(rc == 0);
+
+ /* Create the shell task. */
+ rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
+ SHELL_MAX_INPUT_LEN);
+ assert(rc == 0);
+
+ /* Initialize the logging system. */
log_init();
log_console_handler_init(&bletiny_log_console_handler);
log_register("bletiny", &bletiny_log, &bletiny_log_console_handler);
+ /* Initialize eventq for the application task. */
os_eventq_init(&bletiny_evq);
+
+ /* Create the bletiny task. All application logic and NimBLE host
+ * operations are performed in this task.
+ */
os_task_init(&bletiny_task, "bletiny", bletiny_task_handler,
NULL, BLETINY_TASK_PRIO, OS_WAIT_FOREVER,
bletiny_stack, BLETINY_STACK_SIZE);
- rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
- SHELL_MAX_INPUT_LEN);
- assert(rc == 0);
-
- /* Init the console */
- rc = console_init(shell_console_rx_cb);
+ rc = stats_module_init();
assert(rc == 0);
- rc = stats_module_init();
+ /* Initialize the BLE LL */
+ rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
- /* Initialize the BLE host. */
+ /* Initialize the NimBLE host configuration. */
cfg = ble_hs_cfg_dflt;
cfg.max_hci_bufs = 3;
cfg.max_gattc_procs = 2;
- cfg.max_l2cap_sig_procs = 2;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
+ cfg.gatts_register_cb = gatt_svr_register_cb;
- /* Populate config with the required GATT server settings. */
+ /* Initialize GATT services. */
rc = ble_svc_gap_init(&cfg);
assert(rc == 0);
@@ -1699,32 +1712,20 @@ main(void)
rc = gatt_svr_init(&cfg);
assert(rc == 0);
+ /* Initialize NimBLE host. */
rc = ble_hs_init(&bletiny_evq, &cfg);
assert(rc == 0);
- /* Initialize the BLE LL */
- rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
- assert(rc == 0);
-
rc = cmd_init();
assert(rc == 0);
- /* Register GATT attributes (services, characteristics, and
- * descriptors).
- */
- rc = ble_svc_gap_register();
- assert(rc == 0);
-
- rc = ble_svc_gatt_register();
- assert(rc == 0);
-
- rc = gatt_svr_register();
- assert(rc == 0);
-
/* Set the default device name. */
rc = ble_svc_gap_device_name_set("nimble-bletiny");
assert(rc == 0);
+ /* Create a callout (timer). This callout is used by the "tx" bletiny
+ * command to repeatedly send packets of sequential data bytes.
+ */
os_callout_func_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
NULL);