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 2018/11/21 22:47:36 UTC
[mynewt-nimble] 04/06: apps/btshell: Allow enable / disable of host
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 766fea564c2e3ac1602705546bb1656b3e7e5c18
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Oct 4 12:28:20 2018 -0700
apps/btshell: Allow enable / disable of host
This commit adds two commands to btshell:
* host-enable
* host-disable
---
apps/btshell/src/cmd.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
apps/btshell/src/main.c | 7 ++++++
2 files changed, 73 insertions(+)
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 0ad0e8a..42507fd 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -3155,6 +3155,58 @@ static const struct shell_cmd_help phy_read_help = {
};
/*****************************************************************************
+ * $host-enable *
+ *****************************************************************************/
+
+static int
+cmd_host_enable(int argc, char **argv)
+{
+ ble_hs_sched_start();
+
+ return 0;
+}
+
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+static const struct shell_cmd_help host_enable_help = {
+ .summary = "start the NimBLE host",
+ .usage = NULL,
+ .params = NULL,
+};
+#endif
+
+/*****************************************************************************
+ * $host-disable *
+ *****************************************************************************/
+
+static void
+on_stop(int status, void *arg)
+{
+ if (status == 0) {
+ console_printf("host stopped\n");
+ } else {
+ console_printf("host failed to stop; rc=%d\n", status);
+ }
+}
+
+static int
+cmd_host_disable(int argc, char **argv)
+{
+ static struct ble_hs_stop_listener listener;
+ int rc;
+
+ rc = ble_hs_stop(&listener, on_stop, NULL);
+ return rc;
+}
+
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+static const struct shell_cmd_help host_disable_help = {
+ .summary = "stop the NimBLE host",
+ .usage = NULL,
+ .params = NULL,
+};
+#endif
+
+/*****************************************************************************
* $gatt-discover *
*****************************************************************************/
@@ -3856,6 +3908,20 @@ static const struct shell_cmd btshell_commands[] = {
.help = &phy_read_help,
#endif
},
+ {
+ .sc_cmd = "host-enable",
+ .sc_cmd_func = cmd_host_enable,
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+ .help = &host_enable_help,
+#endif
+ },
+ {
+ .sc_cmd = "host-disable",
+ .sc_cmd_func = cmd_host_disable,
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+ .help = &host_disable_help,
+#endif
+ },
{ NULL, NULL, NULL },
};
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index ab60527..f87efb9 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -1862,6 +1862,12 @@ btshell_on_reset(int reason)
console_printf("Error: Resetting state; reason=%d\n", reason);
}
+static void
+btshell_on_sync(void)
+{
+ console_printf("Host and controller synced\n");
+}
+
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
static int
@@ -2214,6 +2220,7 @@ main(int argc, char **argv)
/* Initialize the NimBLE host configuration. */
ble_hs_cfg.reset_cb = btshell_on_reset;
+ ble_hs_cfg.sync_cb = btshell_on_sync;
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;