apps/btshell: Allow enable / disable of host

This commit adds two commands to btshell:
    * host-enable
    * host-disable
This commit is contained in:
Christopher Collins
2018-11-21 14:47:27 -08:00
committed by ccollins476ad
parent 4eec25a1c2
commit 766fea564c
2 changed files with 73 additions and 0 deletions
+66
View File
@@ -3154,6 +3154,58 @@ static const struct shell_cmd_help phy_read_help = {
.params = phy_read_params,
};
/*****************************************************************************
* $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 *
*****************************************************************************/
@@ -3854,6 +3906,20 @@ static const struct shell_cmd btshell_commands[] = {
.sc_cmd_func = cmd_phy_read,
#if MYNEWT_VAL(SHELL_CMD_HELP)
.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 },
+7
View File
@@ -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;