Bluetooth: Add Heart Rate Service to peripheral sample

Add Heart Rate Service along with its characteristics and descriptors
to the database table.

Change-Id: Ibff52da7352883edccb7c5b903538a81aad2ba55
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-05-21 13:12:28 +03:00 committed by Anas Nashif
parent 0d505e2045
commit 1b793139db
2 changed files with 79 additions and 0 deletions

View file

@ -34,6 +34,7 @@
#define BT_UUID_GAP 0x1800
#define BT_UUID_GATT 0x1801
#define BT_UUID_HRS 0x180d
#define BT_UUID_GATT_PRIMARY 0x2800
#define BT_UUID_GATT_SECONDARY 0x2801
#define BT_UUID_GATT_INCLUDE 0x2802
@ -43,6 +44,9 @@
#define BT_UUID_GATT_CCC 0x2902
#define BT_UUID_GAP_DEVICE_NAME 0x2a00
#define BT_UUID_GAP_APPEARANCE 0x2a01
#define BT_UUID_HR_MEASUREMENT 0x2a37
#define BT_UUID_HR_BODY_SENSOR 0x2a38
#define BT_UUID_HR_CONTROL_POINT 0x2a39
/* Bluetooth UUID types */
enum bt_uuid_type {

View file

@ -89,6 +89,65 @@ static int read_appearance(const struct bt_gatt_attr *attr, void *buf,
sizeof(appearance));
}
static struct bt_uuid hrs_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS,
};
static struct bt_uuid hrmc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HR_MEASUREMENT,
};
static struct bt_gatt_chrc hrmc_chrc = {
.properties = BT_GATT_CHRC_NOTIFY,
.value_handle = 0x0008,
.uuid = &hrmc_uuid,
};
static struct bt_uuid bslc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HR_BODY_SENSOR,
};
static struct bt_gatt_chrc bslc_chrc = {
.properties = BT_GATT_CHRC_READ,
.value_handle = 0x000b,
.uuid = &bslc_uuid,
};
static struct bt_uuid hrcpc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HR_CONTROL_POINT,
};
static struct bt_gatt_chrc hrcpc_chrc = {
.properties = BT_GATT_CHRC_WRITE,
.value_handle = 0x000d,
.uuid = &hrcpc_uuid,
};
static struct bt_uuid ccc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GATT_CCC,
};
static int read_ccc(const struct bt_gatt_attr *attr, void *buf, uint8_t len,
uint16_t offset)
{
uint16_t value = 0x0000;
return bt_gatt_attr_read(attr, buf, len, offset, &value, sizeof(value));
}
static int read_blsc(const struct bt_gatt_attr *attr, void *buf, uint8_t len,
uint16_t offset)
{
uint8_t value = 0x01;
return bt_gatt_attr_read(attr, buf, len, offset, &value, sizeof(value));
}
static const struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(0x0001, &gap_uuid),
BT_GATT_CHARACTERISTIC(0x0002, &name_chrc),
@ -97,6 +156,17 @@ static const struct bt_gatt_attr attrs[] = {
BT_GATT_CHARACTERISTIC(0x0004, &appearance_chrc),
BT_GATT_DESCRIPTOR(0x0005, &appeareance_uuid, read_appearance, NULL,
NULL),
/* Heart Rate Service Declaration */
BT_GATT_PRIMARY_SERVICE(0x0006, &hrs_uuid),
BT_GATT_CHARACTERISTIC(0x0007, &hrmc_chrc),
BT_GATT_DESCRIPTOR(0x0008, &hrmc_uuid, NULL, NULL, NULL),
/* TODO: Add write support CCC */
BT_GATT_DESCRIPTOR(0x0009, &ccc_uuid, read_ccc, NULL, NULL),
BT_GATT_CHARACTERISTIC(0x000a, &bslc_chrc),
BT_GATT_DESCRIPTOR(0x000b, &bslc_uuid, read_blsc, NULL, NULL),
BT_GATT_CHARACTERISTIC(0x000c, &hrcpc_chrc),
/* TODO: Add write permission and callback */
BT_GATT_DESCRIPTOR(0x000d, &hrcpc_uuid, NULL, NULL, NULL),
};
static const struct bt_eir ad[] = {
@ -105,6 +175,11 @@ static const struct bt_eir ad[] = {
.type = BT_EIR_FLAGS,
.data = { BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR },
},
{
.len = 3,
.type = BT_EIR_UUID16_ALL,
.data = { 0x0d, 0x18 },
},
{ }
};