|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -#ifndef __BLE_IBEACON_H__ |
17 |
| -#define __BLE_IBEACON_H__ |
| 16 | +#ifndef MBED_BLE_IBEACON_H__ |
| 17 | +#define MBED_BLE_IBEACON_H__ |
18 | 18 |
|
19 | 19 | #include "cmsis_compiler.h"
|
20 | 20 | #include "ble/BLE.h"
|
21 | 21 |
|
22 | 22 | /**
|
23 |
| -* @class iBeacon |
24 |
| -* @brief iBeacon Service. This sets up a device to broadcast advertising packets to mimic an iBeacon. |
25 |
| -*/ |
| 23 | + * iBeacon Service. |
| 24 | + * |
| 25 | + * @par Purpose |
| 26 | + * |
| 27 | + * iBeacons are Bluetooth Low Energy (BLE) devices advertising an identification |
| 28 | + * number generally used to identify the location of devices or physical objects |
| 29 | + * nearby a mobile phone user. |
| 30 | + * |
| 31 | + * iOS scans for iBeacon devices in a background task and will notify Apps |
| 32 | + * subscribed to a specific region when the area is entered or left. Apps may |
| 33 | + * use this information to display context-aware content to users. |
| 34 | + * |
| 35 | + * As an example a museum can deploy an apps which inform the user when one of |
| 36 | + * its exhibition is enterred then display specific information about exposed |
| 37 | + * pieces of art when the user is sufficiently close to them. |
| 38 | + * |
| 39 | + * @par Positioning |
| 40 | + * |
| 41 | + * Location information is hierarchically structured. A UUID specific to the |
| 42 | + * application and its deployment is used to identify a region. That region |
| 43 | + * usually identify an organization. The region is divided into subregions |
| 44 | + * identified by a major ID. The subregion may contain related points of |
| 45 | + * interrest. Finally specific points of interrest within a subregion are |
| 46 | + * distinguished by a minor ID. |
| 47 | + * |
| 48 | + * As an example a city willing to improve tourists experience can deploy a fleet |
| 49 | + * of iBeacons in relevant touristic locations it operates. The UUID may |
| 50 | + * identify a place managed by the city. The major ID would identify the place |
| 51 | + * it can be something such as a museum, an historic monument or a metro station. |
| 52 | + * The minor ID would locate a specific spot within the city place. It can be a |
| 53 | + * piece of art, a ticket dispenser or a relevant point of interrest. Each |
| 54 | + * iBeacon device is physically attached to the spot it identify and advertise |
| 55 | + * those three location information. |
| 56 | + * |
| 57 | + * @par Proximity |
| 58 | + * |
| 59 | + * The beacon advertise the signal strength measured by an iOS device at a |
| 60 | + * distance of one meter. This information is used by iOS to approximate the |
| 61 | + * proximity to a given beacon: |
| 62 | + * - Immediate: The beacon is less than one meter away from the user. |
| 63 | + * - Near: The beacon is one to three meter away from the user. |
| 64 | + * - Far: The application is not near the device, distance highly depends on |
| 65 | + * the physical environment. |
| 66 | + * |
| 67 | + * Ideally beacons should be calibrated at there deployment location because the |
| 68 | + * surrounding environment affect the strength of the advertised signal. |
| 69 | + * |
| 70 | + * @par Usage |
| 71 | + * |
| 72 | + * Mbed OS applications can use this class to set up a device to broadcast |
| 73 | + * advertising packets mimicking an iBeacon. The construction will automatically |
| 74 | + * create the payload identifying the beacon and register it as part of the |
| 75 | + * advertising payload of the device. |
| 76 | + * |
| 77 | + * @important If you are interested in manufacturing iBeacons, you must obtain a |
| 78 | + * license from Apple. More information at https://developer.apple.com/ibeacon/. |
| 79 | + * The licence also grant access to the iBeacons technical specification. |
| 80 | + * |
| 81 | + * @note More information at https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf |
| 82 | + */ |
26 | 83 | class iBeacon
|
27 | 84 | {
|
28 | 85 | public:
|
| 86 | + /** |
| 87 | + * Data buffer of a location UUID. |
| 88 | + */ |
29 | 89 | typedef const uint8_t LocationUUID_t[16];
|
30 | 90 |
|
| 91 | + /** |
| 92 | + * iBeacon payload builder. |
| 93 | + * |
| 94 | + * This data structure contains the payload of an iBeacon. The payload is |
| 95 | + * built at construction time and application code can set up an iBeacon by |
| 96 | + * injecting the raw field into the GAP advertising payload as a |
| 97 | + * GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA. |
| 98 | + */ |
31 | 99 | union Payload {
|
| 100 | + /** |
| 101 | + * Raw data of the payload. |
| 102 | + */ |
32 | 103 | uint8_t raw[25];
|
33 | 104 | struct {
|
| 105 | + /** |
| 106 | + * Beacon manufacturer identifier. |
| 107 | + */ |
34 | 108 | uint16_t companyID;
|
| 109 | + |
| 110 | + /** |
| 111 | + * Packet ID; Equal to 2 for an iBeacon. |
| 112 | + */ |
35 | 113 | uint8_t ID;
|
| 114 | + |
| 115 | + /** |
| 116 | + * Length of the remaining data presents in the payload. |
| 117 | + */ |
36 | 118 | uint8_t len;
|
| 119 | + |
| 120 | + /** |
| 121 | + * Beacon UUID. |
| 122 | + */ |
37 | 123 | uint8_t proximityUUID[16];
|
| 124 | + |
| 125 | + /** |
| 126 | + * Beacon Major group ID. |
| 127 | + */ |
38 | 128 | uint16_t majorNumber;
|
| 129 | + |
| 130 | + /** |
| 131 | + * Beacon minor ID. |
| 132 | + */ |
39 | 133 | uint16_t minorNumber;
|
| 134 | + |
| 135 | + /** |
| 136 | + * Tx power received at 1 meter; in dBm. |
| 137 | + */ |
40 | 138 | uint8_t txPower;
|
41 | 139 | };
|
42 | 140 |
|
43 |
| - Payload(LocationUUID_t uuid, uint16_t majNum, uint16_t minNum, uint8_t transmitPower, uint16_t companyIDIn) : |
44 |
| - companyID(companyIDIn), ID(0x02), len(0x15), majorNumber(__REV16(majNum)), minorNumber(__REV16(minNum)), txPower(transmitPower) |
| 141 | + /** |
| 142 | + * Assemble an iBeacon payload. |
| 143 | + * |
| 144 | + * @param[in] uuid Beacon network ID. iBeacon operators use this value |
| 145 | + * to group their iBeacons into a single network, a single region and |
| 146 | + * identify their organization amongst others. |
| 147 | + * |
| 148 | + * @param[in] majNum Beacon major group ID. iBeacon exploitants may use |
| 149 | + * this field to divide the region into subregions, their network into |
| 150 | + * sub networks. |
| 151 | + * |
| 152 | + * @param[in] minNum Identifier of the Beacon in its subregion. |
| 153 | + * |
| 154 | + * @param[in] transmitPower Measured transmit power of the beacon at 1 |
| 155 | + * meter. This parameter is used by scanners to approximate the distance |
| 156 | + * to the beacon. |
| 157 | + * |
| 158 | + * @param[in] companyIDIn ID of the beacon manufacturer. |
| 159 | + */ |
| 160 | + Payload( |
| 161 | + LocationUUID_t uuid, |
| 162 | + uint16_t majNum, |
| 163 | + uint16_t minNum, |
| 164 | + uint8_t transmitPower, |
| 165 | + uint16_t companyIDIn |
| 166 | + ) : companyID(companyIDIn), |
| 167 | + ID(0x02), |
| 168 | + len(0x15), |
| 169 | + majorNumber(__REV16(majNum)), |
| 170 | + minorNumber(__REV16(minNum)), |
| 171 | + txPower(transmitPower) |
45 | 172 | {
|
46 | 173 | memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
|
47 | 174 | }
|
48 | 175 | };
|
49 | 176 |
|
50 | 177 | public:
|
51 |
| - iBeacon(BLE &_ble, |
52 |
| - LocationUUID_t uuid, |
53 |
| - uint16_t majNum, |
54 |
| - uint16_t minNum, |
55 |
| - uint8_t txP = 0xC8, |
56 |
| - uint16_t compID = 0x004C) : |
57 |
| - ble(_ble), data(uuid, majNum, minNum, txP, compID) |
| 178 | + /** |
| 179 | + * Construct an iBeacon::Payload and register it into Gap. |
| 180 | + * |
| 181 | + * @param[in] _ble The ble interface to configure with the iBeacon payload. |
| 182 | + * |
| 183 | + * @param[in] uuid Beacon network ID. iBeacon operators use this value |
| 184 | + * to group their iBeacons into a single network, a single region and |
| 185 | + * identify their organization amongst others. |
| 186 | + * |
| 187 | + * @param[in] majNum Beacon major group ID. iBeacon exploitants may use |
| 188 | + * this field to divide the region into subregions, their network into |
| 189 | + * sub networks. |
| 190 | + * |
| 191 | + * @param[in] minNum Identifier of the Beacon in its subregion. |
| 192 | + * |
| 193 | + * @param[in] txP Measured transmit power of the beacon at 1 |
| 194 | + * meter. This parameter is used by scanners to approximate the distance |
| 195 | + * to the beacon. |
| 196 | + * |
| 197 | + * @param[in] compID ID of the beacon manufacturer. |
| 198 | + */ |
| 199 | + iBeacon( |
| 200 | + BLE &_ble, |
| 201 | + LocationUUID_t uuid, |
| 202 | + uint16_t majNum, |
| 203 | + uint16_t minNum, |
| 204 | + uint8_t txP = 0xC8, |
| 205 | + uint16_t compID = 0x004C |
| 206 | + ) : ble(_ble), |
| 207 | + data(uuid, majNum, minNum, txP, compID) |
58 | 208 | {
|
59 | 209 | // Generate the 0x020106 part of the iBeacon Prefix.
|
60 |
| - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); |
| 210 | + ble.accumulateAdvertisingPayload( |
| 211 | + GapAdvertisingData::BREDR_NOT_SUPPORTED | |
| 212 | + GapAdvertisingData::LE_GENERAL_DISCOVERABLE |
| 213 | + ); |
61 | 214 | // Generate the 0x1AFF part of the iBeacon Prefix.
|
62 |
| - ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw)); |
| 215 | + ble.accumulateAdvertisingPayload( |
| 216 | + GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
| 217 | + data.raw, |
| 218 | + sizeof(data.raw) |
| 219 | + ); |
63 | 220 |
|
64 | 221 | // Set advertising type.
|
65 |
| - ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
| 222 | + ble.setAdvertisingType( |
| 223 | + GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED |
| 224 | + ); |
66 | 225 | }
|
67 | 226 |
|
68 | 227 | protected:
|
69 |
| - BLE &ble; |
70 |
| - Payload data; |
| 228 | + BLE &ble; |
| 229 | + Payload data; |
71 | 230 | };
|
72 | 231 |
|
73 |
| -typedef iBeacon iBeaconService; /* This type-alias is deprecated. Please use iBeacon directly. This alias may be dropped from a future release. */ |
| 232 | +/** |
| 233 | + * iBeacon alias. |
| 234 | + * |
| 235 | + * @deprecated Please use iBeacon directly. This alias may be dropped from a |
| 236 | + * future release. |
| 237 | + */ |
| 238 | +typedef iBeacon iBeaconService; |
74 | 239 |
|
75 |
| -#endif //__BLE_IBEACON_H__ |
| 240 | +#endif //MBED_BLE_IBEACON_H__ |
0 commit comments