Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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