From f3f32579ec5bffacd5912f0ffbb0399b28d32241 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 25 Feb 2015 13:22:09 +0100 Subject: [PATCH] android/bas: Read battery level characteristic For TC_HGRF_HH_BV_10_I test purposes, apart from registration for notification, read request should be sent to get battery level. --- android/bas.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/android/bas.c b/android/bas.c index 3d4bee0ed..b6891ab21 100644 --- a/android/bas.c +++ b/android/bas.c @@ -44,6 +44,7 @@ #include "android/bas.h" #define ATT_NOTIFICATION_HEADER_SIZE 3 +#define ATT_READ_RESPONSE_HEADER_SIZE 1 struct bt_bas { int ref_count; @@ -226,11 +227,17 @@ static void discover_desc(struct bt_bas *bas, GAttrib *attrib, free(req); } -static void value_cb(const guint8 *pdu, guint16 len, gpointer user_data) +static void notification_cb(const guint8 *pdu, guint16 len, gpointer user_data) { DBG("Battery Level at %u", pdu[ATT_NOTIFICATION_HEADER_SIZE]); } +static void read_value_cb(guint8 status, const guint8 *pdu, guint16 len, + gpointer user_data) +{ + DBG("Battery Level at %u", pdu[ATT_READ_RESPONSE_HEADER_SIZE]); +} + static void ccc_written_cb(guint8 status, const guint8 *pdu, guint16 plen, gpointer user_data) { @@ -248,7 +255,8 @@ static void ccc_written_cb(guint8 status, const guint8 *pdu, DBG("Battery Level: notification enabled"); bas->id = g_attrib_register(bas->attrib, ATT_OP_HANDLE_NOTIFY, - bas->handle, value_cb, bas, NULL); + bas->handle, notification_cb, bas, + NULL); } static void write_ccc(struct bt_bas *bas, GAttrib *attrib, uint16_t handle, @@ -319,6 +327,8 @@ static void bas_discovered_cb(uint8_t status, GSList *chars, void *user_data) DBG("Battery handle: 0x%04x", bas->handle); + read_char(bas, bas->attrib, bas->handle, read_value_cb, bas); + start = chr->value_handle + 1; end = bas->primary->range.end; -- 2.47.3