Skip to content

Commit

Permalink
bluetooth: Add CPF attribute to BAS battery level.
Browse files Browse the repository at this point in the history
BAS v1.1, section 3.1.2.1 notes that a CPF should be added if the
device has more that one instance of the Battery Service, so
add one with the `main` description so that apps can add additional
Battery Level services with other descriptions, e.g. `auxiliary`.

Signed-off-by: Peter Johanson <[email protected]>
  • Loading branch information
petejohanson committed Dec 1, 2023
1 parent 9b9cf36 commit 1ae0eb5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions subsys/bluetooth/services/bas.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ static ssize_t read_blvl(struct bt_conn *conn,
sizeof(lvl8));
}

/* Constant values from the Assigned Numbers specification:
* https://www.bluetooth.com/wp-content/uploads/Files/Specification/Assigned_Numbers.pdf?id=89
*/
static const struct bt_gatt_cpf level_cpf = {
.format = 0x04, /* uint8 */
.exponent = 0x0,
.unit = 0x27AD, /* Percentage */
.name_space = 0x01, /* Bluetooth SIG */
.description = 0x0106, /* "main" */
};

BT_GATT_SERVICE_DEFINE(bas,
BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL,
Expand All @@ -55,6 +66,7 @@ BT_GATT_SERVICE_DEFINE(bas,
&battery_level),
BT_GATT_CCC(blvl_ccc_cfg_changed,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
BT_GATT_CPF(&level_cpf),
);

static int bas_init(const struct device *dev)
Expand Down

0 comments on commit 1ae0eb5

Please sign in to comment.