High level Bluetooth Low Energy API and radio abstraction layer

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:58 2015 +0100
Revision:
458:5546ebd25359
Parent:
457:6ebc9bbde90b
Child:
459:a83b41d87755
Synchronized with git rev 081ceb5c
Author: Rohit Grover
Move certain UUID related declarations within the UUID namespace.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 431:1c8c592430ec 1 /* mbed Microcontroller Library
rgrover1 431:1c8c592430ec 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 431:1c8c592430ec 3 *
rgrover1 431:1c8c592430ec 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 431:1c8c592430ec 5 * you may not use this file except in compliance with the License.
rgrover1 431:1c8c592430ec 6 * You may obtain a copy of the License at
rgrover1 431:1c8c592430ec 7 *
rgrover1 431:1c8c592430ec 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 431:1c8c592430ec 9 *
rgrover1 431:1c8c592430ec 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 431:1c8c592430ec 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 431:1c8c592430ec 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 431:1c8c592430ec 13 * See the License for the specific language governing permissions and
rgrover1 431:1c8c592430ec 14 * limitations under the License.
rgrover1 431:1c8c592430ec 15 */
rgrover1 431:1c8c592430ec 16
rgrover1 431:1c8c592430ec 17 #ifndef __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 18 #define __SERVICE_DISOVERY_H__
rgrover1 431:1c8c592430ec 19
rgrover1 431:1c8c592430ec 20 #include "UUID.h"
rgrover1 431:1c8c592430ec 21 #include "Gap.h"
rgrover1 438:b55ce5f5715d 22 #include "GattAttribute.h"
rgrover1 431:1c8c592430ec 23
rgrover1 431:1c8c592430ec 24 class ServiceDiscovery {
rgrover1 431:1c8c592430ec 25 public:
rgrover1 439:c57413bf88a9 26 /**@brief Type for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 27 * the discovery process.
rgrover1 431:1c8c592430ec 28 */
rgrover1 439:c57413bf88a9 29 class DiscoveredService {
rgrover1 439:c57413bf88a9 30 public:
rgrover1 458:5546ebd25359 31 void setup(UUID::ShortUUIDBytes_t uuidIn, GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
rgrover1 431:1c8c592430ec 32 uuid = uuidIn;
rgrover1 439:c57413bf88a9 33 startHandle = startHandleIn;
rgrover1 439:c57413bf88a9 34 endHandle = endHandleIn;
rgrover1 439:c57413bf88a9 35 }
rgrover1 439:c57413bf88a9 36
rgrover1 439:c57413bf88a9 37 public:
rgrover1 458:5546ebd25359 38 const UUID::ShortUUIDBytes_t& getShortUUID(void) const {
rgrover1 439:c57413bf88a9 39 return uuid;
rgrover1 431:1c8c592430ec 40 }
rgrover1 431:1c8c592430ec 41
rgrover1 439:c57413bf88a9 42 const GattAttribute::Handle_t& getStartHandle(void) const {
rgrover1 439:c57413bf88a9 43 return startHandle;
rgrover1 439:c57413bf88a9 44 }
rgrover1 439:c57413bf88a9 45 const GattAttribute::Handle_t& getEndHandle(void) const {
rgrover1 439:c57413bf88a9 46 return endHandle;
rgrover1 439:c57413bf88a9 47 }
rgrover1 439:c57413bf88a9 48
rgrover1 439:c57413bf88a9 49 public:
rgrover1 439:c57413bf88a9 50 DiscoveredService() : uuid(0), startHandle(GattAttribute::INVALID_HANDLE), endHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 439:c57413bf88a9 51 /* empty */
rgrover1 439:c57413bf88a9 52 }
rgrover1 439:c57413bf88a9 53
rgrover1 439:c57413bf88a9 54 private:
rgrover1 439:c57413bf88a9 55 DiscoveredService(const DiscoveredService &);
rgrover1 439:c57413bf88a9 56
rgrover1 439:c57413bf88a9 57 private:
rgrover1 458:5546ebd25359 58 UUID::ShortUUIDBytes_t uuid; /**< UUID of the service. */
rgrover1 438:b55ce5f5715d 59 GattAttribute::Handle_t startHandle; /**< Service Handle Range. */
rgrover1 438:b55ce5f5715d 60 GattAttribute::Handle_t endHandle; /**< Service Handle Range. */
rgrover1 431:1c8c592430ec 61 };
rgrover1 431:1c8c592430ec 62
rgrover1 431:1c8c592430ec 63 /**@brief Structure for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 64 * the discovery process.
rgrover1 431:1c8c592430ec 65 */
rgrover1 440:21c83c010895 66 class DiscoveredCharacteristic {
rgrover1 440:21c83c010895 67 public:
rgrover1 431:1c8c592430ec 68 struct Properties_t {
rgrover1 431:1c8c592430ec 69 static const uint8_t BROADCAST_PROPERTY_MASK = 0x01;
rgrover1 431:1c8c592430ec 70 static const uint8_t READ_PROPERTY_MASK = 0x02;
rgrover1 431:1c8c592430ec 71 static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04;
rgrover1 431:1c8c592430ec 72 static const uint8_t WRITE_PROPERTY_MASK = 0x08;
rgrover1 431:1c8c592430ec 73 static const uint8_t NOTIFY_PROPERTY_MASK = 0x10;
rgrover1 431:1c8c592430ec 74 static const uint8_t INDICATE_PROPERTY_MASK = 0x20;
rgrover1 431:1c8c592430ec 75 static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40;
rgrover1 431:1c8c592430ec 76
rgrover1 431:1c8c592430ec 77 Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) {
rgrover1 431:1c8c592430ec 78 /* empty */
rgrover1 431:1c8c592430ec 79 }
rgrover1 431:1c8c592430ec 80
rgrover1 431:1c8c592430ec 81 Properties_t(uint8_t props) :
rgrover1 431:1c8c592430ec 82 broadcast(props & BROADCAST_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 83 read(props & READ_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 84 write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 85 write(props & WRITE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 86 notify(props & NOTIFY_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 87 indicate(props & INDICATE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 88 auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) {
rgrover1 431:1c8c592430ec 89 /* empty*/
rgrover1 431:1c8c592430ec 90 }
rgrover1 431:1c8c592430ec 91
rgrover1 431:1c8c592430ec 92 uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
rgrover1 431:1c8c592430ec 93 uint8_t read :1; /**< Reading the value permitted. */
rgrover1 431:1c8c592430ec 94 uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
rgrover1 431:1c8c592430ec 95 uint8_t write :1; /**< Writing the value with Write Request permitted. */
rgrover1 431:1c8c592430ec 96 uint8_t notify :1; /**< Notications of the value permitted. */
rgrover1 431:1c8c592430ec 97 uint8_t indicate :1; /**< Indications of the value permitted. */
rgrover1 431:1c8c592430ec 98 uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 431:1c8c592430ec 99 };
rgrover1 431:1c8c592430ec 100
rgrover1 458:5546ebd25359 101 void setup(UUID::ShortUUIDBytes_t uuidIn, Properties_t propsIn, GattAttribute::Handle_t declHandleIn, GattAttribute::Handle_t valueHandleIn) {
rgrover1 431:1c8c592430ec 102 uuid = uuidIn;
rgrover1 431:1c8c592430ec 103 props = propsIn;
rgrover1 431:1c8c592430ec 104 declHandle = declHandleIn;
rgrover1 431:1c8c592430ec 105 valueHandle = valueHandleIn;
rgrover1 431:1c8c592430ec 106 }
rgrover1 431:1c8c592430ec 107
rgrover1 440:21c83c010895 108 public:
rgrover1 458:5546ebd25359 109 const UUID::ShortUUIDBytes_t& getShortUUID(void) const {
rgrover1 440:21c83c010895 110 return uuid;
rgrover1 440:21c83c010895 111 }
rgrover1 440:21c83c010895 112
rgrover1 440:21c83c010895 113 const Properties_t& getProperties(void) const {
rgrover1 440:21c83c010895 114 return props;
rgrover1 440:21c83c010895 115 }
rgrover1 440:21c83c010895 116
rgrover1 440:21c83c010895 117 const GattAttribute::Handle_t& getDeclHandle(void) const {
rgrover1 440:21c83c010895 118 return declHandle;
rgrover1 440:21c83c010895 119 }
rgrover1 440:21c83c010895 120 const GattAttribute::Handle_t& getValueHandle(void) const {
rgrover1 440:21c83c010895 121 return valueHandle;
rgrover1 440:21c83c010895 122 }
rgrover1 440:21c83c010895 123
rgrover1 440:21c83c010895 124 public:
rgrover1 440:21c83c010895 125 DiscoveredCharacteristic() : uuid(0), props(), declHandle(GattAttribute::INVALID_HANDLE), valueHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 440:21c83c010895 126 /* empty */
rgrover1 440:21c83c010895 127 }
rgrover1 440:21c83c010895 128
rgrover1 440:21c83c010895 129 private:
rgrover1 458:5546ebd25359 130 UUID::ShortUUIDBytes_t uuid;
rgrover1 438:b55ce5f5715d 131 Properties_t props;
rgrover1 438:b55ce5f5715d 132 GattAttribute::Handle_t declHandle;
rgrover1 438:b55ce5f5715d 133 GattAttribute::Handle_t valueHandle;
rgrover1 431:1c8c592430ec 134 };
rgrover1 431:1c8c592430ec 135
rgrover1 431:1c8c592430ec 136 public:
rgrover1 431:1c8c592430ec 137 typedef void (*ServiceCallback_t)(const DiscoveredService &);
rgrover1 431:1c8c592430ec 138 typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &);
rgrover1 457:6ebc9bbde90b 139 typedef void (*TerminationCallback_t)(Gap::Handle_t connectionHandle);
rgrover1 431:1c8c592430ec 140
rgrover1 431:1c8c592430ec 141 public:
rgrover1 456:ff4ffb69e19f 142 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 456:ff4ffb69e19f 143 ServiceCallback_t sc = NULL,
rgrover1 456:ff4ffb69e19f 144 CharacteristicCallback_t cc = NULL,
rgrover1 458:5546ebd25359 145 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 458:5546ebd25359 146 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
rgrover1 431:1c8c592430ec 147
rgrover1 431:1c8c592430ec 148 static void terminate(void);
rgrover1 431:1c8c592430ec 149
rgrover1 457:6ebc9bbde90b 150 static bool isActive(void);
rgrover1 457:6ebc9bbde90b 151 static void onTermination(TerminationCallback_t callback);
rgrover1 457:6ebc9bbde90b 152
rgrover1 431:1c8c592430ec 153 protected:
rgrover1 431:1c8c592430ec 154 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
rgrover1 431:1c8c592430ec 155 UUID matchingServiceUUID;
rgrover1 431:1c8c592430ec 156 ServiceCallback_t serviceCallback;
rgrover1 431:1c8c592430ec 157 UUID matchingCharacteristicUUID;
rgrover1 431:1c8c592430ec 158 CharacteristicCallback_t characteristicCallback;
rgrover1 431:1c8c592430ec 159 };
rgrover1 431:1c8c592430ec 160
rgrover1 431:1c8c592430ec 161 #endif // ifndef __SERVICE_DISOVERY_H__