BLE

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:57 2015 +0100
Revision:
457:ff4ffb69e19f
Parent:
456:b117ff978aec
Child:
458:6ebc9bbde90b
Synchronized with git rev 09063c36
Author: Rohit Grover
ServiceDiscovery::Launch() should take in const references for UUID.

Who changed what in which revision?

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