diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2016-01-28 14:00:40 +0200 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2016-02-05 20:25:27 -0500 |
commit | bcea32a2cad76c2e32f9b0c7818100aa36854651 (patch) | |
tree | 6d6801d9678d108565ab523cedbcc9242caec517 /samples | |
parent | 26e152f7344bed7fec307a523987f4e8bf3280d3 (diff) |
Bluetooth: shell: Don't call bt_enable blocking
Now that nble driver is supported bt_enable cannot be called blocking
since it is not supported, futhermore the call to bt_gatt_register
should be done after bt_enable is complete.
Change-Id: I404f8cd8b8339dba0fd26d24edeb718eba4bf225
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/bluetooth/shell/src/main.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/samples/bluetooth/shell/src/main.c b/samples/bluetooth/shell/src/main.c index fdcc228ad..af089894e 100644 --- a/samples/bluetooth/shell/src/main.c +++ b/samples/bluetooth/shell/src/main.c @@ -206,15 +206,56 @@ static struct bt_conn_cb conn_callbacks = { .security_changed = security_changed, }; +static int read_string(struct bt_conn *conn, const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) +{ + const char *str = attr->user_data; + + return bt_gatt_attr_read(conn, attr, buf, len, offset, str, + strlen(str)); +} + +static uint16_t appearance_value = 0x0001; + +static int read_appearance(struct bt_conn *conn, + const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) +{ + uint16_t appearance = sys_cpu_to_le16(appearance_value); + + return bt_gatt_attr_read(conn, attr, buf, len, offset, &appearance, + sizeof(appearance)); +} + +static struct bt_gatt_attr attrs[] = { + BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP), + BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ), + BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ, + read_string, NULL, DEVICE_NAME), + BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ), + BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ, + read_appearance, NULL, NULL), +}; + +static void bt_ready(int err) +{ + if (err) { + printk("Bluetooth init failed (err %d)\n", err); + return; + } + + printk("Bluetooth initialized\n"); + + bt_gatt_register(attrs, ARRAY_SIZE(attrs)); +} + static void cmd_init(int argc, char *argv[]) { int err; - err = bt_enable(NULL); + err = bt_enable(bt_ready); if (err) { printk("Bluetooth init failed (err %d)\n", err); - } else { - printk("Bluetooth initialized\n"); } } @@ -1008,37 +1049,6 @@ static void cmd_gatt_unsubscribe(int argc, char *argv[]) } } -static int read_string(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const char *str = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, str, - strlen(str)); -} - -static uint16_t appearance_value = 0x0001; - -static int read_appearance(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - uint16_t appearance = sys_cpu_to_le16(appearance_value); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &appearance, - sizeof(appearance)); -} - -static struct bt_gatt_attr attrs[] = { - BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP), - BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ, - read_string, NULL, DEVICE_NAME), - BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ), - BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ, - read_appearance, NULL, NULL), -}; - static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) { char addr[BT_ADDR_LE_STR_LEN]; @@ -1529,8 +1539,6 @@ void main(void) { bt_conn_cb_register(&conn_callbacks); - bt_gatt_register(attrs, ARRAY_SIZE(attrs)); - net_buf_pool_init(data_pool); shell_init("btshell> ", commands); |