From 2baf01d2b227306eb75a5788cec285355109c089 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 2 Dec 2019 12:26:00 +0100 Subject: [PATCH] ad_parser: use bool return types --- src/ad_parser.c | 26 +++++++++++++------------- src/ad_parser.h | 8 +++++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ad_parser.c b/src/ad_parser.c index 27a9c7b5d..79efe5d9e 100644 --- a/src/ad_parser.c +++ b/src/ad_parser.c @@ -63,18 +63,18 @@ void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_ context->offset = 0; } -int ad_iterator_has_more(const ad_context_t * context){ +bool ad_iterator_has_more(const ad_context_t * context){ // assert chunk_len and chunk_type are withing buffer - if ((context->offset+1) >= context->length) return 0; + if ((context->offset+1) >= context->length) return false; // assert chunk_len > 0 int chunk_len = context->data[context->offset]; - if (chunk_len == 0) return 0; + if (chunk_len == 0) return false; // assert complete chunk fits into buffer - if ((context->offset + 1 + chunk_len) > context->length) return 0; + if ((context->offset + 1 + chunk_len) > context->length) return false; - return 1; + return true; } // pre: ad_iterator_has_more() == 1 @@ -95,7 +95,7 @@ const uint8_t * ad_iterator_get_data(const ad_context_t * context){ return &context->data[context->offset + 2]; } -int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid16){ +bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid16){ ad_context_t context; for (ad_iterator_init(&context, ad_len, ad_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){ uint8_t data_type = ad_iterator_get_data_type(&context); @@ -110,7 +110,7 @@ int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uu case BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS: for (i=0; i #if defined __cplusplus @@ -61,7 +63,7 @@ typedef struct ad_context { // Advertising or Scan Response data iterator void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_data); -int ad_iterator_has_more(const ad_context_t * context); +bool ad_iterator_has_more(const ad_context_t * context); void ad_iterator_next(ad_context_t * context); // Access functions @@ -70,8 +72,8 @@ uint8_t ad_iterator_get_data_len(const ad_context_t * context); const uint8_t * ad_iterator_get_data(const ad_context_t * context); // convenience function on complete advertisements -int ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid); -int ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128); +bool ad_data_contains_uuid16(uint8_t ad_len, const uint8_t * ad_data, uint16_t uuid); +bool ad_data_contains_uuid128(uint8_t ad_len, const uint8_t * ad_data, const uint8_t * uuid128); /* API_END */