Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GAP_Example by
CustomAdvertisingPacket.h@1:0692bee84264, 2015-02-13 (annotated)
- Committer:
- mbedAustin
- Date:
- Fri Feb 13 20:59:53 2015 +0000
- Revision:
- 1:0692bee84264
Initial Commit of Evothings custom GAP example App
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbedAustin | 1:0692bee84264 | 1 | |
| mbedAustin | 1:0692bee84264 | 2 | #ifndef __BLE_EVOTHINGS_CUSTOM_GAP_H__ |
| mbedAustin | 1:0692bee84264 | 3 | #define __BLE_EVOTHINGS_CUSTOM_GAP_H__ |
| mbedAustin | 1:0692bee84264 | 4 | |
| mbedAustin | 1:0692bee84264 | 5 | #include "BLEDevice.h" // must include this |
| mbedAustin | 1:0692bee84264 | 6 | |
| mbedAustin | 1:0692bee84264 | 7 | /** |
| mbedAustin | 1:0692bee84264 | 8 | * @class iBeaconService |
| mbedAustin | 1:0692bee84264 | 9 | * @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<br> |
| mbedAustin | 1:0692bee84264 | 10 | */ |
| mbedAustin | 1:0692bee84264 | 11 | |
| mbedAustin | 1:0692bee84264 | 12 | class iBeaconService |
| mbedAustin | 1:0692bee84264 | 13 | { |
| mbedAustin | 1:0692bee84264 | 14 | public: |
| mbedAustin | 1:0692bee84264 | 15 | iBeaconService(BLEDevice &_ble, uint8_t proxUUID[16],uint16_t majNum,uint16_t minNum,uint8_t txP=0xC8, uint16_t compID=0x004C): |
| mbedAustin | 1:0692bee84264 | 16 | ble(_ble) |
| mbedAustin | 1:0692bee84264 | 17 | { |
| mbedAustin | 1:0692bee84264 | 18 | data.ID = 0x02; // Optional ID field |
| mbedAustin | 1:0692bee84264 | 19 | data.len = 0x15; // Len of remaining stuff (16B UUID, 2B Maj, 2B Min, 1B TxP) |
| mbedAustin | 1:0692bee84264 | 20 | data.majorNumber = ((majNum<<8) | (majNum >>8)); |
| mbedAustin | 1:0692bee84264 | 21 | data.minorNumber = ((minNum<<8) | (minNum >>8)); |
| mbedAustin | 1:0692bee84264 | 22 | data.txPower = txP; // The user should calibrate this to ~1meter fromt he device |
| mbedAustin | 1:0692bee84264 | 23 | data.companyID = compID; // Note: all iBeacons use the Apple ID of 0x004C |
| mbedAustin | 1:0692bee84264 | 24 | |
| mbedAustin | 1:0692bee84264 | 25 | // copy across proximity UUID |
| mbedAustin | 1:0692bee84264 | 26 | for(int x=0; x<sizeof(data.proximityUUID); x++) { |
| mbedAustin | 1:0692bee84264 | 27 | data.proximityUUID[x]=proxUUID[x]; |
| mbedAustin | 1:0692bee84264 | 28 | } |
| mbedAustin | 1:0692bee84264 | 29 | |
| mbedAustin | 1:0692bee84264 | 30 | // Set up iBeacon data |
| mbedAustin | 1:0692bee84264 | 31 | // Generate the 0x020106 part of the iBeacon Prefix |
| mbedAustin | 1:0692bee84264 | 32 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); |
| mbedAustin | 1:0692bee84264 | 33 | // Generate the 0x1AFF part of the iBeacon Prefix |
| mbedAustin | 1:0692bee84264 | 34 | ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw)); |
| mbedAustin | 1:0692bee84264 | 35 | |
| mbedAustin | 1:0692bee84264 | 36 | // Set advertising type |
| mbedAustin | 1:0692bee84264 | 37 | ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
| mbedAustin | 1:0692bee84264 | 38 | } |
| mbedAustin | 1:0692bee84264 | 39 | |
| mbedAustin | 1:0692bee84264 | 40 | public: |
| mbedAustin | 1:0692bee84264 | 41 | union { |
| mbedAustin | 1:0692bee84264 | 42 | uint8_t raw[25]; |
| mbedAustin | 1:0692bee84264 | 43 | struct { |
| mbedAustin | 1:0692bee84264 | 44 | uint16_t companyID; |
| mbedAustin | 1:0692bee84264 | 45 | uint8_t ID; |
| mbedAustin | 1:0692bee84264 | 46 | uint8_t len; |
| mbedAustin | 1:0692bee84264 | 47 | uint8_t proximityUUID[16]; |
| mbedAustin | 1:0692bee84264 | 48 | uint16_t majorNumber; |
| mbedAustin | 1:0692bee84264 | 49 | uint16_t minorNumber; |
| mbedAustin | 1:0692bee84264 | 50 | uint8_t txPower; |
| mbedAustin | 1:0692bee84264 | 51 | }; |
| mbedAustin | 1:0692bee84264 | 52 | } data; |
| mbedAustin | 1:0692bee84264 | 53 | |
| mbedAustin | 1:0692bee84264 | 54 | private: |
| mbedAustin | 1:0692bee84264 | 55 | BLEDevice &ble; |
| mbedAustin | 1:0692bee84264 | 56 | |
| mbedAustin | 1:0692bee84264 | 57 | }; |
| mbedAustin | 1:0692bee84264 | 58 | |
| mbedAustin | 1:0692bee84264 | 59 | #endif //__BLE_EVOTHINGS_CUSTOM_GAP_H__ |
