Skip to content

Commit 62e984b

Browse files
committed
BLE: Update iBeacon documentation.
Provide detailled description of the purpose, general concepts and usage.
1 parent 20d93bf commit 62e984b

File tree

1 file changed

+186
-21
lines changed

1 file changed

+186
-21
lines changed

features/FEATURE_BLE/ble/services/iBeacon.h

Lines changed: 186 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,228 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __BLE_IBEACON_H__
17-
#define __BLE_IBEACON_H__
16+
#ifndef MBED_BLE_IBEACON_H__
17+
#define MBED_BLE_IBEACON_H__
1818

1919
#include "cmsis_compiler.h"
2020
#include "ble/BLE.h"
2121

2222
/**
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+
*/
2683
class iBeacon
2784
{
2885
public:
86+
/**
87+
* Data buffer of a location UUID.
88+
*/
2989
typedef const uint8_t LocationUUID_t[16];
3090

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+
*/
3199
union Payload {
100+
/**
101+
* Raw data of the payload.
102+
*/
32103
uint8_t raw[25];
33104
struct {
105+
/**
106+
* Beacon manufacturer identifier.
107+
*/
34108
uint16_t companyID;
109+
110+
/**
111+
* Packet ID; Equal to 2 for an iBeacon.
112+
*/
35113
uint8_t ID;
114+
115+
/**
116+
* Length of the remaining data presents in the payload.
117+
*/
36118
uint8_t len;
119+
120+
/**
121+
* Beacon UUID.
122+
*/
37123
uint8_t proximityUUID[16];
124+
125+
/**
126+
* Beacon Major group ID.
127+
*/
38128
uint16_t majorNumber;
129+
130+
/**
131+
* Beacon minor ID.
132+
*/
39133
uint16_t minorNumber;
134+
135+
/**
136+
* Tx power received at 1 meter; in dBm.
137+
*/
40138
uint8_t txPower;
41139
};
42140

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)
45172
{
46173
memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
47174
}
48175
};
49176

50177
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)
58208
{
59209
// 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+
);
61214
// 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+
);
63220

64221
// Set advertising type.
65-
ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
222+
ble.setAdvertisingType(
223+
GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED
224+
);
66225
}
67226

68227
protected:
69-
BLE &ble;
70-
Payload data;
228+
BLE &ble;
229+
Payload data;
71230
};
72231

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;
74239

75-
#endif //__BLE_IBEACON_H__
240+
#endif //MBED_BLE_IBEACON_H__

0 commit comments

Comments
 (0)