Aura-Tech Solutions / Mbed 2 deprecated Connect_Test4

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_EvothingsExample_GATT by Austin Blackstone

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AltBeaconService.h Source File

AltBeaconService.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_ALTBEACON_SERVICE_H__
00017 #define __BLE_ALTBEACON_SERVICE_H__
00018 
00019 #include "BLEDevice.h"
00020 
00021 /**
00022 * @class AltBeaconService
00023 * @brief AltBeacon Service. This service sets up a device to broadcast advertising packets to mimic an AltBeacon<br>
00024 */
00025 
00026 class AltBeaconService
00027 {
00028 public:
00029     /**
00030     * @param[ref] _ble
00031     *               BLEDevice object for the underlying controller.
00032     * @param[in] mfgID
00033     *               The beacon device manufacturer's company identifier code. 
00034     *               Usually this will coorespond to the companies BLE SIG assigned number.
00035     * @param[in] beaconID
00036     *               A 20-byte value uniquely identifying the beacon. 
00037     *               The big endian representation of the beacon identifier. 
00038     *               For interoperability purposes, the first 16+ bytes of the beacon 
00039     *               identifier should be unique to the advertiser's organizational unit. 
00040     *               Any remaining bytes of the beacon identifier may be subdivided as needed for the use case.
00041     * @param[in] refRSSI
00042     *               The RSSI of the beacon (as signed value from 0 to -127) as measured 1 meter from the device. Used for micro-location.
00043     * @param[in] mfgReserved
00044     *               Used for special manufacturer data. Defaults to 0x00 if not specified.
00045     */
00046     AltBeaconService (BLEDevice &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
00047         ble(_ble)
00048     {
00049         data.mfgID = ((mfgID<<8) | (mfgID >>8));
00050         if(refRSSI > 0){refRSSI = 0;} // refRSSI can only be 0 to -127, smash everything above 0 to zero
00051         data.refRSSI = refRSSI;
00052         data.beaconCode = 0xACBE;
00053         data.mfgReserved = mfgReserved;
00054 
00055         // copy across beacon ID
00056         for(int x=0; x<sizeof(data.beaconID); x++) {
00057             data.beaconID[x] = beaconID[x];
00058         }
00059 
00060         // Set up alt beacon
00061         ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
00062         // Generate the 0x1BFF part of the Alt 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 public:
00070     union {
00071         uint8_t raw[26]; // AltBeacon advertisment data
00072         struct {
00073             uint16_t mfgID;         // little endian representation of manufacturer ID
00074             uint16_t beaconCode;    // Big Endian representation of 0xBEAC
00075             uint8_t  beaconID[20];  // 20byte beacon ID, usually 16byte UUID w/ remainder used as necessary
00076             int8_t   refRSSI;       // 1 byte signed data, 0 to -127
00077             uint8_t  mfgReserved;   // reserved for use by manufacturer to implement special features
00078         };
00079     } data;
00080 
00081 private:
00082     BLEDevice &ble;
00083 
00084 };
00085 
00086 #endif //__BLE_ALTBEACON_SERVICE_H__