Beacon demo for the BLE API using the nRF51822 native mode drivers

Dependencies:   BLE_API SDFileSystem mbed-rtos mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_iBeacon by Bluetooth Low Energy

Committer:
mbedAustin
Date:
Thu Feb 12 22:36:55 2015 +0000
Revision:
53:f9ec2c7a47f5
Updated BLE_API library and mbed library, added iBeaconService.h and altered main.cpp to reflect the use of iBeaconService.h accordingly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 53:f9ec2c7a47f5 1 /* mbed Microcontroller Library
mbedAustin 53:f9ec2c7a47f5 2 * Copyright (c) 2006-2015 ARM Limited
mbedAustin 53:f9ec2c7a47f5 3 *
mbedAustin 53:f9ec2c7a47f5 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 53:f9ec2c7a47f5 5 * you may not use this file except in compliance with the License.
mbedAustin 53:f9ec2c7a47f5 6 * You may obtain a copy of the License at
mbedAustin 53:f9ec2c7a47f5 7 *
mbedAustin 53:f9ec2c7a47f5 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 53:f9ec2c7a47f5 9 *
mbedAustin 53:f9ec2c7a47f5 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 53:f9ec2c7a47f5 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 53:f9ec2c7a47f5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 53:f9ec2c7a47f5 13 * See the License for the specific language governing permissions and
mbedAustin 53:f9ec2c7a47f5 14 * limitations under the License.
mbedAustin 53:f9ec2c7a47f5 15 */
mbedAustin 53:f9ec2c7a47f5 16 #ifndef __BLE_IBEACON_SERVICE_H__
mbedAustin 53:f9ec2c7a47f5 17 #define __BLE_IBEACON_SERVICE_H__
mbedAustin 53:f9ec2c7a47f5 18
mbedAustin 53:f9ec2c7a47f5 19 #include "BLEDevice.h"
mbedAustin 53:f9ec2c7a47f5 20
mbedAustin 53:f9ec2c7a47f5 21 /**
mbedAustin 53:f9ec2c7a47f5 22 * @class iBeaconService
mbedAustin 53:f9ec2c7a47f5 23 * @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<br>
mbedAustin 53:f9ec2c7a47f5 24 */
mbedAustin 53:f9ec2c7a47f5 25
mbedAustin 53:f9ec2c7a47f5 26 class iBeaconService
mbedAustin 53:f9ec2c7a47f5 27 {
mbedAustin 53:f9ec2c7a47f5 28 public:
mbedAustin 53:f9ec2c7a47f5 29 iBeaconService(BLEDevice &_ble, uint8_t proxUUID[16],uint16_t majNum,uint16_t minNum,uint8_t txP=0xC8, uint16_t compID=0x004C):
mbedAustin 53:f9ec2c7a47f5 30 ble(_ble)
mbedAustin 53:f9ec2c7a47f5 31 {
mbedAustin 53:f9ec2c7a47f5 32 data.ID = 0x02; // Optional ID field
mbedAustin 53:f9ec2c7a47f5 33 data.len = 0x15; // Len of remaining stuff (16B UUID, 2B Maj, 2B Min, 1B TxP)
mbedAustin 53:f9ec2c7a47f5 34 data.majorNumber = ((majNum<<8) | (majNum >>8));
mbedAustin 53:f9ec2c7a47f5 35 data.minorNumber = ((minNum<<8) | (minNum >>8));
mbedAustin 53:f9ec2c7a47f5 36 data.txPower = txP; // The user should calibrate this to ~1meter fromt he device
mbedAustin 53:f9ec2c7a47f5 37 data.companyID = compID; // Note: all iBeacons use the Apple ID of 0x004C
mbedAustin 53:f9ec2c7a47f5 38
mbedAustin 53:f9ec2c7a47f5 39 // copy across proximity UUID
mbedAustin 53:f9ec2c7a47f5 40 for(int x=0; x<sizeof(data.proximityUUID); x++) {
mbedAustin 53:f9ec2c7a47f5 41 data.proximityUUID[x]=proxUUID[x];
mbedAustin 53:f9ec2c7a47f5 42 }
mbedAustin 53:f9ec2c7a47f5 43
mbedAustin 53:f9ec2c7a47f5 44 // Set up iBeacon data
mbedAustin 53:f9ec2c7a47f5 45 // Generate the 0x020106 part of the iBeacon Prefix
mbedAustin 53:f9ec2c7a47f5 46 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
mbedAustin 53:f9ec2c7a47f5 47 // Generate the 0x1AFF part of the iBeacon Prefix
mbedAustin 53:f9ec2c7a47f5 48 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
mbedAustin 53:f9ec2c7a47f5 49
mbedAustin 53:f9ec2c7a47f5 50 // Set advertising type
mbedAustin 53:f9ec2c7a47f5 51 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
mbedAustin 53:f9ec2c7a47f5 52 }
mbedAustin 53:f9ec2c7a47f5 53
mbedAustin 53:f9ec2c7a47f5 54 public:
mbedAustin 53:f9ec2c7a47f5 55 union {
mbedAustin 53:f9ec2c7a47f5 56 uint8_t raw[25];
mbedAustin 53:f9ec2c7a47f5 57 struct {
mbedAustin 53:f9ec2c7a47f5 58 uint16_t companyID;
mbedAustin 53:f9ec2c7a47f5 59 uint8_t ID;
mbedAustin 53:f9ec2c7a47f5 60 uint8_t len;
mbedAustin 53:f9ec2c7a47f5 61 uint8_t proximityUUID[16];
mbedAustin 53:f9ec2c7a47f5 62 uint16_t majorNumber;
mbedAustin 53:f9ec2c7a47f5 63 uint16_t minorNumber;
mbedAustin 53:f9ec2c7a47f5 64 uint8_t txPower;
mbedAustin 53:f9ec2c7a47f5 65 };
mbedAustin 53:f9ec2c7a47f5 66 } data;
mbedAustin 53:f9ec2c7a47f5 67
mbedAustin 53:f9ec2c7a47f5 68 private:
mbedAustin 53:f9ec2c7a47f5 69 BLEDevice &ble;
mbedAustin 53:f9ec2c7a47f5 70
mbedAustin 53:f9ec2c7a47f5 71 };
mbedAustin 53:f9ec2c7a47f5 72
mbedAustin 53:f9ec2c7a47f5 73 #endif //__BLE_IBEACON_SERVICE_H__