test

Dependencies:   BLE_API mbed nRF51822

Fork of Connect_Test4 by Aura-Tech Solutions

Committer:
peteratsl
Date:
Fri Nov 13 15:04:50 2015 +0000
Revision:
20:e9d6adb5162b
Parent:
19:da48cacdb4c1
new

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peteratsl 19:da48cacdb4c1 1 /* mbed Microcontroller Library
peteratsl 19:da48cacdb4c1 2 * Copyright (c) 2006-2015 ARM Limited
peteratsl 19:da48cacdb4c1 3 *
peteratsl 19:da48cacdb4c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
peteratsl 19:da48cacdb4c1 5 * you may not use this file except in compliance with the License.
peteratsl 19:da48cacdb4c1 6 * You may obtain a copy of the License at
peteratsl 19:da48cacdb4c1 7 *
peteratsl 19:da48cacdb4c1 8 * http://www.apache.org/licenses/LICENSE-2.0
peteratsl 19:da48cacdb4c1 9 *
peteratsl 19:da48cacdb4c1 10 * Unless required by applicable law or agreed to in writing, software
peteratsl 19:da48cacdb4c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
peteratsl 19:da48cacdb4c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
peteratsl 19:da48cacdb4c1 13 * See the License for the specific language governing permissions and
peteratsl 19:da48cacdb4c1 14 * limitations under the License.
peteratsl 19:da48cacdb4c1 15 */
peteratsl 19:da48cacdb4c1 16 #ifndef __BLE_ALTBEACON_SERVICE_H__
peteratsl 19:da48cacdb4c1 17 #define __BLE_ALTBEACON_SERVICE_H__
peteratsl 19:da48cacdb4c1 18
peteratsl 19:da48cacdb4c1 19 #include "BLEDevice.h"
peteratsl 19:da48cacdb4c1 20
peteratsl 19:da48cacdb4c1 21 /**
peteratsl 19:da48cacdb4c1 22 * @class AltBeaconService
peteratsl 19:da48cacdb4c1 23 * @brief AltBeacon Service. This service sets up a device to broadcast advertising packets to mimic an AltBeacon<br>
peteratsl 19:da48cacdb4c1 24 */
peteratsl 19:da48cacdb4c1 25
peteratsl 19:da48cacdb4c1 26 class AltBeaconService
peteratsl 19:da48cacdb4c1 27 {
peteratsl 19:da48cacdb4c1 28 public:
peteratsl 19:da48cacdb4c1 29 /**
peteratsl 19:da48cacdb4c1 30 * @param[ref] _ble
peteratsl 19:da48cacdb4c1 31 * BLEDevice object for the underlying controller.
peteratsl 19:da48cacdb4c1 32 * @param[in] mfgID
peteratsl 19:da48cacdb4c1 33 * The beacon device manufacturer's company identifier code.
peteratsl 19:da48cacdb4c1 34 * Usually this will coorespond to the companies BLE SIG assigned number.
peteratsl 19:da48cacdb4c1 35 * @param[in] beaconID
peteratsl 19:da48cacdb4c1 36 * A 20-byte value uniquely identifying the beacon.
peteratsl 19:da48cacdb4c1 37 * The big endian representation of the beacon identifier.
peteratsl 19:da48cacdb4c1 38 * For interoperability purposes, the first 16+ bytes of the beacon
peteratsl 19:da48cacdb4c1 39 * identifier should be unique to the advertiser's organizational unit.
peteratsl 19:da48cacdb4c1 40 * Any remaining bytes of the beacon identifier may be subdivided as needed for the use case.
peteratsl 19:da48cacdb4c1 41 * @param[in] refRSSI
peteratsl 19:da48cacdb4c1 42 * The RSSI of the beacon (as signed value from 0 to -127) as measured 1 meter from the device. Used for micro-location.
peteratsl 19:da48cacdb4c1 43 * @param[in] mfgReserved
peteratsl 19:da48cacdb4c1 44 * Used for special manufacturer data. Defaults to 0x00 if not specified.
peteratsl 19:da48cacdb4c1 45 */
peteratsl 19:da48cacdb4c1 46 AltBeaconService(BLEDevice &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
peteratsl 19:da48cacdb4c1 47 ble(_ble)
peteratsl 19:da48cacdb4c1 48 {
peteratsl 19:da48cacdb4c1 49 data.mfgID = ((mfgID<<8) | (mfgID >>8));
peteratsl 19:da48cacdb4c1 50 if(refRSSI > 0){refRSSI = 0;} // refRSSI can only be 0 to -127, smash everything above 0 to zero
peteratsl 19:da48cacdb4c1 51 data.refRSSI = refRSSI;
peteratsl 19:da48cacdb4c1 52 data.beaconCode = 0xACBE;
peteratsl 19:da48cacdb4c1 53 data.mfgReserved = mfgReserved;
peteratsl 19:da48cacdb4c1 54
peteratsl 19:da48cacdb4c1 55 // copy across beacon ID
peteratsl 19:da48cacdb4c1 56 for(int x=0; x<sizeof(data.beaconID); x++) {
peteratsl 19:da48cacdb4c1 57 data.beaconID[x] = beaconID[x];
peteratsl 19:da48cacdb4c1 58 }
peteratsl 19:da48cacdb4c1 59
peteratsl 19:da48cacdb4c1 60 // Set up alt beacon
peteratsl 19:da48cacdb4c1 61 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
peteratsl 19:da48cacdb4c1 62 // Generate the 0x1BFF part of the Alt Prefix
peteratsl 19:da48cacdb4c1 63 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
peteratsl 19:da48cacdb4c1 64
peteratsl 19:da48cacdb4c1 65 // Set advertising type
peteratsl 19:da48cacdb4c1 66 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
peteratsl 19:da48cacdb4c1 67 }
peteratsl 19:da48cacdb4c1 68
peteratsl 19:da48cacdb4c1 69 public:
peteratsl 19:da48cacdb4c1 70 union {
peteratsl 19:da48cacdb4c1 71 uint8_t raw[26]; // AltBeacon advertisment data
peteratsl 19:da48cacdb4c1 72 struct {
peteratsl 19:da48cacdb4c1 73 uint16_t mfgID; // little endian representation of manufacturer ID
peteratsl 19:da48cacdb4c1 74 uint16_t beaconCode; // Big Endian representation of 0xBEAC
peteratsl 19:da48cacdb4c1 75 uint8_t beaconID[20]; // 20byte beacon ID, usually 16byte UUID w/ remainder used as necessary
peteratsl 19:da48cacdb4c1 76 int8_t refRSSI; // 1 byte signed data, 0 to -127
peteratsl 19:da48cacdb4c1 77 uint8_t mfgReserved; // reserved for use by manufacturer to implement special features
peteratsl 19:da48cacdb4c1 78 };
peteratsl 19:da48cacdb4c1 79 } data;
peteratsl 19:da48cacdb4c1 80
peteratsl 19:da48cacdb4c1 81 private:
peteratsl 19:da48cacdb4c1 82 BLEDevice &ble;
peteratsl 19:da48cacdb4c1 83
peteratsl 19:da48cacdb4c1 84 };
peteratsl 19:da48cacdb4c1 85
peteratsl 19:da48cacdb4c1 86 #endif //__BLE_ALTBEACON_SERVICE_H__