forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved iBeacon logic from example into separate iBeacon class.
- Loading branch information
1 parent
042730a
commit 6d906be
Showing
3 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#if defined(NRF51) || defined(__RFduino__) | ||
|
||
#include <BLEUuid.h> | ||
|
||
#include "iBeacon.h" | ||
|
||
void iBeacon::setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower) { | ||
unsigned char manufacturerData[MAX_UUID_LENGTH + 9]; // 4 bytes of header and 5 bytes of trailer. | ||
BLEUuid uuid(uuidString); | ||
int i = 0; | ||
|
||
// 0x004c = Apple, see https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers | ||
manufacturerData[i++] = 0x4c; // Apple Company Identifier LE (16 bit) | ||
manufacturerData[i++] = 0x00; | ||
|
||
// See "Beacon type" in "Building Applications with IBeacon". | ||
manufacturerData[i++] = 0x02; | ||
manufacturerData[i++] = uuid.length() + 5; | ||
|
||
for (int j = (uuid.length() - 1); j >= 0; j--) { | ||
manufacturerData[i++] = uuid.data()[j]; | ||
} | ||
|
||
manufacturerData[i++] = major >> 8; | ||
manufacturerData[i++] = major; | ||
manufacturerData[i++] = minor >> 8; | ||
manufacturerData[i++] = minor; | ||
manufacturerData[i++] = measuredPower; | ||
|
||
peripheral.setManufacturerData(manufacturerData, i); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _I_BEACON_H_ | ||
#define _I_BEACON_H_ | ||
|
||
#if defined(NRF51) || !defined(__RFduino__) | ||
|
||
#include "BLEPeripheral.h" | ||
|
||
class iBeacon | ||
{ | ||
public: | ||
static void setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower); | ||
}; | ||
|
||
#endif | ||
|
||
#endif |