mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 05:00:55 +01:00
Bugfixes + add new NimBLEUUID constructor.
This commit is contained in:
parent
725807b619
commit
1779a3f723
8 changed files with 42 additions and 35 deletions
|
@ -59,9 +59,9 @@ NimBLEAddress::NimBLEAddress(std::string stringAddress) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructor for compatibility with bluedrioid esp library.
|
* @brief Constructor for compatibility with bluedrioid esp library.
|
||||||
* @param [in] esp_bd_addr_t struct containing the address.
|
* @param [in] uint8_t[6] or esp_bd_addr_t struct containing the address.
|
||||||
*/
|
*/
|
||||||
NimBLEAddress::NimBLEAddress(esp_bd_addr_t address) {
|
NimBLEAddress::NimBLEAddress(uint8_t address[6]) {
|
||||||
NimBLEUtils::memrcpy(m_address, address, 6);
|
NimBLEUtils::memrcpy(m_address, address, 6);
|
||||||
} // NimBLEAddress
|
} // NimBLEAddress
|
||||||
|
|
||||||
|
|
|
@ -25,22 +25,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BLE_ADDR_TYPE_PUBLIC = 0x00,
|
|
||||||
BLE_ADDR_TYPE_RANDOM = 0x01,
|
|
||||||
BLE_ADDR_TYPE_RPA_PUBLIC = 0x02,
|
|
||||||
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
|
|
||||||
} esp_nimble_addr_type_t;
|
|
||||||
|
|
||||||
typedef uint8_t esp_ble_addr_type_t ;
|
|
||||||
|
|
||||||
/// Bluetooth address length
|
|
||||||
#define ESP_BD_ADDR_LEN 6
|
|
||||||
|
|
||||||
/// Bluetooth device address
|
|
||||||
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A %BLE device address.
|
* @brief A %BLE device address.
|
||||||
*
|
*
|
||||||
|
@ -49,7 +33,7 @@ typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
|
||||||
class NimBLEAddress {
|
class NimBLEAddress {
|
||||||
public:
|
public:
|
||||||
NimBLEAddress(ble_addr_t address);
|
NimBLEAddress(ble_addr_t address);
|
||||||
NimBLEAddress(esp_bd_addr_t address);
|
NimBLEAddress(uint8_t address[6]);
|
||||||
NimBLEAddress(std::string stringAddress);
|
NimBLEAddress(std::string stringAddress);
|
||||||
bool equals(NimBLEAddress otherAddress);
|
bool equals(NimBLEAddress otherAddress);
|
||||||
uint8_t* getNative();
|
uint8_t* getNative();
|
||||||
|
|
|
@ -74,7 +74,7 @@ NimBLEClient::~NimBLEClient() {
|
||||||
// Before we are finished with the client, we must release resources.
|
// Before we are finished with the client, we must release resources.
|
||||||
clearServices();
|
clearServices();
|
||||||
|
|
||||||
if(m_deleteCallbacks) {
|
if(m_deleteCallbacks && m_pClientCallbacks != &defaultCallbacks) {
|
||||||
delete m_pClientCallbacks;
|
delete m_pClientCallbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class NimBLEAdvertisedDevice;
|
||||||
class NimBLEClient {
|
class NimBLEClient {
|
||||||
public:
|
public:
|
||||||
bool connect(NimBLEAdvertisedDevice* device, bool refreshServices = true);
|
bool connect(NimBLEAdvertisedDevice* device, bool refreshServices = true);
|
||||||
bool connect(NimBLEAddress address, uint8_t type = BLE_ADDR_TYPE_PUBLIC, bool refreshServices = true); // Connect to the remote BLE Server
|
bool connect(NimBLEAddress address, uint8_t type = BLE_ADDR_PUBLIC, bool refreshServices = true); // Connect to the remote BLE Server
|
||||||
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); // Disconnect from the remote BLE Server
|
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); // Disconnect from the remote BLE Server
|
||||||
NimBLEAddress getPeerAddress(); // Get the address of the remote BLE Server
|
NimBLEAddress getPeerAddress(); // Get the address of the remote BLE Server
|
||||||
int getRssi(); // Get the RSSI of the remote BLE Server
|
int getRssi(); // Get the RSSI of the remote BLE Server
|
||||||
|
|
|
@ -379,14 +379,16 @@ void NimBLEDevice::stopAdvertising() {
|
||||||
|
|
||||||
m_synced = true;
|
m_synced = true;
|
||||||
|
|
||||||
if(m_pScan != nullptr) {
|
if(initialized) {
|
||||||
// Restart scanning with the last values sent, allow to clear results.
|
if(m_pScan != nullptr) {
|
||||||
m_pScan->start(m_pScan->m_duration, m_pScan->m_scanCompleteCB);
|
// Restart scanning with the last values sent, allow to clear results.
|
||||||
}
|
m_pScan->start(m_pScan->m_duration, m_pScan->m_scanCompleteCB);
|
||||||
|
}
|
||||||
|
|
||||||
if(m_bleAdvertising != nullptr) {
|
if(m_bleAdvertising != nullptr) {
|
||||||
// Restart advertisng, parameters should already be set.
|
// Restart advertisng, parameters should already be set.
|
||||||
m_bleAdvertising->start();
|
m_bleAdvertising->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // onSync
|
} // onSync
|
||||||
|
|
||||||
|
@ -410,8 +412,6 @@ void NimBLEDevice::stopAdvertising() {
|
||||||
*/
|
*/
|
||||||
/* STATIC */ void NimBLEDevice::init(std::string deviceName) {
|
/* STATIC */ void NimBLEDevice::init(std::string deviceName) {
|
||||||
if(!initialized){
|
if(!initialized){
|
||||||
initialized = true; // Set the initialization flag to ensure we are only initialized once.
|
|
||||||
|
|
||||||
int rc=0;
|
int rc=0;
|
||||||
esp_err_t errRc = ESP_OK;
|
esp_err_t errRc = ESP_OK;
|
||||||
|
|
||||||
|
@ -459,7 +459,8 @@ void NimBLEDevice::stopAdvertising() {
|
||||||
while(!m_synced){
|
while(!m_synced){
|
||||||
vTaskDelay(1 / portTICK_PERIOD_MS);
|
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
//vTaskDelay(200 / portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue.
|
|
||||||
|
initialized = true; // Set the initialization flag to ensure we are only initialized once.
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
|
|
||||||
|
@ -477,6 +478,7 @@ void NimBLEDevice::stopAdvertising() {
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
m_synced = false;
|
||||||
}
|
}
|
||||||
} // deinit
|
} // deinit
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ NimBLEScan::NimBLEScan() {
|
||||||
|
|
||||||
if (pScan->m_pAdvertisedDeviceCallbacks) {
|
if (pScan->m_pAdvertisedDeviceCallbacks) {
|
||||||
// If not active scanning report the result to the listener.
|
// If not active scanning report the result to the listener.
|
||||||
if(pScan->m_scan_params.passive) {
|
if(pScan->m_scan_params.passive || event->disc.event_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) {
|
||||||
pScan->m_pAdvertisedDeviceCallbacks->onResult(advertisedDevice);
|
pScan->m_pAdvertisedDeviceCallbacks->onResult(advertisedDevice);
|
||||||
// Otherwise wait for the scan response so we can report all of the data at once.
|
// Otherwise wait for the scan response so we can report all of the data at once.
|
||||||
} else if (event->disc.event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
} else if (event->disc.event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
||||||
|
|
|
@ -156,6 +156,26 @@ NimBLEUUID::NimBLEUUID(ble_uuid128_t* uuid) {
|
||||||
} // NimBLEUUID
|
} // NimBLEUUID
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a UUID from the 128bit value using hex parts instead of string,
|
||||||
|
* instead of BLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes
|
||||||
|
* BLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)
|
||||||
|
*
|
||||||
|
* @param [in] first The first 32bit of the UUID.
|
||||||
|
* @param [in] second The next 16bit of the UUID.
|
||||||
|
* @param [in] third The next 16bit of the UUID.
|
||||||
|
* @param [in] fourth The last 64bit of the UUID, combining the last 2 parts of the string equivalent
|
||||||
|
*/
|
||||||
|
NimBLEUUID::NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth) {
|
||||||
|
m_uuid.u.type = BLE_UUID_TYPE_128;
|
||||||
|
memcpy(m_uuid.u128.value + 12, &first, 4);
|
||||||
|
memcpy(m_uuid.u128.value + 10, &second, 2);
|
||||||
|
memcpy(m_uuid.u128.value + 8, &third, 2);
|
||||||
|
memcpy(m_uuid.u128.value, &fourth, 8);
|
||||||
|
m_valueSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NimBLEUUID::NimBLEUUID() {
|
NimBLEUUID::NimBLEUUID() {
|
||||||
m_valueSet = false;
|
m_valueSet = false;
|
||||||
} // NimBLEUUID
|
} // NimBLEUUID
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
NimBLEUUID(uint32_t uuid);
|
NimBLEUUID(uint32_t uuid);
|
||||||
NimBLEUUID(ble_uuid128_t* uuid);
|
NimBLEUUID(ble_uuid128_t* uuid);
|
||||||
NimBLEUUID(uint8_t* pData, size_t size, bool msbFirst);
|
NimBLEUUID(uint8_t* pData, size_t size, bool msbFirst);
|
||||||
|
NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth);
|
||||||
NimBLEUUID();
|
NimBLEUUID();
|
||||||
uint8_t bitSize(); // Get the number of bits in this uuid.
|
uint8_t bitSize(); // Get the number of bits in this uuid.
|
||||||
bool equals(NimBLEUUID uuid);
|
bool equals(NimBLEUUID uuid);
|
||||||
|
|
Loading…
Reference in a new issue