BLE: reception support multiple service data (#3502)
* BLE: reception support multiple service data * fix prev commit, i not inicialized
This commit is contained in:
parent
36075257c2
commit
85ef51ffbc
@ -25,7 +25,8 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
|
|||||||
m_manufacturerData = "";
|
m_manufacturerData = "";
|
||||||
m_name = "";
|
m_name = "";
|
||||||
m_rssi = -9999;
|
m_rssi = -9999;
|
||||||
m_serviceData = "";
|
m_serviceData = {};
|
||||||
|
m_serviceDataUUIDs = {};
|
||||||
m_txPower = 0;
|
m_txPower = 0;
|
||||||
m_pScan = nullptr;
|
m_pScan = nullptr;
|
||||||
|
|
||||||
@ -101,33 +102,66 @@ BLEScan* BLEAdvertisedDevice::getScan() {
|
|||||||
return m_pScan;
|
return m_pScan;
|
||||||
} // getScan
|
} // getScan
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the number of service data.
|
||||||
|
* @return Number of service data discovered.
|
||||||
|
*/
|
||||||
|
int BLEAdvertisedDevice::getServiceDataCount() {
|
||||||
|
if (m_haveServiceData)
|
||||||
|
return m_serviceData.size();
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} //getServiceDataCount
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the service data.
|
* @brief Get the service data.
|
||||||
* @return The ServiceData of the advertised device.
|
* @return The ServiceData of the advertised device.
|
||||||
*/
|
*/
|
||||||
std::string BLEAdvertisedDevice::getServiceData() {
|
std::string BLEAdvertisedDevice::getServiceData() {
|
||||||
return m_serviceData;
|
return m_serviceData[0];
|
||||||
} //getServiceData
|
} //getServiceData
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the service data.
|
||||||
|
* @return The ServiceData of the advertised device.
|
||||||
|
*/
|
||||||
|
std::string BLEAdvertisedDevice::getServiceData(int i) {
|
||||||
|
return m_serviceData[i];
|
||||||
|
} //getServiceData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the service data UUID.
|
* @brief Get the service data UUID.
|
||||||
* @return The service data UUID.
|
* @return The service data UUID.
|
||||||
*/
|
*/
|
||||||
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
|
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
|
||||||
return m_serviceDataUUID;
|
return m_serviceDataUUIDs[0];
|
||||||
} // getServiceDataUUID
|
} // getServiceDataUUID
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the service data UUID.
|
||||||
|
* @return The service data UUID.
|
||||||
|
*/
|
||||||
|
BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
|
||||||
|
return m_serviceDataUUIDs[i];
|
||||||
|
} // getServiceDataUUID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the Service UUID.
|
* @brief Get the Service UUID.
|
||||||
* @return The Service UUID of the advertised device.
|
* @return The Service UUID of the advertised device.
|
||||||
*/
|
*/
|
||||||
BLEUUID BLEAdvertisedDevice::getServiceUUID() { //TODO Remove it eventually, is no longer useful
|
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
|
||||||
return m_serviceUUIDs[0];
|
return m_serviceUUIDs[0];
|
||||||
} // getServiceUUID
|
} // getServiceUUID
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Service UUID.
|
||||||
|
* @return The Service UUID of the advertised device.
|
||||||
|
*/
|
||||||
|
BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
|
||||||
|
return m_serviceUUIDs[i];
|
||||||
|
} // getServiceUUID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check advertised serviced for existence required UUID
|
* @brief Check advertised serviced for existence required UUID
|
||||||
* @return Return true if service is advertised
|
* @return Return true if service is advertised
|
||||||
@ -454,7 +488,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
|
|||||||
*/
|
*/
|
||||||
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
||||||
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
||||||
m_serviceData = serviceData; // Save the service data that we received.
|
m_serviceData.push_back(serviceData); // Save the service data that we received.
|
||||||
} //setServiceData
|
} //setServiceData
|
||||||
|
|
||||||
|
|
||||||
@ -464,7 +498,8 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
|
|||||||
*/
|
*/
|
||||||
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
|
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
|
||||||
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
m_haveServiceData = true; // Set the flag that indicates we have service data.
|
||||||
m_serviceDataUUID = uuid;
|
m_serviceDataUUIDs.push_back(uuid);
|
||||||
|
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
|
||||||
} // setServiceDataUUID
|
} // setServiceDataUUID
|
||||||
|
|
||||||
|
|
||||||
@ -498,7 +533,9 @@ std::string BLEAdvertisedDevice::toString() {
|
|||||||
free(pHex);
|
free(pHex);
|
||||||
}
|
}
|
||||||
if (haveServiceUUID()) {
|
if (haveServiceUUID()) {
|
||||||
res += ", serviceUUID: " + getServiceUUID().toString();
|
for (int i=0; i < m_serviceUUIDs.size(); i++) {
|
||||||
|
res += ", serviceUUID: " + getServiceUUID(i).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (haveTXPower()) {
|
if (haveTXPower()) {
|
||||||
char val[4];
|
char val[4];
|
||||||
|
@ -36,8 +36,12 @@ public:
|
|||||||
int getRSSI();
|
int getRSSI();
|
||||||
BLEScan* getScan();
|
BLEScan* getScan();
|
||||||
std::string getServiceData();
|
std::string getServiceData();
|
||||||
|
std::string getServiceData(int i);
|
||||||
BLEUUID getServiceDataUUID();
|
BLEUUID getServiceDataUUID();
|
||||||
|
BLEUUID getServiceDataUUID(int i);
|
||||||
BLEUUID getServiceUUID();
|
BLEUUID getServiceUUID();
|
||||||
|
BLEUUID getServiceUUID(int i);
|
||||||
|
int getServiceDataCount();
|
||||||
int8_t getTXPower();
|
int8_t getTXPower();
|
||||||
uint8_t* getPayload();
|
uint8_t* getPayload();
|
||||||
size_t getPayloadLength();
|
size_t getPayloadLength();
|
||||||
@ -93,8 +97,8 @@ private:
|
|||||||
int m_rssi;
|
int m_rssi;
|
||||||
std::vector<BLEUUID> m_serviceUUIDs;
|
std::vector<BLEUUID> m_serviceUUIDs;
|
||||||
int8_t m_txPower;
|
int8_t m_txPower;
|
||||||
std::string m_serviceData;
|
std::vector<std::string> m_serviceData;
|
||||||
BLEUUID m_serviceDataUUID;
|
std::vector<BLEUUID> m_serviceDataUUIDs;
|
||||||
uint8_t* m_payload;
|
uint8_t* m_payload;
|
||||||
size_t m_payloadLength = 0;
|
size_t m_payloadLength = 0;
|
||||||
esp_ble_addr_type_t m_addressType;
|
esp_ble_addr_type_t m_addressType;
|
||||||
|
Loading…
Reference in New Issue
Block a user