test

Dependents:   BLE_PowerBank_HeyFaradey

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:59 2015 +0100
Revision:
466:5c2cb68e7c3b
Parent:
465:8c4c61279f82
Child:
467:143ca3152ffa
Synchronized with git rev 3c76cf7e
Author: Rohit Grover
switch DiscoveredService::getShortUUID() to getUUID()

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 461:a636b8ee72f1 112 void setup(UUID::ShortUUIDBytes_t uuidIn,
rgrover1 461:a636b8ee72f1 113 Properties_t propsIn,
rgrover1 461:a636b8ee72f1 114 GattAttribute::Handle_t declHandleIn,
rgrover1 461:a636b8ee72f1 115 GattAttribute::Handle_t valueHandleIn) {
rgrover1 431:1c8c592430ec 116 uuid = uuidIn;
rgrover1 431:1c8c592430ec 117 props = propsIn;
rgrover1 431:1c8c592430ec 118 declHandle = declHandleIn;
rgrover1 431:1c8c592430ec 119 valueHandle = valueHandleIn;
rgrover1 431:1c8c592430ec 120 }
rgrover1 431:1c8c592430ec 121
rgrover1 440:21c83c010895 122 public:
rgrover1 460:f5468aee162d 123 UUID::ShortUUIDBytes_t getShortUUID(void) const {
rgrover1 460:f5468aee162d 124 return uuid.getShortUUID();
rgrover1 440:21c83c010895 125 }
rgrover1 440:21c83c010895 126
rgrover1 440:21c83c010895 127 const Properties_t& getProperties(void) const {
rgrover1 440:21c83c010895 128 return props;
rgrover1 440:21c83c010895 129 }
rgrover1 440:21c83c010895 130
rgrover1 440:21c83c010895 131 const GattAttribute::Handle_t& getDeclHandle(void) const {
rgrover1 440:21c83c010895 132 return declHandle;
rgrover1 440:21c83c010895 133 }
rgrover1 440:21c83c010895 134 const GattAttribute::Handle_t& getValueHandle(void) const {
rgrover1 440:21c83c010895 135 return valueHandle;
rgrover1 440:21c83c010895 136 }
rgrover1 440:21c83c010895 137
rgrover1 440:21c83c010895 138 public:
rgrover1 461:a636b8ee72f1 139 DiscoveredCharacteristic() : uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 461:a636b8ee72f1 140 props(),
rgrover1 461:a636b8ee72f1 141 declHandle(GattAttribute::INVALID_HANDLE),
rgrover1 461:a636b8ee72f1 142 valueHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 440:21c83c010895 143 /* empty */
rgrover1 440:21c83c010895 144 }
rgrover1 440:21c83c010895 145
rgrover1 440:21c83c010895 146 private:
rgrover1 460:f5468aee162d 147 UUID uuid;
rgrover1 438:b55ce5f5715d 148 Properties_t props;
rgrover1 438:b55ce5f5715d 149 GattAttribute::Handle_t declHandle;
rgrover1 438:b55ce5f5715d 150 GattAttribute::Handle_t valueHandle;
rgrover1 431:1c8c592430ec 151 };
rgrover1 431:1c8c592430ec 152
rgrover1 431:1c8c592430ec 153 public:
rgrover1 431:1c8c592430ec 154 typedef void (*ServiceCallback_t)(const DiscoveredService &);
rgrover1 431:1c8c592430ec 155 typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &);
rgrover1 457:6ebc9bbde90b 156 typedef void (*TerminationCallback_t)(Gap::Handle_t connectionHandle);
rgrover1 431:1c8c592430ec 157
rgrover1 431:1c8c592430ec 158 public:
rgrover1 456:ff4ffb69e19f 159 static ble_error_t launch(Gap::Handle_t connectionHandle,
rgrover1 456:ff4ffb69e19f 160 ServiceCallback_t sc = NULL,
rgrover1 456:ff4ffb69e19f 161 CharacteristicCallback_t cc = NULL,
rgrover1 458:5546ebd25359 162 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 458:5546ebd25359 163 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
rgrover1 431:1c8c592430ec 164
rgrover1 431:1c8c592430ec 165 static void terminate(void);
rgrover1 431:1c8c592430ec 166
rgrover1 457:6ebc9bbde90b 167 static bool isActive(void);
rgrover1 457:6ebc9bbde90b 168 static void onTermination(TerminationCallback_t callback);
rgrover1 457:6ebc9bbde90b 169
rgrover1 431:1c8c592430ec 170 protected:
rgrover1 431:1c8c592430ec 171 Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
rgrover1 431:1c8c592430ec 172 UUID matchingServiceUUID;
rgrover1 431:1c8c592430ec 173 ServiceCallback_t serviceCallback;
rgrover1 431:1c8c592430ec 174 UUID matchingCharacteristicUUID;
rgrover1 431:1c8c592430ec 175 CharacteristicCallback_t characteristicCallback;
rgrover1 431:1c8c592430ec 176 };
rgrover1 431:1c8c592430ec 177
rgrover1 431:1c8c592430ec 178 #endif // ifndef __SERVICE_DISOVERY_H__