mirror of https://github.com/labapart/gattlib
gattlib.h: Changed prototype of 'gattlib_read_char_by_uuid'
parent
80f9884ae0
commit
beed53a6ba
|
@ -95,21 +95,20 @@ void uuid_to_bt_uuid(uuid_t* uuid, bt_uuid_t* bt_uuid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid,
|
int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid,
|
||||||
void* buffer, size_t buffer_len)
|
void* buffer, size_t* buffer_len)
|
||||||
{
|
{
|
||||||
gattlib_context_t* conn_context = connection->context;
|
gattlib_context_t* conn_context = connection->context;
|
||||||
struct gattlib_result_read_uuid_t* gattlib_result;
|
struct gattlib_result_read_uuid_t* gattlib_result;
|
||||||
bt_uuid_t bt_uuid;
|
bt_uuid_t bt_uuid;
|
||||||
const int start = 0x0001;
|
const int start = 0x0001;
|
||||||
const int end = 0xffff;
|
const int end = 0xffff;
|
||||||
int len;
|
|
||||||
|
|
||||||
gattlib_result = malloc(sizeof(struct gattlib_result_read_uuid_t));
|
gattlib_result = malloc(sizeof(struct gattlib_result_read_uuid_t));
|
||||||
if (gattlib_result == NULL) {
|
if (gattlib_result == NULL) {
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
gattlib_result->buffer = buffer;
|
gattlib_result->buffer = buffer;
|
||||||
gattlib_result->buffer_max_len = buffer_len;
|
gattlib_result->buffer_max_len = *buffer_len;
|
||||||
gattlib_result->buffer_len = 0;
|
gattlib_result->buffer_len = 0;
|
||||||
gattlib_result->callback = NULL;
|
gattlib_result->callback = NULL;
|
||||||
gattlib_result->completed = FALSE;
|
gattlib_result->completed = FALSE;
|
||||||
|
@ -124,10 +123,10 @@ int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid,
|
||||||
g_main_context_iteration(g_gattlib_thread.loop_context, FALSE);
|
g_main_context_iteration(g_gattlib_thread.loop_context, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
len = gattlib_result->buffer_len;
|
*buffer_len = gattlib_result->buffer_len;
|
||||||
|
|
||||||
free(gattlib_result);
|
free(gattlib_result);
|
||||||
return len;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid,
|
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid,
|
||||||
|
|
|
@ -775,7 +775,7 @@ int gattlib_discover_desc(gatt_connection_t* connection, gattlib_descriptor_t**
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(gatt_connection_t* connection, uuid_t* uuid, void* buffer, size_t* buffer_len) {
|
||||||
OrgBluezGattCharacteristic1 *characteristic = get_characteristic_from_uuid(uuid);
|
OrgBluezGattCharacteristic1 *characteristic = get_characteristic_from_uuid(uuid);
|
||||||
if (characteristic == NULL) {
|
if (characteristic == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -793,12 +793,14 @@ int gattlib_read_char_by_uuid(gatt_connection_t* connection, uuid_t* uuid, void*
|
||||||
gsize n_elements = 0;
|
gsize n_elements = 0;
|
||||||
gconstpointer const_buffer = g_variant_get_fixed_array(out_value, &n_elements, sizeof(guchar));
|
gconstpointer const_buffer = g_variant_get_fixed_array(out_value, &n_elements, sizeof(guchar));
|
||||||
if (const_buffer) {
|
if (const_buffer) {
|
||||||
n_elements = MIN(n_elements, buffer_len);
|
n_elements = MIN(n_elements, *buffer_len);
|
||||||
memcpy(buffer, const_buffer, n_elements);
|
memcpy(buffer, const_buffer, n_elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*buffer_len = n_elements;
|
||||||
|
|
||||||
g_object_unref(characteristic);
|
g_object_unref(characteristic);
|
||||||
return n_elements;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid, gatt_read_cb_t gatt_read_cb) {
|
int gattlib_read_char_by_uuid_async(gatt_connection_t* connection, uuid_t* uuid, gatt_read_cb_t gatt_read_cb) {
|
||||||
|
|
|
@ -249,12 +249,13 @@ static gboolean characteristics_read(gpointer user_data)
|
||||||
if (opt_uuid != NULL) {
|
if (opt_uuid != NULL) {
|
||||||
uint8_t buffer[0x100];
|
uint8_t buffer[0x100];
|
||||||
uuid_t uuid;
|
uuid_t uuid;
|
||||||
int len, i;
|
size_t len = sizeof(buffer);
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
bt_uuid_to_uuid(opt_uuid, &uuid);
|
bt_uuid_to_uuid(opt_uuid, &uuid);
|
||||||
|
|
||||||
len = gattlib_read_char_by_uuid(connection, &uuid, buffer, sizeof(buffer));
|
ret = gattlib_read_char_by_uuid(connection, &uuid, buffer, &len);
|
||||||
if (len == 0) {
|
if (ret) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
g_print("value: ");
|
g_print("value: ");
|
||||||
|
|
|
@ -39,7 +39,8 @@ static void usage(char *argv[]) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
uint8_t buffer[100];
|
uint8_t buffer[100];
|
||||||
int i, len, ret;
|
int i, ret;
|
||||||
|
size_t len;
|
||||||
gatt_connection_t* connection;
|
gatt_connection_t* connection;
|
||||||
|
|
||||||
if ((argc != 4) && (argc != 5)) {
|
if ((argc != 4) && (argc != 5)) {
|
||||||
|
@ -75,7 +76,9 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_operation == READ) {
|
if (g_operation == READ) {
|
||||||
len = gattlib_read_char_by_uuid(connection, &g_uuid, buffer, sizeof(buffer));
|
len = sizeof(buffer);
|
||||||
|
ret = gattlib_read_char_by_uuid(connection, &g_uuid, buffer, &len);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
printf("Read UUID completed: ");
|
printf("Read UUID completed: ");
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
|
|
|
@ -136,7 +136,7 @@ int gattlib_discover_char(gatt_connection_t* connection, gattlib_characteristic_
|
||||||
int gattlib_discover_desc_range(gatt_connection_t* connection, int start, int end, gattlib_descriptor_t** descriptors, int* descriptor_count);
|
int gattlib_discover_desc_range(gatt_connection_t* connection, int start, int end, gattlib_descriptor_t** descriptors, int* descriptor_count);
|
||||||
int gattlib_discover_desc(gatt_connection_t* connection, gattlib_descriptor_t** descriptors, int* descriptor_count);
|
int gattlib_discover_desc(gatt_connection_t* connection, gattlib_descriptor_t** descriptors, int* descriptor_count);
|
||||||
|
|
||||||
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(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_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_uuid(gatt_connection_t* connection, uuid_t* uuid, void* buffer, size_t buffer_len);
|
||||||
|
|
Loading…
Reference in New Issue