Preliminary main mbed library for nexpaq development
features/FEATURE_BLE/ble/services/iBeacon.h@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | /* mbed Microcontroller Library |
nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2006-2015 ARM Limited |
nexpaq | 0:6c56fb4bc5f0 | 3 | * |
nexpaq | 0:6c56fb4bc5f0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 0:6c56fb4bc5f0 | 5 | * you may not use this file except in compliance with the License. |
nexpaq | 0:6c56fb4bc5f0 | 6 | * You may obtain a copy of the License at |
nexpaq | 0:6c56fb4bc5f0 | 7 | * |
nexpaq | 0:6c56fb4bc5f0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 9 | * |
nexpaq | 0:6c56fb4bc5f0 | 10 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 0:6c56fb4bc5f0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 0:6c56fb4bc5f0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 0:6c56fb4bc5f0 | 13 | * See the License for the specific language governing permissions and |
nexpaq | 0:6c56fb4bc5f0 | 14 | * limitations under the License. |
nexpaq | 0:6c56fb4bc5f0 | 15 | */ |
nexpaq | 0:6c56fb4bc5f0 | 16 | #ifndef __BLE_IBEACON_H__ |
nexpaq | 0:6c56fb4bc5f0 | 17 | #define __BLE_IBEACON_H__ |
nexpaq | 0:6c56fb4bc5f0 | 18 | |
nexpaq | 0:6c56fb4bc5f0 | 19 | #include "core_cmInstr.h" |
nexpaq | 0:6c56fb4bc5f0 | 20 | #include "ble/BLE.h" |
nexpaq | 0:6c56fb4bc5f0 | 21 | |
nexpaq | 0:6c56fb4bc5f0 | 22 | /** |
nexpaq | 0:6c56fb4bc5f0 | 23 | * @class iBeacon |
nexpaq | 0:6c56fb4bc5f0 | 24 | * @brief iBeacon Service. This sets up a device to broadcast advertising packets to mimic an iBeacon. |
nexpaq | 0:6c56fb4bc5f0 | 25 | */ |
nexpaq | 0:6c56fb4bc5f0 | 26 | class iBeacon |
nexpaq | 0:6c56fb4bc5f0 | 27 | { |
nexpaq | 0:6c56fb4bc5f0 | 28 | public: |
nexpaq | 0:6c56fb4bc5f0 | 29 | typedef const uint8_t LocationUUID_t[16]; |
nexpaq | 0:6c56fb4bc5f0 | 30 | |
nexpaq | 0:6c56fb4bc5f0 | 31 | union Payload { |
nexpaq | 0:6c56fb4bc5f0 | 32 | uint8_t raw[25]; |
nexpaq | 0:6c56fb4bc5f0 | 33 | struct { |
nexpaq | 0:6c56fb4bc5f0 | 34 | uint16_t companyID; |
nexpaq | 0:6c56fb4bc5f0 | 35 | uint8_t ID; |
nexpaq | 0:6c56fb4bc5f0 | 36 | uint8_t len; |
nexpaq | 0:6c56fb4bc5f0 | 37 | uint8_t proximityUUID[16]; |
nexpaq | 0:6c56fb4bc5f0 | 38 | uint16_t majorNumber; |
nexpaq | 0:6c56fb4bc5f0 | 39 | uint16_t minorNumber; |
nexpaq | 0:6c56fb4bc5f0 | 40 | uint8_t txPower; |
nexpaq | 0:6c56fb4bc5f0 | 41 | }; |
nexpaq | 0:6c56fb4bc5f0 | 42 | |
nexpaq | 0:6c56fb4bc5f0 | 43 | Payload(LocationUUID_t uuid, uint16_t majNum, uint16_t minNum, uint8_t transmitPower, uint16_t companyIDIn) : |
nexpaq | 0:6c56fb4bc5f0 | 44 | companyID(companyIDIn), ID(0x02), len(0x15), majorNumber(__REV16(majNum)), minorNumber(__REV16(minNum)), txPower(transmitPower) |
nexpaq | 0:6c56fb4bc5f0 | 45 | { |
nexpaq | 0:6c56fb4bc5f0 | 46 | memcpy(proximityUUID, uuid, sizeof(LocationUUID_t)); |
nexpaq | 0:6c56fb4bc5f0 | 47 | } |
nexpaq | 0:6c56fb4bc5f0 | 48 | }; |
nexpaq | 0:6c56fb4bc5f0 | 49 | |
nexpaq | 0:6c56fb4bc5f0 | 50 | public: |
nexpaq | 0:6c56fb4bc5f0 | 51 | iBeacon(BLE &_ble, |
nexpaq | 0:6c56fb4bc5f0 | 52 | LocationUUID_t uuid, |
nexpaq | 0:6c56fb4bc5f0 | 53 | uint16_t majNum, |
nexpaq | 0:6c56fb4bc5f0 | 54 | uint16_t minNum, |
nexpaq | 0:6c56fb4bc5f0 | 55 | uint8_t txP = 0xC8, |
nexpaq | 0:6c56fb4bc5f0 | 56 | uint16_t compID = 0x004C) : |
nexpaq | 0:6c56fb4bc5f0 | 57 | ble(_ble), data(uuid, majNum, minNum, txP, compID) |
nexpaq | 0:6c56fb4bc5f0 | 58 | { |
nexpaq | 0:6c56fb4bc5f0 | 59 | // Generate the 0x020106 part of the iBeacon Prefix. |
nexpaq | 0:6c56fb4bc5f0 | 60 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE ); |
nexpaq | 0:6c56fb4bc5f0 | 61 | // Generate the 0x1AFF part of the iBeacon Prefix. |
nexpaq | 0:6c56fb4bc5f0 | 62 | ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw)); |
nexpaq | 0:6c56fb4bc5f0 | 63 | |
nexpaq | 0:6c56fb4bc5f0 | 64 | // Set advertising type. |
nexpaq | 0:6c56fb4bc5f0 | 65 | ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
nexpaq | 0:6c56fb4bc5f0 | 66 | } |
nexpaq | 0:6c56fb4bc5f0 | 67 | |
nexpaq | 0:6c56fb4bc5f0 | 68 | protected: |
nexpaq | 0:6c56fb4bc5f0 | 69 | BLE &ble; |
nexpaq | 0:6c56fb4bc5f0 | 70 | Payload data; |
nexpaq | 0:6c56fb4bc5f0 | 71 | }; |
nexpaq | 0:6c56fb4bc5f0 | 72 | |
nexpaq | 0:6c56fb4bc5f0 | 73 | typedef iBeacon iBeaconService; /* This type-alias is deprecated. Please use iBeacon directly. This alias may be dropped from a future release. */ |
nexpaq | 0:6c56fb4bc5f0 | 74 | |
nexpaq | 0:6c56fb4bc5f0 | 75 | #endif //__BLE_IBEACON_H__ |