Minor fixes

Fork of BLE_API by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers iBeaconService.h Source File

iBeaconService.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef __BLE_IBEACON_SERVICE_H__
00017 #define __BLE_IBEACON_SERVICE_H__
00018 
00019 #include "core_cmInstr.h"
00020 #include "BLE.h"
00021 
00022 /**
00023 * @class iBeaconService
00024 * @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<br>
00025 */
00026 
00027 class iBeaconService
00028 {
00029 public:
00030     typedef const uint8_t LocationUUID_t[16];
00031 
00032     union Payload {
00033         uint8_t raw[25];
00034         struct {
00035             uint16_t companyID;
00036             uint8_t ID;
00037             uint8_t len;
00038             uint8_t proximityUUID[16];
00039             uint16_t majorNumber;
00040             uint16_t minorNumber;
00041             uint8_t txPower;
00042         };
00043 
00044         Payload(LocationUUID_t uuid, uint16_t majNum, uint16_t minNum, uint8_t transmitPower, uint16_t companyIDIn) :
00045             companyID(companyIDIn), ID(0x02), len(0x15), majorNumber(__REV16(majNum)), minorNumber(__REV16(minNum)), txPower(transmitPower)
00046         {
00047             memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
00048         }
00049     };
00050 
00051 public:
00052     iBeaconService(BLE            &_ble,
00053                    LocationUUID_t  uuid,
00054                    uint16_t        majNum,
00055                    uint16_t        minNum,
00056                    uint8_t         txP    = 0xC8,
00057                    uint16_t        compID = 0x004C) :
00058         ble(_ble), data(uuid, majNum, minNum, txP, compID)
00059     {
00060         // Generate the 0x020106 part of the iBeacon Prefix
00061         ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
00062         // Generate the 0x1AFF part of the iBeacon Prefix
00063         ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
00064 
00065         // Set advertising type
00066         ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
00067     }
00068 
00069 protected:
00070     BLE     &ble;
00071     Payload  data;
00072 };
00073 
00074 #endif //__BLE_IBEACON_SERVICE_H__