mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-28 19:20:54 +00:00
use new gap le advertisement functions for Arduino wrapper
This commit is contained in:
parent
cfc59f1b60
commit
9520fec5f4
@ -26,6 +26,7 @@
|
|||||||
#include "att_db_util.h"
|
#include "att_db_util.h"
|
||||||
#include "le_device_db.h"
|
#include "le_device_db.h"
|
||||||
#include "sm.h"
|
#include "sm.h"
|
||||||
|
#include "gap_le.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
// Pin 13 has an LED connected on most Arduino boards.
|
// Pin 13 has an LED connected on most Arduino boards.
|
||||||
@ -59,7 +60,6 @@ static const uint8_t iBeaconAdvertisement01[] = { 0x02, 0x01 };
|
|||||||
static const uint8_t iBeaconAdvertisement38[] = { 0x1a, 0xff, 0x4c, 0x00, 0x02, 0x15 };
|
static const uint8_t iBeaconAdvertisement38[] = { 0x1a, 0xff, 0x4c, 0x00, 0x02, 0x15 };
|
||||||
static uint8_t adv_data[31];
|
static uint8_t adv_data[31];
|
||||||
static uint16_t adv_data_len = 0;
|
static uint16_t adv_data_len = 0;
|
||||||
static int adv_enabled = 0;
|
|
||||||
static uint16_t gatt_client_id;
|
static uint16_t gatt_client_id;
|
||||||
static int gatt_is_characteristics_query;
|
static int gatt_is_characteristics_query;
|
||||||
|
|
||||||
@ -236,37 +236,6 @@ static void gatt_client_callback(le_event_t * event){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void le_peripheral_run(void){
|
|
||||||
|
|
||||||
if (!hci_can_send_command_packet_now()) return;
|
|
||||||
|
|
||||||
if (le_peripheral_todos & SET_ADVERTISEMENT_DATA){
|
|
||||||
printf("le_peripheral_run: set advertisement data\n");
|
|
||||||
le_peripheral_todos &= ~SET_ADVERTISEMENT_DATA;
|
|
||||||
hci_send_cmd(&hci_le_set_advertising_data, adv_data_len, adv_data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (le_peripheral_todos & SET_ADVERTISEMENT_PARAMS){
|
|
||||||
printf("le_peripheral_run: set advertisement params\n");
|
|
||||||
le_peripheral_todos &= ~SET_ADVERTISEMENT_PARAMS;
|
|
||||||
uint8_t adv_type = 0; // default
|
|
||||||
bd_addr_t null_addr;
|
|
||||||
memset(null_addr, 0, 6);
|
|
||||||
uint16_t adv_int_min = 0x0030;
|
|
||||||
uint16_t adv_int_max = 0x0030;
|
|
||||||
hci_send_cmd(&hci_le_set_advertising_parameters, adv_int_min, adv_int_max, adv_type, 0, 0, &null_addr, 0x07, 0x00);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (le_peripheral_todos & SET_ADVERTISEMENT_ENABLED) {
|
|
||||||
printf("le_peripheral_run: enable advertisements\n");
|
|
||||||
le_peripheral_todos &= ~SET_ADVERTISEMENT_ENABLED;
|
|
||||||
hci_send_cmd(&hci_le_set_advertise_enable, adv_enabled);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void connection_timeout_handler(timer_source_t * timer){
|
static void connection_timeout_handler(timer_source_t * timer){
|
||||||
// log_info("Cancel outgoing connection");
|
// log_info("Cancel outgoing connection");
|
||||||
le_central_connect_cancel();
|
le_central_connect_cancel();
|
||||||
@ -569,20 +538,11 @@ BTstackManager::BTstackManager(void){
|
|||||||
gattCharacteristicDiscoveredCallback = NULL;
|
gattCharacteristicDiscoveredCallback = NULL;
|
||||||
gattCharacteristicNotificationCallback = NULL;
|
gattCharacteristicNotificationCallback = NULL;
|
||||||
|
|
||||||
// setup adv data
|
|
||||||
int pos = 0;
|
|
||||||
const uint8_t flags[] = { 0x02, 0x01, 0x02 };
|
|
||||||
memcpy(&adv_data[pos], flags, sizeof(flags));
|
|
||||||
pos += sizeof(flags);
|
|
||||||
char * name = "BTstack LE Shield";
|
|
||||||
adv_data[pos++] = strlen(name) + 1;
|
|
||||||
adv_data[pos++] = 0x09;
|
|
||||||
memcpy(&adv_data[pos], name, strlen(name));
|
|
||||||
pos += strlen(name);
|
|
||||||
adv_data_len = pos;
|
|
||||||
|
|
||||||
att_db_util_init();
|
att_db_util_init();
|
||||||
|
|
||||||
|
// disable LOG_INFO messages
|
||||||
|
hci_dump_enable_log_level(LOG_LEVEL_INFO, 0);
|
||||||
|
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
// configure stdout to go via Serial
|
// configure stdout to go via Serial
|
||||||
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
fdev_setup_stream (&uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
@ -716,9 +676,6 @@ void BTstackManager::setup(void){
|
|||||||
bt_control_t * control = bt_control_em9301_instance();
|
bt_control_t * control = bt_control_em9301_instance();
|
||||||
hci_init(transport, NULL, control, NULL);
|
hci_init(transport, NULL, control, NULL);
|
||||||
|
|
||||||
// disable LOG_INFO messages
|
|
||||||
hci_dump_enable_log_level(LOG_LEVEL_INFO, 0);
|
|
||||||
|
|
||||||
if (have_custom_addr){
|
if (have_custom_addr){
|
||||||
hci_set_bd_addr(public_bd_addr);
|
hci_set_bd_addr(public_bd_addr);
|
||||||
}
|
}
|
||||||
@ -738,6 +695,27 @@ void BTstackManager::setup(void){
|
|||||||
gatt_client_init();
|
gatt_client_init();
|
||||||
gatt_client_id = gatt_client_register_packet_handler(gatt_client_callback);
|
gatt_client_id = gatt_client_register_packet_handler(gatt_client_callback);
|
||||||
|
|
||||||
|
// setup advertisements params
|
||||||
|
uint16_t adv_int_min = 0x0030;
|
||||||
|
uint16_t adv_int_max = 0x0030;
|
||||||
|
uint8_t adv_type = 0;
|
||||||
|
bd_addr_t null_addr;
|
||||||
|
memset(null_addr, 0, 6);
|
||||||
|
gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
|
||||||
|
|
||||||
|
// setup advertisements data
|
||||||
|
int pos = 0;
|
||||||
|
const uint8_t flags[] = { 0x02, 0x01, 0x02 };
|
||||||
|
memcpy(&adv_data[pos], flags, sizeof(flags));
|
||||||
|
pos += sizeof(flags);
|
||||||
|
char * name = "BTstack LE Shield";
|
||||||
|
adv_data[pos++] = strlen(name) + 1;
|
||||||
|
adv_data[pos++] = 0x09;
|
||||||
|
memcpy(&adv_data[pos], name, strlen(name));
|
||||||
|
pos += strlen(name);
|
||||||
|
adv_data_len = pos;
|
||||||
|
gap_advertisements_set_data(adv_data_len, adv_data);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
btstack_state = 0;
|
btstack_state = 0;
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
||||||
@ -763,9 +741,6 @@ void BTstackManager::loop(void){
|
|||||||
hal_uart_dma_process();
|
hal_uart_dma_process();
|
||||||
// BTstack Run Loop
|
// BTstack Run Loop
|
||||||
embedded_execute_once();
|
embedded_execute_once();
|
||||||
|
|
||||||
// manage advertisements
|
|
||||||
le_peripheral_run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTstackManager::bleStartScanning(void){
|
void BTstackManager::bleStartScanning(void){
|
||||||
@ -794,26 +769,15 @@ uint16_t BTstackManager::addGATTCharacteristic(UUID * uuid, uint16_t flags, uint
|
|||||||
uint16_t BTstackManager::addGATTCharacteristicDynamic(UUID * uuid, uint16_t flags, uint16_t characteristic_id){
|
uint16_t BTstackManager::addGATTCharacteristicDynamic(UUID * uuid, uint16_t flags, uint16_t characteristic_id){
|
||||||
return att_db_util_add_characteristic_uuid128((uint8_t*)uuid->getUuid(), flags | ATT_PROPERTY_DYNAMIC, NULL, 0);
|
return att_db_util_add_characteristic_uuid128((uint8_t*)uuid->getUuid(), flags | ATT_PROPERTY_DYNAMIC, NULL, 0);
|
||||||
}
|
}
|
||||||
void BTstackManager::setAdvData(uint16_t size, const uint8_t * data){
|
void BTstackManager::setAdvData(uint16_t adv_data_len, const uint8_t * adv_data){
|
||||||
memcpy(adv_data, data, size);
|
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
|
||||||
adv_data_len = size;
|
|
||||||
if (btstack_state == HCI_STATE_WORKING){
|
|
||||||
le_peripheral_todos |= SET_ADVERTISEMENT_DATA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void BTstackManager::startAdvertising(){
|
void BTstackManager::startAdvertising(){
|
||||||
adv_enabled = 1;
|
gap_advertisements_enable(1);
|
||||||
if (btstack_state == HCI_STATE_WORKING){
|
|
||||||
le_peripheral_todos |= SET_ADVERTISEMENT_DATA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void BTstackManager::stopAdvertising(){
|
void BTstackManager::stopAdvertising(){
|
||||||
adv_enabled = 0;
|
gap_advertisements_enable(0);
|
||||||
if (btstack_state == HCI_STATE_WORKING){
|
|
||||||
le_peripheral_todos |= SET_ADVERTISEMENT_DATA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTstackManager::iBeaconConfigure(UUID * uuid, uint16_t major_id, uint16_t minor_id, uint8_t measured_power){
|
void BTstackManager::iBeaconConfigure(UUID * uuid, uint16_t major_id, uint16_t minor_id, uint8_t measured_power){
|
||||||
memcpy(adv_data, iBeaconAdvertisement01, sizeof(iBeaconAdvertisement01));
|
memcpy(adv_data, iBeaconAdvertisement01, sizeof(iBeaconAdvertisement01));
|
||||||
adv_data[2] = 0x06;
|
adv_data[2] = 0x06;
|
||||||
@ -823,9 +787,7 @@ void BTstackManager::iBeaconConfigure(UUID * uuid, uint16_t major_id, uint16_t m
|
|||||||
net_store_16(adv_data, 27, minor_id);
|
net_store_16(adv_data, 27, minor_id);
|
||||||
adv_data[29] = measured_power;
|
adv_data[29] = measured_power;
|
||||||
adv_data_len = 30;
|
adv_data_len = 30;
|
||||||
if (btstack_state == HCI_STATE_WORKING){
|
gap_advertisements_set_data(adv_data_len, adv_data);
|
||||||
le_peripheral_todos |= SET_ADVERTISEMENT_DATA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 02 01 06 1A FF 4C 00 02 15 -- F8 97 17 7B AE E8 47 67 8E CC CC 69 4F D5 FC EE -- 12 67 00 02 00 00
|
// 02 01 06 1A FF 4C 00 02 15 -- F8 97 17 7B AE E8 47 67 8E CC CC 69 4F D5 FC EE -- 12 67 00 02 00 00
|
||||||
// 02 01 06 1a ff 4c 00 02 15 -- FB 0B 57 A2 82 28 44 CD 91 3A 94 A1 22 BA 12 06 -- 00 01 00 02 D1 00
|
// 02 01 06 1a ff 4c 00 02 15 -- FB 0B 57 A2 82 28 44 CD 91 3A 94 A1 22 BA 12 06 -- 00 01 00 02 D1 00
|
||||||
|
Loading…
x
Reference in New Issue
Block a user