Skip to content

Add (optional) company ID argument to BLE.setManufacturerData(....) #18

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

Merged
merged 6 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions src/local/BLELocalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ void BLELocalDevice::setAdvertisedService(const BLEService& service)
setAdvertisedServiceUuid(service.uuid());
}

void BLELocalDevice::setManufacturerData(const uint8_t manufacturerData[], int manufacturerDataLength)
void BLELocalDevice::setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength)
{
GAP.setManufacturerData(manufacturerData, manufacturerDataLength);
GAP.setManufacturerData(companyId, manufacturerData, manufacturerDataLength);
}

void BLELocalDevice::setLocalName(const char *localName)
Expand Down
2 changes: 1 addition & 1 deletion src/local/BLELocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BLELocalDevice {

void setAdvertisedServiceUuid(const char* advertisedServiceUuid);
void setAdvertisedService(const BLEService& service);
void setManufacturerData(const uint8_t manufacturerData[], int manufacturerDataLength);
void setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to maintain backwards compatibility here and support both the newer and older API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing out the problem.
Please check new code.

void setLocalName(const char *localName);

void setDeviceName(const char* deviceName);
Expand Down
10 changes: 7 additions & 3 deletions src/utility/GAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ void GAPClass::setAdvertisedServiceUuid(const char* advertisedServiceUuid)
_advertisedServiceUuid = advertisedServiceUuid;
}

void GAPClass::setManufacturerData(const uint8_t manufacturerData[], int manufacturerDataLength)
void GAPClass::setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength)
{
_manufacturerData = manufacturerData;
_manufacturerDataLength = manufacturerDataLength;
uint8_t tmpManufacturerData[manufacturerDataLength + 2];
tmpManufacturerData[0] = companyId & 0xff;
tmpManufacturerData[1] = companyId >> 8;
memcpy(&tmpManufacturerData[2], manufacturerData, manufacturerDataLength);
_manufacturerData = tmpManufacturerData;
_manufacturerDataLength = manufacturerDataLength + 2;
}

void GAPClass::setLocalName(const char *localName)
Expand Down
2 changes: 1 addition & 1 deletion src/utility/GAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GAPClass {
virtual ~GAPClass();

void setAdvertisedServiceUuid(const char* advertisedServiceUuid);
void setManufacturerData(const uint8_t manufacturerData[], int manufacturerDataLength);
void setManufacturerData(const uint16_t companyId, const uint8_t manufacturerData[], int manufacturerDataLength);
void setLocalName(const char *localName);

bool advertising();
Expand Down