Update for latest nRF51822 code changes.
Dependencies: BLE_API nRF51822
Fork of Puck by
Puck.cpp@1:29b2cca0d529, 2014-07-17 (annotated)
- Committer:
- stiaje
- Date:
- Thu Jul 17 08:46:50 2014 +0000
- Revision:
- 1:29b2cca0d529
- Parent:
- 0:718051934fdb
Make all pucks connectable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stiaje | 0:718051934fdb | 1 | #include "mbed.h" |
stiaje | 0:718051934fdb | 2 | #include "Puck.hpp" |
stiaje | 0:718051934fdb | 3 | |
stiaje | 1:29b2cca0d529 | 4 | Puck::Puck(uint16_t minor) { |
stiaje | 0:718051934fdb | 5 | /* |
stiaje | 0:718051934fdb | 6 | * The Beacon payload (encapsulated within the MSD advertising data structure) |
stiaje | 0:718051934fdb | 7 | * has the following composition: |
stiaje | 0:718051934fdb | 8 | * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 |
stiaje | 0:718051934fdb | 9 | * Major/Minor = 1337 / XXXX |
stiaje | 0:718051934fdb | 10 | * Tx Power = C8 |
stiaje | 0:718051934fdb | 11 | */ |
stiaje | 0:718051934fdb | 12 | uint8_t beaconPayloadTemplate[] = { |
stiaje | 0:718051934fdb | 13 | 0x00, 0x00, // Company identifier code (0x004C == Apple) |
stiaje | 0:718051934fdb | 14 | 0x02, // ID |
stiaje | 0:718051934fdb | 15 | 0x15, // length of the remaining payload |
stiaje | 0:718051934fdb | 16 | 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID |
stiaje | 0:718051934fdb | 17 | 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61, |
stiaje | 0:718051934fdb | 18 | 0x13, 0x37, // the major value to differenciate a location (Our app requires 1337 as major number) |
stiaje | 0:718051934fdb | 19 | 0x00, 0x00, // the minor value to differenciate a location (Change this to differentiate location pucks) |
stiaje | 0:718051934fdb | 20 | 0xC8 // 2's complement of the Tx power (-56dB) |
stiaje | 0:718051934fdb | 21 | }; |
stiaje | 0:718051934fdb | 22 | beaconPayloadTemplate[22] = minor >> 8; |
stiaje | 0:718051934fdb | 23 | beaconPayloadTemplate[23] = minor & 255; |
stiaje | 0:718051934fdb | 24 | |
stiaje | 0:718051934fdb | 25 | for (int i=0; i < 25; i++) { |
stiaje | 0:718051934fdb | 26 | _beaconPayload[i] = beaconPayloadTemplate[i]; |
stiaje | 0:718051934fdb | 27 | } |
stiaje | 0:718051934fdb | 28 | } |
stiaje | 0:718051934fdb | 29 | |
stiaje | 0:718051934fdb | 30 | void Puck::init(void) { |
stiaje | 0:718051934fdb | 31 | _ble.init(); |
stiaje | 0:718051934fdb | 32 | |
stiaje | 0:718051934fdb | 33 | _ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
stiaje | 0:718051934fdb | 34 | _ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
stiaje | 0:718051934fdb | 35 | _beaconPayload, sizeof(_beaconPayload)); |
stiaje | 0:718051934fdb | 36 | |
stiaje | 1:29b2cca0d529 | 37 | _ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
stiaje | 0:718051934fdb | 38 | |
stiaje | 0:718051934fdb | 39 | _ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ |
stiaje | 0:718051934fdb | 40 | |
stiaje | 0:718051934fdb | 41 | _ble.startAdvertising(); |
stiaje | 0:718051934fdb | 42 | } |