Skip to content

Alter library so it can handle multiple service data #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/BLEAdvertisedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
m_manufacturerData = "";
m_name = "";
m_rssi = -9999;
m_serviceData = "";
m_txPower = 0;
m_pScan = nullptr;

Expand Down Expand Up @@ -106,30 +105,42 @@ BLEScan* BLEAdvertisedDevice::getScan() {
} // getScan


/**
* @brief Get the number of service data.
* @return Number of service data discovered.
*/
int BLEAdvertisedDevice::getServiceDataCount() {
if (m_haveServiceData)
return m_serviceDataVector.size();
else
return 0;

} //getServiceDataCount

/**
* @brief Get the service data.
* @return The ServiceData of the advertised device.
*/
std::string BLEAdvertisedDevice::getServiceData() {
return m_serviceData;
std::string BLEAdvertisedDevice::getServiceData(int i) {
return m_serviceDataVector[i];
} //getServiceData


/**
* @brief Get the service data UUID.
* @return The service data UUID.
*/
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
return m_serviceDataUUID;
BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
return m_serviceDataUUIDs[i];
} // getServiceDataUUID


/**
* @brief Get the Service UUID.
* @return The Service UUID of the advertised device.
*/
BLEUUID BLEAdvertisedDevice::getServiceUUID() { //TODO Remove it eventually, is no longer useful
return m_serviceUUIDs[0];
BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
return m_serviceUUIDs[i];
} // getServiceUUID

/**
Expand Down Expand Up @@ -458,7 +469,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
*/
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
m_haveServiceData = true; // Set the flag that indicates we have service data.
m_serviceData = serviceData; // Save the service data that we received.
m_serviceDataVector.push_back(serviceData); // Save the service data that we received.
} //setServiceData


Expand All @@ -468,7 +479,8 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
*/
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
m_haveServiceData = true; // Set the flag that indicates we have service data.
m_serviceDataUUID = uuid;
m_serviceDataUUIDs.push_back(uuid);
ESP_LOGD(LOG_TAG, "- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
} // setServiceDataUUID


Expand Down Expand Up @@ -499,7 +511,9 @@ std::string BLEAdvertisedDevice::toString() {
free(pHex);
}
if (haveServiceUUID()) {
ss << ", serviceUUID: " << getServiceUUID().toString();
for (int i; i < m_serviceUUIDs.size(); i++) {
ss << ", serviceUUID: " << getServiceUUID(i).toString();
}
}
if (haveTXPower()) {
ss << ", txPower: " << (int)getTXPower();
Expand Down
13 changes: 7 additions & 6 deletions src/BLEAdvertisedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class BLEAdvertisedDevice {
std::string getName();
int getRSSI();
BLEScan* getScan();
std::string getServiceData();
BLEUUID getServiceDataUUID();
BLEUUID getServiceUUID();
std::string getServiceData(int i);
BLEUUID getServiceDataUUID(int i);
BLEUUID getServiceUUID(int i);
int getServiceDataCount();
int8_t getTXPower();
uint8_t* getPayload();

Expand Down Expand Up @@ -91,9 +92,9 @@ class BLEAdvertisedDevice {
BLEScan* m_pScan;
int m_rssi;
std::vector<BLEUUID> m_serviceUUIDs;
int8_t m_txPower;
std::string m_serviceData;
BLEUUID m_serviceDataUUID;
std::vector<BLEUUID> m_serviceDataUUIDs;
std::vector<std::string> m_serviceDataVector;
int8_t m_txPower;
uint8_t* m_payload;
};

Expand Down