#include <gatt/dis.h> #include <gatt/bas.h> #define DEVICE_NAME "Zephyr Heartrate Sensor" #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) #define HEART_RATE_APPEARANCE 0x0341 struct bt_conn *default_conn; static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0d, 0x18, 0x0f, 0x18, 0x05, 0x18), }; static const struct bt_data sd[] = { BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), }; static void connected(struct bt_conn *conn, uint8_t err) { if (err) { printk("Connection failed (err %u)\n", err); } else { default_conn = bt_conn_ref(conn); printk("Connected\n"); } } static void disconnected(struct bt_conn *conn, uint8_t reason) { printk("Disconnected (reason %u)\n", reason);
if (cmd->connectable) { atomic_set_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); } else { atomic_clear_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE); } rp.current_settings = sys_cpu_to_le32(current_settings); tester_send(BTP_SERVICE_ID_GAP, GAP_SET_CONNECTABLE, CONTROLLER_INDEX, (uint8_t *) &rp, sizeof(rp)); } static uint8_t ad_flags = BT_LE_AD_NO_BREDR; static struct bt_data ad[10] = { BT_DATA(BT_DATA_FLAGS, &ad_flags, sizeof(ad_flags)), }; static struct bt_data sd[10]; static void set_discoverable(uint8_t *data, uint16_t len) { const struct gap_set_discoverable_cmd *cmd = (void *) data; struct gap_set_discoverable_rp rp; switch (cmd->discoverable) { case GAP_NON_DISCOVERABLE: ad_flags &= ~(BT_LE_AD_GENERAL | BT_LE_AD_LIMITED); atomic_clear_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE); break; case GAP_GENERAL_DISCOVERABLE: ad_flags &= ~BT_LE_AD_LIMITED;