Skip to content
Snippets Groups Projects
Commit d6d9d669 authored by Hauke Petersen's avatar Hauke Petersen
Browse files

examples/nimble_gatt: use bluetil_ad

parent 23abc896
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ RIOTBASE ?= $(CURDIR)/../.. ...@@ -13,6 +13,9 @@ RIOTBASE ?= $(CURDIR)/../..
# Include NimBLE # Include NimBLE
USEPKG += nimble USEPKG += nimble
# We also use the AD part of the BLE helper module
USEMODULE += bluetil_ad
# Comment this out to disable code in RIOT that does safety checking # Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the # which is not needed in a production environment but helps in the
# development process: # development process:
......
...@@ -23,39 +23,26 @@ ...@@ -23,39 +23,26 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "net/bluetil/ad.h"
#include "host/ble_hs.h" #include "host/ble_hs.h"
#include "host/util/util.h" #include "host/util/util.h"
#include "host/ble_gatt.h" #include "host/ble_gatt.h"
#include "services/gap/ble_svc_gap.h" #include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h" #include "services/gatt/ble_svc_gatt.h"
static const char device_name[] = "NimBLE on RIOT"; static const char *device_name = "NimBLE on RIOT";
static uint8_t own_addr_type; static uint8_t own_addr_type;
static void start_advertise(void); static void start_advertise(void);
static void put_ad(uint8_t ad_type, uint8_t ad_len, const void *ad, uint8_t *buf,
uint8_t *len)
{
buf[(*len)++] = ad_len + 1;
buf[(*len)++] = ad_type;
memcpy(&buf[*len], ad, ad_len);
*len += ad_len;
}
static void update_ad(void) static void update_ad(void)
{ {
uint8_t ad[BLE_HS_ADV_MAX_SZ]; uint8_t buf[BLE_HS_ADV_MAX_SZ];
uint8_t ad_len = 0; bluetil_ad_t ad;
uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; bluetil_ad_init_with_flags(&ad, buf, sizeof(buf), BLUETIL_AD_FLAGS_DEFAULT);
bluetil_ad_add_name(&ad, device_name);
put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len); ble_gap_adv_set_data(ad.buf, ad.pos);
put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(device_name), device_name, ad, &ad_len);
ble_gap_adv_set_data(ad, ad_len);
} }
static int gap_event_cb(struct ble_gap_event *event, void *arg) static int gap_event_cb(struct ble_gap_event *event, void *arg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment