jgh

Dependents:   Migration

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:59 2015 +0100
Revision:
467:143ca3152ffa
Parent:
466:5c2cb68e7c3b
Child:
468:bbf2a395bb8d
Synchronized with git rev f13fe428
Author: Rohit Grover
add variants for DiscoveredCharacteristic::setup()

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 459:a83b41d87755 31 void setup(UUID 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 465:8c4c61279f82 37 void setup(GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn) {
rgrover1 465:8c4c61279f82 38 startHandle = startHandleIn;
rgrover1 465:8c4c61279f82 39 endHandle = endHandleIn;
rgrover1 465:8c4c61279f82 40 }
rgrover1 465:8c4c61279f82 41
rgrover1 465:8c4c61279f82 42 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
rgrover1 465:8c4c61279f82 43 uuid.setupLong(longUUID);
rgrover1 465:8c4c61279f82 44 }
rgrover1 465:8c4c61279f82 45
rgrover1 439:c57413bf88a9 46 public:
rgrover1 466:5c2cb68e7c3b 47 const UUID &getUUID(void) const {
rgrover1 466:5c2cb68e7c3b 48 return uuid;
rgrover1 431:1c8c592430ec 49 }
rgrover1 431:1c8c592430ec 50
rgrover1 439:c57413bf88a9 51 const GattAttribute::Handle_t& getStartHandle(void) const {
rgrover1 439:c57413bf88a9 52 return startHandle;
rgrover1 439:c57413bf88a9 53 }
rgrover1 439:c57413bf88a9 54 const GattAttribute::Handle_t& getEndHandle(void) const {
rgrover1 439:c57413bf88a9 55 return endHandle;
rgrover1 439:c57413bf88a9 56 }
rgrover1 439:c57413bf88a9 57
rgrover1 439:c57413bf88a9 58 public:
rgrover1 461:a636b8ee72f1 59 DiscoveredService() : uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 461:a636b8ee72f1 60 startHandle(GattAttribute::INVALID_HANDLE),
rgrover1 461:a636b8ee72f1 61 endHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 439:c57413bf88a9 62 /* empty */
rgrover1 439:c57413bf88a9 63 }
rgrover1 439:c57413bf88a9 64
rgrover1 439:c57413bf88a9 65 private:
rgrover1 439:c57413bf88a9 66 DiscoveredService(const DiscoveredService &);
rgrover1 439:c57413bf88a9 67
rgrover1 439:c57413bf88a9 68 private:
rgrover1 459:a83b41d87755 69 UUID uuid; /**< UUID of the service. */
rgrover1 438:b55ce5f5715d 70 GattAttribute::Handle_t startHandle; /**< Service Handle Range. */
rgrover1 438:b55ce5f5715d 71 GattAttribute::Handle_t endHandle; /**< Service Handle Range. */
rgrover1 431:1c8c592430ec 72 };
rgrover1 431:1c8c592430ec 73
rgrover1 431:1c8c592430ec 74 /**@brief Structure for holding information about the service and the characteristics found during
rgrover1 431:1c8c592430ec 75 * the discovery process.
rgrover1 431:1c8c592430ec 76 */
rgrover1 440:21c83c010895 77 class DiscoveredCharacteristic {
rgrover1 440:21c83c010895 78 public:
rgrover1 431:1c8c592430ec 79 struct Properties_t {
rgrover1 431:1c8c592430ec 80 static const uint8_t BROADCAST_PROPERTY_MASK = 0x01;
rgrover1 431:1c8c592430ec 81 static const uint8_t READ_PROPERTY_MASK = 0x02;
rgrover1 431:1c8c592430ec 82 static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04;
rgrover1 431:1c8c592430ec 83 static const uint8_t WRITE_PROPERTY_MASK = 0x08;
rgrover1 431:1c8c592430ec 84 static const uint8_t NOTIFY_PROPERTY_MASK = 0x10;
rgrover1 431:1c8c592430ec 85 static const uint8_t INDICATE_PROPERTY_MASK = 0x20;
rgrover1 431:1c8c592430ec 86 static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40;
rgrover1 431:1c8c592430ec 87
rgrover1 431:1c8c592430ec 88 Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) {
rgrover1 431:1c8c592430ec 89 /* empty */
rgrover1 431:1c8c592430ec 90 }
rgrover1 431:1c8c592430ec 91
rgrover1 431:1c8c592430ec 92 Properties_t(uint8_t props) :
rgrover1 431:1c8c592430ec 93 broadcast(props & BROADCAST_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 94 read(props & READ_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 95 write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 96 write(props & WRITE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 97 notify(props & NOTIFY_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 98 indicate(props & INDICATE_PROPERTY_MASK),
rgrover1 431:1c8c592430ec 99 auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) {
rgrover1 431:1c8c592430ec 100 /* empty*/
rgrover1 431:1c8c592430ec 101 }
rgrover1 431:1c8c592430ec 102
rgrover1 431:1c8c592430ec 103 uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
rgrover1 431:1c8c592430ec 104 uint8_t read :1; /**< Reading the value permitted. */
rgrover1 431:1c8c592430ec 105 uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
rgrover1 431:1c8c592430ec 106 uint8_t write :1; /**< Writing the value with Write Request permitted. */
rgrover1 431:1c8c592430ec 107 uint8_t notify :1; /**< Notications of the value permitted. */
rgrover1 431:1c8c592430ec 108 uint8_t indicate :1; /**< Indications of the value permitted. */
rgrover1 431:1c8c592430ec 109 uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 431:1c8c592430ec 110 };
rgrover1 431:1c8c592430ec 111
rgrover1 467:143ca3152ffa 112 void setup(Properties_t propsIn,
rgrover1 467:143ca3152ffa 113 GattAttribute::Handle_t declHandleIn,
rgrover1 467:143ca3152ffa 114 GattAttribute::Handle_t valueHandleIn) {
rgrover1 467:143ca3152ffa 115 props = propsIn;
rgrover1 467:143ca3152ffa 116 declHandle = declHandleIn;
rgrover1 467:143ca3152ffa 117 valueHandle = valueHandleIn;
rgrover1 467:143ca3152ffa 118 }
rgrover1 467:143ca3152ffa 119
rgrover1 461:a636b8ee72f1 120 void setup(UUID::ShortUUIDBytes_t uuidIn,
rgrover1 461:a636b8ee72f1 121 Properties_t propsIn,
rgrover1 461:a636b8ee72f1 122 GattAttribute::Handle_t declHandleIn,
rgrover1 461:a636b8ee72f1 123 GattAttribute::Handle_t valueHandleIn) {
rgrover1 431:1c8c592430ec 124 uuid = uuidIn;
rgrover1 431:1c8c592430ec 125 props = propsIn;
rgrover1 431:1c8c592430ec 126 declHandle = declHandleIn;
rgrover1 431:1c8c592430ec 127 valueHandle = valueHandleIn;
rgrover1 431:1c8c592430ec 128 }
rgrover1 431:1c8c592430ec 129
rgrover1 467:143ca3152ffa 130 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
rgrover1 467:143ca3152ffa 131 uuid.setupLong(longUUID);
rgrover1 467:143ca3152ffa 132 }
rgrover1 467:143ca3152ffa 133
rgrover1 440:21c83c010895 134 public:
rgrover1 460:f5468aee162d 135 UUID::ShortUUIDBytes_t getShortUUID(void) const {
rgrover1 460:f5468aee162d 136 return uuid.getShortUUID();
rgrover1 440:21c83c010895 137 }
rgrover1 440:21c83c010895 138
rgrover1 440:21c83c010895 139 const Properties_t& getProperties(void) const {
rgrover1 440:21c83c010895 140 return props;
rgrover1 440:21c83c010895 141 }
rgrover1 440:21c83c010895 142
rgrover1 440:21c83c010895 143 const GattAttribute::Handle_t& getDeclHandle(void) const {
rgrover1 440:21c83c010895 144 return declHandle;
rgrover1 440:21c83c010895 145 }
rgrover1 440:21c83c010895 146 const GattAttribute::Handle_t& getValueHandle(void) const {
rgrover1 440:21c83c010895 147 return valueHandle;
rgrover1 440:21c83c010895 148 }
rgrover1 440:21c83c010895 149
rgrover1 440:21c83c010895 150 public:
rgrover1 461:a636b8ee72f1 151 DiscoveredCharacteristic() : uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 461:a636b8ee72f1 152 props(),
rgrover1 461:a636b8ee72f1 153 declHandle(GattAttribute::INVALID_HANDLE),
rgrover1 461:a636b8ee72f1 154 valueHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 440:21c83c010895 155 /* empty */
rgrover1 440:21c83c010895 156 }
rgrover1 440:21c83c010895 157
rgrover1 440:21c83c010895 158 private:
rgrover1 460:f5468aee162d 159 UUID uuid;
rgrover1 438:b55ce5f5715d 160 Properties_t props;
rgrover1 438:b55ce5f5715d 161 GattAttribute::Handle_t declHandle;
rgrover1 438:b55ce5f5715d 162 GattAttribute::Handle_t valueHandle;
rgrover1 431:1c8c592430ec 163 };
rgrover1 431:1c8c592430ec 164
rgrover1 431:1c8c592430ec 165 public:
rgrover1 431:1c8c592430ec 166 typedef void (*ServiceCallback_t)(const DiscoveredService &);
rgrover1 431:1c8c592430ec 167 typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &);
rgrover1 457:6ebc9bbde90b 168 typedef void (*TerminationCallback_t)(Gap::Handle_t connectionHandle);
rgrover1 431:1c8c592430ec 169
rgrover1 431:1c8c592430ec 170 public:
rgrover1 456:ff4ffb69e19f 171 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 456:ff4ffb69e19f 172 ServiceCallback_t sc = NULL,
rgrover1 456:ff4ffb69e19f 173 CharacteristicCallback_t cc = NULL,
rgrover1 458:5546ebd25359 174 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 458:5546ebd25359 175 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
rgrover1 431:1c8c592430ec 176
rgrover1 431:1c8c592430ec 177 static void terminate(void);
rgrover1 431:1c8c592430ec 178
rgrover1 457:6ebc9bbde90b 179 static bool isActive(void);
rgrover1 457:6ebc9bbde90b 180 static void onTermination(TerminationCallback_t callback);
rgrover1 457:6ebc9bbde90b 181
rgrover1 431:1c8c592430ec 182 protected:
rgrover1 431:1c8c592430ec 183 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
rgrover1 431:1c8c592430ec 184 UUID matchingServiceUUID;
rgrover1 431:1c8c592430ec 185 ServiceCallback_t serviceCallback;
rgrover1 431:1c8c592430ec 186 UUID matchingCharacteristicUUID;
rgrover1 431:1c8c592430ec 187 CharacteristicCallback_t characteristicCallback;
rgrover1 431:1c8c592430ec 188 };
rgrover1 431:1c8c592430ec 189
rgrover1 431:1c8c592430ec 190 #endif // ifndef __SERVICE_DISOVERY_H__