examples: Use GATTLIB_ error code

pull/108/head
Olivier Martin 2019-06-26 17:34:57 +02:00 committed by Olivier Martin
parent 120f6e0886
commit 028004a8a1
4 changed files with 11 additions and 11 deletions

View File

@ -47,7 +47,7 @@ int main(int argc, char *argv[])
}
ret = gattlib_discover_primary(connection, &services, &services_count);
if (ret != 0) {
if (ret != GATTLIB_SUCCESS) {
fprintf(stderr, "Fail to discover primary services.\n");
return 1;
}
@ -62,7 +62,7 @@ int main(int argc, char *argv[])
free(services);
ret = gattlib_discover_char(connection, &characteristics, &characteristics_count);
if (ret != 0) {
if (ret != GATTLIB_SUCCESS) {
fprintf(stderr, "Fail to discover characteristics.\n");
return 1;
}

View File

@ -159,7 +159,7 @@ static gboolean primary(gpointer user_data)
int services_count, i;
int ret = gattlib_discover_primary(connection, &services, &services_count);
if (ret == 0) {
if (ret == GATTLIB_SUCCESS) {
for (i = 0; i < services_count; i++) {
gattlib_uuid_to_string(&services[i].uuid, uuid_str, sizeof(uuid_str));

View File

@ -351,7 +351,7 @@ static void cmd_primary(int argcp, char **argvp)
int services_count, ret, i;
ret = gattlib_discover_primary(g_connection, &services, &services_count);
if (ret == 0) {
if (ret == GATTLIB_SUCCESS) {
for (i = 0; i < services_count; i++) {
gattlib_uuid_to_string(&services[i].uuid, uuid_str, sizeof(uuid_str));
@ -428,7 +428,7 @@ static void cmd_char(int argcp, char **argvp)
}
ret = gattlib_discover_char_range(g_connection, start, end, &characteristics, &characteristics_count);
if (ret == 0) {
if (ret == GATTLIB_SUCCESS) {
for (i = 0; i < characteristics_count; i++) {
gattlib_uuid_to_string(&characteristics[i].uuid, uuid_str, sizeof(uuid_str));
@ -470,7 +470,7 @@ static void cmd_char_desc(int argcp, char **argvp)
}
ret = gattlib_discover_desc_range(g_connection, start, end, &descriptors, &descriptor_count);
if (ret == 0) {
if (ret == GATTLIB_SUCCESS) {
for (i = 0; i < descriptor_count; i++) {
char uuid_str[MAX_LEN_UUID_STR + 1];

View File

@ -75,15 +75,15 @@ int main(int argc, char *argv[]) {
}
if (g_operation == READ) {
uint8_t *buffer;
uint8_t *buffer = NULL;
ret = gattlib_read_char_by_uuid(connection, &g_uuid, (void **)&buffer, &len);
if (ret == -1) {
if (ret != GATTLIB_SUCCESS) {
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);
fprintf(stderr, "Could not find GATT Characteristic with UUID %s (ret:%d)\n", uuid_str, ret);
goto EXIT;
}
@ -96,12 +96,12 @@ int main(int argc, char *argv[]) {
free(buffer);
} else {
ret = gattlib_write_char_by_uuid(connection, &g_uuid, &value_data, sizeof(value_data));
if (ret == -1) {
if (ret != GATTLIB_SUCCESS) {
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);
fprintf(stderr, "Could not find GATT Characteristic with UUID %s (ret:%d)\n", uuid_str, ret);
goto EXIT;
}
}