BLE lib
Fork of Nucleo_BLE_API by
services/LocService.h@4:f1696bf0e6c6, 2015-02-08 (annotated)
- Committer:
- vijaynvr
- Date:
- Sun Feb 08 14:26:05 2015 +0000
- Revision:
- 4:f1696bf0e6c6
- Parent:
- 2:f8c343d5ff07
working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sjallouli | 0:289fd2dae405 | 1 | /* mbed Microcontroller Library |
sjallouli | 0:289fd2dae405 | 2 | * Copyright (c) 2006-2013 ARM Limited |
sjallouli | 0:289fd2dae405 | 3 | * |
sjallouli | 0:289fd2dae405 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sjallouli | 0:289fd2dae405 | 5 | * you may not use this file except in compliance with the License. |
sjallouli | 0:289fd2dae405 | 6 | * You may obtain a copy of the License at |
sjallouli | 0:289fd2dae405 | 7 | * |
sjallouli | 0:289fd2dae405 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sjallouli | 0:289fd2dae405 | 9 | * |
sjallouli | 0:289fd2dae405 | 10 | * Unless required by applicable law or agreed to in writing, software |
sjallouli | 0:289fd2dae405 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sjallouli | 0:289fd2dae405 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sjallouli | 0:289fd2dae405 | 13 | * See the License for the specific language governing permissions and |
sjallouli | 0:289fd2dae405 | 14 | * limitations under the License. |
sjallouli | 0:289fd2dae405 | 15 | */ |
sjallouli | 0:289fd2dae405 | 16 | |
fbd38 | 2:f8c343d5ff07 | 17 | #ifndef __BLE_LOC_SERVICE_H__ |
fbd38 | 2:f8c343d5ff07 | 18 | #define __BLE_LOC_SERVICE_H__ |
sjallouli | 0:289fd2dae405 | 19 | |
sjallouli | 0:289fd2dae405 | 20 | #include "BLEDevice.h" |
sjallouli | 0:289fd2dae405 | 21 | |
fbd38 | 2:f8c343d5ff07 | 22 | // Force value by using already existing data |
fbd38 | 2:f8c343d5ff07 | 23 | #define UUID_LOC_INDEX_CHAR UUID_BATTERY_LEVEL_CHAR |
fbd38 | 2:f8c343d5ff07 | 24 | #define UUID_LOC_SERVICE UUID_GLUCOSE_SERVICE |
fbd38 | 2:f8c343d5ff07 | 25 | |
fbd38 | 2:f8c343d5ff07 | 26 | /* Loc Service */ |
fbd38 | 2:f8c343d5ff07 | 27 | class LocService { |
sjallouli | 0:289fd2dae405 | 28 | public: |
fbd38 | 2:f8c343d5ff07 | 29 | LocService(BLEDevice &_ble, uint8_t loc_index = 0) : |
sjallouli | 0:289fd2dae405 | 30 | ble(_ble), |
fbd38 | 2:f8c343d5ff07 | 31 | locIndex(loc_index), |
fbd38 | 2:f8c343d5ff07 | 32 | locIndexCharacteristic(GattCharacteristic::UUID_LOC_INDEX_CHAR, &locIndex, sizeof(locIndex), sizeof(locIndex), |
fbd38 | 2:f8c343d5ff07 | 33 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) { |
sjallouli | 0:289fd2dae405 | 34 | |
fbd38 | 2:f8c343d5ff07 | 35 | static bool serviceAdded = false; /* We should only ever need to add the loc index service once. */ |
sjallouli | 0:289fd2dae405 | 36 | if (serviceAdded) { |
sjallouli | 0:289fd2dae405 | 37 | return; |
sjallouli | 0:289fd2dae405 | 38 | } |
sjallouli | 0:289fd2dae405 | 39 | |
fbd38 | 2:f8c343d5ff07 | 40 | GattCharacteristic *charTable[] = {&locIndexCharacteristic}; |
fbd38 | 2:f8c343d5ff07 | 41 | GattService locService(GattService::UUID_LOC_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
sjallouli | 0:289fd2dae405 | 42 | |
fbd38 | 2:f8c343d5ff07 | 43 | ble.addService(locService); |
sjallouli | 0:289fd2dae405 | 44 | serviceAdded = true; |
sjallouli | 0:289fd2dae405 | 45 | } |
fbd38 | 2:f8c343d5ff07 | 46 | |
sjallouli | 0:289fd2dae405 | 47 | private: |
fbd38 | 2:f8c343d5ff07 | 48 | BLEDevice &ble; |
fbd38 | 2:f8c343d5ff07 | 49 | uint8_t locIndex; |
fbd38 | 2:f8c343d5ff07 | 50 | GattCharacteristic locIndexCharacteristic; |
sjallouli | 0:289fd2dae405 | 51 | }; |
sjallouli | 0:289fd2dae405 | 52 | |
fbd38 | 2:f8c343d5ff07 | 53 | #endif /* #ifndef __BLE_LOC_SERVICE_H__*/ |