mirror of
https://github.com/Smartphone-Companions/ESP32-ANCS-Notifications.git
synced 2025-01-22 11:28:29 +00:00
#7 fixed. Patched the setServiceSolicitation method from nkolban's libraries into this library, since it is missing from the Espressif core libs.
This commit is contained in:
parent
932fd85f04
commit
e1b8467e12
@ -1,6 +1,11 @@
|
||||
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
|
||||
|
||||
// NKolban's original library has a setServiceSolicitation method. As of writing, this is not in the
|
||||
// Espressif core libs. If you are using NKolban's branch of the library, or if this moves into
|
||||
// the core libraries eventually, uncomment this.
|
||||
//#define BLE_LIB_HAS_SERVICE_SOLICITATION
|
||||
|
||||
#include "esp32notifications.h"
|
||||
#include "ancs_ble_client.h"
|
||||
#include "ble_security.h"
|
||||
@ -18,6 +23,11 @@ static char LOG_TAG[] = "BLENotifications";
|
||||
|
||||
extern const BLEUUID ancsServiceUUID;
|
||||
|
||||
#ifndef BLE_LIB_HAS_SERVICE_SOLICITATION
|
||||
// Use a static function, instead of doing a whole private implementation just for a this one small patch.
|
||||
static void setServiceSolicitation(class BLEAdvertisementData & advertisementData, BLEUUID uuid);
|
||||
#endif
|
||||
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
private:
|
||||
struct gatts_connect_evt_param { // @todo include from sdk/include/bt/esp_gatts_api.h
|
||||
@ -144,7 +154,13 @@ void BLENotifications::startAdvertising() {
|
||||
|
||||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
|
||||
oAdvertisementData.setFlags(0x01);
|
||||
|
||||
#ifdef BLE_LIB_HAS_SERVICE_SOLICITATION
|
||||
oAdvertisementData.setServiceSolicitation(ANCSBLEClient::getAncsServiceUUID());
|
||||
#else
|
||||
setServiceSolicitation(oAdvertisementData, ANCSBLEClient::getAncsServiceUUID());
|
||||
#endif
|
||||
|
||||
pAdvertising->setAdvertisementData(oAdvertisementData);
|
||||
|
||||
// Set security
|
||||
@ -159,3 +175,30 @@ void BLENotifications::startAdvertising() {
|
||||
}
|
||||
|
||||
|
||||
#ifndef BLE_LIB_HAS_SERVICE_SOLICITATION
|
||||
void setServiceSolicitation(BLEAdvertisementData & advertisementData, BLEUUID uuid)
|
||||
{
|
||||
char cdata[2];
|
||||
switch(uuid.bitSize()) {
|
||||
case 16: {
|
||||
// [Len] [0x14] [UUID16] data
|
||||
cdata[0] = 3;
|
||||
cdata[1] = ESP_BLE_AD_TYPE_SOL_SRV_UUID; // 0x14
|
||||
advertisementData.addData(std::string(cdata, 2) + std::string((char *)&uuid.getNative()->uuid.uuid16,2));
|
||||
break;
|
||||
}
|
||||
|
||||
case 128: {
|
||||
// [Len] [0x15] [UUID128] data
|
||||
cdata[0] = 17;
|
||||
cdata[1] = ESP_BLE_AD_TYPE_128SOL_SRV_UUID; // 0x15
|
||||
advertisementData.addData(std::string(cdata, 2) + std::string((char *)uuid.getNative()->uuid.uuid128,16));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -71,6 +71,8 @@ class BLENotifications {
|
||||
*/
|
||||
const char * getNotificationCategoryDescription(NotificationCategory category) const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
private:
|
||||
ble_notifications_state_changed_t cbStateChanged;
|
||||
|
Loading…
Reference in New Issue
Block a user