fka mod

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:51:58 2015 +0100
Revision:
461:a636b8ee72f1
Parent:
460:f5468aee162d
Child:
465:8c4c61279f82
Synchronized with git rev dc406f5b
Author: Rohit Grover
white space diffs.

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