8000 some small bugfixes · usmandroid/esp32-snippets@482f7b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 482f7b4

Browse files
committed
some small bugfixes
1 parent 874ce79 commit 482f7b4

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

cpp_utils/BLEAdvertisedDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ BLEUUID BLEAdvertisedDevice::getServiceUUID() { //TODO Remove it eventually, is
137137
* @return Return true if service is advertised
138138
*/
139139
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
140-
for (int i = 0; i < m_serviceUUIDs.size(); ++i) {
140+
for (int i = 0; i < m_serviceUUIDs.size(); i++) {
141141
if(m_serviceUUIDs[i].equals(uuid))
142142
return true;
143143
}

cpp_utils/BLERemoteService.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void BLERemoteService::gattClientEventHandler(
114114
} // switch
115115

116116
// Send the event to each of the characteristics owned by this service.
117-
for (auto &myPair : m_characteristicMap) {
117+
for (auto &myPair : m_characteristicMapByHandle) {
118118
myPair.second->gattClientEventHandler(event, gattc_if, evtParam);
119119
}
120120
} // gattClientEventHandler
@@ -206,7 +206,7 @@ void BLERemoteService::retrieveCharacteristics() {
206206
);
207207

208208
m_characteristicMap.insert(std::pair<std::string, BLERemoteCharacteristic*>(pNewRemoteCharacteristic->getUUID().toString(), pNewRemoteCharacteristic));
209-
209+
m_characteristicMapByHandle.insert(std::pair<uint16_t, BLERemoteCharacteristic*>(result.char_handle, pNewRemoteCharacteristic));
210210
offset++; // Increment our count of number of descriptors found.
211211
} // Loop forever (until we break inside the loop).
212212

@@ -231,6 +231,12 @@ std::map<std::string, BLERemoteCharacteristic *> * BLERemoteService::getCharacte
231231
return &m_characteristicMap;
232232
} // getCharacteristics
233233

234+
/**
235+
* @brief This function is designed to get characteristics map when we have multiple characteristics with the same UUID
236+
*/
237+
void BLERemoteService::getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap){
238+
pCharacteristicMap = &m_characteristicMapByHandle;
239+
} // Get the characteristics map.
234240

235241
/**
236242
* @brief Get the client associated with this service.
@@ -292,6 +298,10 @@ void BLERemoteService::removeCharacteristics() {
292298
//m_characteristicMap.erase(myPair.first); // Should be no need to delete as it will be deleted by the clear
293299
}
294300
m_characteristicMap.clear(); // Clear the map
301+
for (auto &myPair : m_characteristicMapByHandle) {
302+
delete myPair.second;
303+
}
304+
m_characteristicMapByHandle.clear(); // Clear the map
295305
} // removeCharacteristics
296306

297307

cpp_utils/tests/BLETests/Arduino/BLE_iBeacon/BLE_iBeacon.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void setBeacon() {
4949

5050
BLEBeacon oBeacon = BLEBeacon();
5151
oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!)
52-
oBeacon.setProximityUUID(BLEUUID(BEACON_UUID));
52+
oBeacon.setProximityUUID(BLEUUID(BEACON_UUID));
5353
oBeacon.setMajor((bootcount & 0xFFFF0000) >> 16);
5454
oBeacon.setMinor(bootcount&0xFFFF);
5555
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
@@ -84,10 +84,10 @@ void setup() {
8484
// Create the BLE Device
8585
BLEDevice::init("");
8686

87-
// Create the BLE Server
88-
BLEServer *pServer = BLEDevice::createServer();
87+
// Create the BLE Server is no longer required to crete beacon
88+
// BLEServer *pServer = BLEDevice::createServer();
8989

90-
pAdvertising = pServer->getAdvertising();
90+
pAdvertising = BLEDevice::getAdvertising();
9191

9292
setBeacon();
9393
// Start advertising

0 commit comments

Comments
 (0)
0