This helpers should be in one place, in file's upper part.
---
android/gatt.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 61746b1..39195f0 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -135,6 +135,20 @@ static void uuid2android(const bt_uuid_t *src, uint8_t *uuid)
uuid[15 - i] = src->value.u128.data[i];
}
+static void hal_srvc_id_to_element_id(const struct hal_gatt_srvc_id *from,
+ struct element_id *to)
+{
+ to->instance = from->inst_id;
+ android2uuid(from->uuid, &to->uuid);
+}
+
+static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
+ struct element_id *to)
+{
+ to->instance = from->inst_id;
+ android2uuid(from->uuid, &to->uuid);
+}
+
static void destroy_service(void *data)
{
struct service *srvc = data;
@@ -256,13 +270,6 @@ static bool match_char_by_element_id(const void *data, const void *user_data)
return false;
}
-static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
- struct element_id *to)
-{
- to->instance = from->inst_id;
- android2uuid(from->uuid, &to->uuid);
-}
-
static void destroy_notification(void *data)
{
struct notification_data *notification = data;
@@ -1268,13 +1275,6 @@ static void discover_char_cb(uint8_t status, GSList *characteristics,
free(data);
}
-static void hal_srvc_id_to_element_id(const struct hal_gatt_srvc_id *from,
- struct element_id *to)
-{
- to->instance = from->inst_id;
- android2uuid(from->uuid, &to->uuid);
-}
-
static bool find_service(int32_t conn_id, struct element_id *service_id,
struct gatt_device **dev, struct service **srvc)
{
--
1.9.0
Ho Jakub,
On Tuesday 01 of April 2014 10:03:22 Jakub Tyszkowski wrote:
> This helpers should be in one place, in file's upper part.
> ---
> android/gatt.c | 28 ++++++++++++++--------------
> 1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index 61746b1..39195f0 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -135,6 +135,20 @@ static void uuid2android(const bt_uuid_t *src, uint8_t *uuid)
> uuid[15 - i] = src->value.u128.data[i];
> }
>
> +static void hal_srvc_id_to_element_id(const struct hal_gatt_srvc_id *from,
> + struct element_id *to)
> +{
> + to->instance = from->inst_id;
> + android2uuid(from->uuid, &to->uuid);
> +}
> +
> +static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
> + struct element_id *to)
> +{
> + to->instance = from->inst_id;
> + android2uuid(from->uuid, &to->uuid);
> +}
> +
> static void destroy_service(void *data)
> {
> struct service *srvc = data;
> @@ -256,13 +270,6 @@ static bool match_char_by_element_id(const void *data, const void *user_data)
> return false;
> }
>
> -static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
> - struct element_id *to)
> -{
> - to->instance = from->inst_id;
> - android2uuid(from->uuid, &to->uuid);
> -}
> -
> static void destroy_notification(void *data)
> {
> struct notification_data *notification = data;
> @@ -1268,13 +1275,6 @@ static void discover_char_cb(uint8_t status, GSList *characteristics,
> free(data);
> }
>
> -static void hal_srvc_id_to_element_id(const struct hal_gatt_srvc_id *from,
> - struct element_id *to)
> -{
> - to->instance = from->inst_id;
> - android2uuid(from->uuid, &to->uuid);
> -}
> -
> static bool find_service(int32_t conn_id, struct element_id *service_id,
> struct gatt_device **dev, struct service **srvc)
> {
>
All patches applied, thanks.
--
Best regards,
Szymon Janc
We should match uuid from element_id struct to avoid uuid creation every
time.
---
android/gatt.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 37a1986..9dd7fe4 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -229,11 +229,9 @@ static bool match_srvc_by_element_id(const void *data, const void *user_data)
{
const struct element_id *exp_id = user_data;
const struct service *service = data;
- bt_uuid_t uuid;
- bt_string_to_uuid(&uuid, service->primary.uuid);
if (service->id.instance == exp_id->instance)
- return !bt_uuid_cmp(&uuid, &exp_id->uuid);
+ return !bt_uuid_cmp(&service->id.uuid, &exp_id->uuid);
return false;
}
@@ -277,11 +275,9 @@ static bool match_char_by_element_id(const void *data, const void *user_data)
{
const struct element_id *exp_id = user_data;
const struct characteristic *chars = data;
- bt_uuid_t uuid;
- bt_string_to_uuid(&uuid, chars->ch.uuid);
if (exp_id->instance == chars->id.instance)
- return !bt_uuid_cmp(&uuid, &exp_id->uuid);
+ return !bt_uuid_cmp(&chars->id.uuid, &exp_id->uuid);
return false;
}
--
1.9.0
We have helpers for hal structs to element_id conversion, so we should
use symetrical element_id to hal struct helpers when sending
notifications.
---
android/gatt.c | 45 +++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 39195f0..37a1986 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -142,6 +142,15 @@ static void hal_srvc_id_to_element_id(const struct hal_gatt_srvc_id *from,
android2uuid(from->uuid, &to->uuid);
}
+static void element_id_to_hal_srvc_id(const struct element_id *from,
+ uint8_t primary,
+ struct hal_gatt_srvc_id *to)
+{
+ to->is_primary = primary;
+ to->inst_id = from->instance;
+ uuid2android(&from->uuid, to->uuid);
+}
+
static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
struct element_id *to)
{
@@ -149,6 +158,13 @@ static void hal_gatt_id_to_element_id(const struct hal_gatt_gatt_id *from,
android2uuid(from->uuid, &to->uuid);
}
+static void element_id_to_hal_gatt_id(const struct element_id *from,
+ struct hal_gatt_gatt_id *to)
+{
+ to->inst_id = from->instance;
+ uuid2android(&from->uuid, to->uuid);
+}
+
static void destroy_service(void *data)
{
struct service *srvc = data;
@@ -468,10 +484,7 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data)
/* Set event data */
ev_res.conn_id = dev->conn_id;
- ev_res.srvc_id.is_primary = 1;
- ev_res.srvc_id.inst_id = 0;
-
- uuid2android(&p->id.uuid, ev_res.srvc_id.uuid);
+ element_id_to_hal_srvc_id(&p->id, 1, &ev_res.srvc_id);
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT ,
HAL_EV_GATT_CLIENT_SEARCH_RESULT,
@@ -1206,16 +1219,12 @@ static void send_client_char_notify(const struct characteristic *ch,
if (ch) {
ev.char_prop = ch->ch.properties;
-
- ev.char_id.inst_id = ch->id.instance;
- uuid2android(&ch->id.uuid, ev.char_id.uuid);
+ element_id_to_hal_gatt_id(&ch->id, &ev.char_id);
}
ev.conn_id = conn_id;
/* TODO need to be handled for included services too */
- ev.srvc_id.is_primary = 1;
- ev.srvc_id.inst_id = service->id.instance;
- uuid2android(&service->id.uuid, ev.srvc_id.uuid);
+ element_id_to_hal_srvc_id(&service->id, 1, &ev.srvc_id);
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
HAL_EV_GATT_CLIENT_GET_CHARACTERISTIC,
@@ -1397,12 +1406,8 @@ static void send_client_read_char_notify(int32_t status, const uint8_t *pdu,
ev->conn_id = conn_id;
ev->status = status;
- ev->data.srvc_id.inst_id = srvc_id->instance;
- uuid2android(&srvc_id->uuid, ev->data.srvc_id.uuid);
- ev->data.srvc_id.is_primary = primary;
-
- ev->data.char_id.inst_id = char_id->instance;
- uuid2android(&char_id->uuid, ev->data.char_id.uuid);
+ element_id_to_hal_srvc_id(srvc_id, primary, &ev->data.srvc_id);
+ element_id_to_hal_gatt_id(char_id, &ev->data.char_id);
if (pdu) {
vlen = dec_read_resp(pdu, len, ev->data.value, sizeof(buf));
@@ -1518,12 +1523,8 @@ static void send_client_write_char_notify(int32_t status, int32_t conn_id,
ev.conn_id = conn_id;
ev.status = status;
- ev.data.srvc_id.inst_id = srvc_id->instance;
- uuid2android(&srvc_id->uuid, ev.data.srvc_id.uuid);
- ev.data.srvc_id.is_primary = primary;
-
- ev.data.char_id.inst_id = char_id->instance;
- uuid2android(&char_id->uuid, ev.data.srvc_id.uuid);
+ element_id_to_hal_srvc_id(srvc_id, primary, &ev.data.srvc_id);
+ element_id_to_hal_gatt_id(char_id, &ev.data.char_id);
ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
HAL_EV_GATT_CLIENT_WRITE_CHARACTERISTIC,
--
1.9.0