examples/read_write: Print an error message rather than an assert when the GATT characteristic is not found

pull/95/head
Olivier Martin 2019-03-05 17:14:45 +01:00
parent c2e48c3fd6
commit f9b92018f1
1 changed files with 20 additions and 4 deletions

View File

@ -78,17 +78,33 @@ int main(int argc, char *argv[]) {
if (g_operation == READ) {
len = sizeof(buffer);
ret = gattlib_read_char_by_uuid(connection, &g_uuid, buffer, &len);
assert(ret == 0);
if (ret == -1) {
char uuid_str[MAX_LEN_UUID_STR + 1];
gattlib_uuid_to_string(&g_uuid, uuid_str, sizeof(uuid_str));
fprintf(stderr, "Could not find GATT Characteristic with UUID %s\n", uuid_str);
goto EXIT;
}
printf("Read UUID completed: ");
for (i = 0; i < len; i++)
for (i = 0; i < len; i++) {
printf("%02x ", buffer[i]);
}
printf("\n");
} else {
ret = gattlib_write_char_by_uuid(connection, &g_uuid, buffer, sizeof(buffer));
assert(ret == 0);
if (ret == -1) {
char uuid_str[MAX_LEN_UUID_STR + 1];
gattlib_uuid_to_string(&g_uuid, uuid_str, sizeof(uuid_str));
fprintf(stderr, "Could not find GATT Characteristic with UUID %s\n", uuid_str);
goto EXIT;
}
}
EXIT:
gattlib_disconnect(connection);
return 0;
return ret;
}