mirror of https://github.com/labapart/gattlib
Introduced 'gattlib_write_char_by_uuid'
parent
74972ae011
commit
ee2fabaf3f
|
@ -181,3 +181,16 @@ int gattlib_write_char_by_handle(gatt_connection_t* connection, uint16_t handle,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gattlib_write_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void* buffer, size_t buffer_len) {
|
||||
uint16_t handle = 0;
|
||||
int ret;
|
||||
|
||||
ret = get_handle_from_uuid(connection, uuid, &handle);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Fail to find handle for UUID.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return gattlib_write_char_by_handle(connection, handle, buffer, sizeof(buffer));
|
||||
}
|
||||
|
|
|
@ -82,30 +82,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("%02x ", buffer[i]);
|
||||
printf("\n");
|
||||
} else {
|
||||
uint16_t handle = 0;
|
||||
|
||||
// Look for handle for the corresponding UUID
|
||||
gattlib_characteristic_t* characteristics;
|
||||
int characteristic_count;
|
||||
ret = gattlib_discover_char(connection, &characteristics, &characteristic_count);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Fail to discover characteristic.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < characteristic_count; i++) {
|
||||
if (gattlib_uuid_cmp(&characteristics[i].uuid, &g_uuid) == 0) {
|
||||
handle = characteristics[i].value_handle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handle == 0) {
|
||||
fprintf(stderr, "Fail to find handle for UUID.\n");
|
||||
return 1;
|
||||
}
|
||||
free(characteristics);
|
||||
|
||||
ret = gattlib_write_char_by_handle(connection, handle, buffer, sizeof(buffer));
|
||||
ret = gattlib_write_char_by_uuid(connection, &g_uuid, buffer, sizeof(buffer));
|
||||
assert(ret == 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ int gattlib_discover_desc(gatt_connection_t* connection, gattlib_descriptor_t**
|
|||
int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void* buffer, size_t buffer_len);
|
||||
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid, gatt_read_cb_t gatt_read_cb);
|
||||
|
||||
int gattlib_write_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void* buffer, size_t buffer_len);
|
||||
int gattlib_write_char_by_handle(gatt_connection_t* connection, uint16_t handle, void* buffer, size_t buffer_len);
|
||||
|
||||
void gattlib_register_notification(gatt_connection_t* connection, gattlib_event_handler_t notification_handler, void* user_data);
|
||||
|
|
Loading…
Reference in New Issue