Fixes to BLE_API for mbedOS Alpha1 release. Mostly relating to doxygen fixes.

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Nov 28 14:11:19 2014 +0000
Revision:
147:f772d9b93808
Child:
148:0072d73e966f
Synchronized with git rev dca34515
Author: Rohit Grover
initial commit for URIBeacon Service.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 147:f772d9b93808 1 /* mbed Microcontroller Library
rgrover1 147:f772d9b93808 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 147:f772d9b93808 3 *
rgrover1 147:f772d9b93808 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 147:f772d9b93808 5 * you may not use this file except in compliance with the License.
rgrover1 147:f772d9b93808 6 * You may obtain a copy of the License at
rgrover1 147:f772d9b93808 7 *
rgrover1 147:f772d9b93808 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 147:f772d9b93808 9 *
rgrover1 147:f772d9b93808 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 147:f772d9b93808 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 147:f772d9b93808 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 147:f772d9b93808 13 * See the License for the specific language governing permissions and
rgrover1 147:f772d9b93808 14 * limitations under the License.
rgrover1 147:f772d9b93808 15 */
rgrover1 147:f772d9b93808 16
rgrover1 147:f772d9b93808 17 #ifndef __BLE_URI_BEACON_2_SERVICE_H__
rgrover1 147:f772d9b93808 18 #define __BLE_URI_BEACON_2_SERVICE_H__
rgrover1 147:f772d9b93808 19
rgrover1 147:f772d9b93808 20 #include "BLEDevice.h"
rgrover1 147:f772d9b93808 21
rgrover1 147:f772d9b93808 22 class URIBeacon2Service {
rgrover1 147:f772d9b93808 23 public:
rgrover1 147:f772d9b93808 24
rgrover1 147:f772d9b93808 25 // ee0c2080-8786-40ba-ab96-99b91ac981d8
rgrover1 147:f772d9b93808 26
rgrover1 147:f772d9b93808 27 URIBeacon2Service(BLEDevice &ble_, const uint8_t urldata_[], size_t sizeofURLData) : ble(ble_), payload() {
rgrover1 147:f772d9b93808 28 if ((sizeofURLData + 4) > 24) {
rgrover1 147:f772d9b93808 29 return;
rgrover1 147:f772d9b93808 30 }
rgrover1 147:f772d9b93808 31
rgrover1 147:f772d9b93808 32 const uint8_t BEACON_UUID[] = {0xD8, 0xFE};
rgrover1 147:f772d9b93808 33
rgrover1 147:f772d9b93808 34 payload[0] = BEACON_UUID[0];
rgrover1 147:f772d9b93808 35 payload[1] = BEACON_UUID[1];
rgrover1 147:f772d9b93808 36 payload[2] = 0x00; /* flags */
rgrover1 147:f772d9b93808 37 payload[3] = 0x20; /* power */
rgrover1 147:f772d9b93808 38 encodeURIData(urldata_, sizeofURLData);
rgrover1 147:f772d9b93808 39
rgrover1 147:f772d9b93808 40 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID));
rgrover1 147:f772d9b93808 41 ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, payload, sizeofURLData + 4);
rgrover1 147:f772d9b93808 42 }
rgrover1 147:f772d9b93808 43
rgrover1 147:f772d9b93808 44 private:
rgrover1 147:f772d9b93808 45 void encodeURIData(const uint8_t urldata_[], size_t sizeofURLData) {
rgrover1 147:f772d9b93808 46 memcpy(&payload[4], urldata_, sizeofURLData);
rgrover1 147:f772d9b93808 47 // |Decimal | Hex | Expansion
rgrover1 147:f772d9b93808 48 // |:------- | :--------- | :--------
rgrover1 147:f772d9b93808 49 // |0 | 0x00 | http://www.
rgrover1 147:f772d9b93808 50 // |1 | 0x01 | https://www.
rgrover1 147:f772d9b93808 51 // |2 | 0x02 | http://
rgrover1 147:f772d9b93808 52 // |3 | 0x03 | https://
rgrover1 147:f772d9b93808 53 // |4 | 0x04 | urn:uuid:
rgrover1 147:f772d9b93808 54 }
rgrover1 147:f772d9b93808 55
rgrover1 147:f772d9b93808 56 // URIBeacon2Service(BLEDevice &_ble, uint8_t level = 100) :
rgrover1 147:f772d9b93808 57 // ble(_ble),
rgrover1 147:f772d9b93808 58 // batteryLevel(level),
rgrover1 147:f772d9b93808 59 // batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, sizeof(batteryLevel), sizeof(batteryLevel),
rgrover1 147:f772d9b93808 60 // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
rgrover1 147:f772d9b93808 61
rgrover1 147:f772d9b93808 62 // static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
rgrover1 147:f772d9b93808 63 // if (serviceAdded) {
rgrover1 147:f772d9b93808 64 // return;
rgrover1 147:f772d9b93808 65 // }
rgrover1 147:f772d9b93808 66
rgrover1 147:f772d9b93808 67 // GattCharacteristic *charTable[] = {&batteryLevelCharacteristic};
rgrover1 147:f772d9b93808 68 // GattService batteryService(GattService::UUID_BATTERY_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
rgrover1 147:f772d9b93808 69
rgrover1 147:f772d9b93808 70 // ble.addService(batteryService);
rgrover1 147:f772d9b93808 71 // serviceAdded = true;
rgrover1 147:f772d9b93808 72 // }
rgrover1 147:f772d9b93808 73 //
rgrover1 147:f772d9b93808 74
rgrover1 147:f772d9b93808 75 private:
rgrover1 147:f772d9b93808 76 static const size_t MAX_SIZEOF_PAYLOAD = 32; /* TODO */
rgrover1 147:f772d9b93808 77
rgrover1 147:f772d9b93808 78 private:
rgrover1 147:f772d9b93808 79 BLEDevice &ble;
rgrover1 147:f772d9b93808 80 uint8_t payload[MAX_SIZEOF_PAYLOAD];
rgrover1 147:f772d9b93808 81 // uint8_t batteryLevel;
rgrover1 147:f772d9b93808 82 // GattCharacteristic batteryLevelCharacteristic;
rgrover1 147:f772d9b93808 83 };
rgrover1 147:f772d9b93808 84
rgrover1 147:f772d9b93808 85 #endif /* #ifndef __BLE_URI_BEACON_2_SERVICE_H__*/