1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/nimble_gatt: use bluetil_ad

This commit is contained in:
Hauke Petersen 2018-12-07 18:05:00 +01:00
parent 23abc89675
commit d6d9d66972
2 changed files with 11 additions and 21 deletions

View File

@ -13,6 +13,9 @@ RIOTBASE ?= $(CURDIR)/../..
# Include 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
# which is not needed in a production environment but helps in the
# development process:

View File

@ -23,39 +23,26 @@
#include <stdio.h>
#include <string.h>
#include "net/bluetil/ad.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
#include "host/ble_gatt.h"
#include "services/gap/ble_svc_gap.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 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)
{
uint8_t ad[BLE_HS_ADV_MAX_SZ];
uint8_t ad_len = 0;
uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len);
put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(device_name), device_name, ad, &ad_len);
ble_gap_adv_set_data(ad, ad_len);
uint8_t buf[BLE_HS_ADV_MAX_SZ];
bluetil_ad_t ad;
bluetil_ad_init_with_flags(&ad, buf, sizeof(buf), BLUETIL_AD_FLAGS_DEFAULT);
bluetil_ad_add_name(&ad, device_name);
ble_gap_adv_set_data(ad.buf, ad.pos);
}
static int gap_event_cb(struct ble_gap_event *event, void *arg)