High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
public/ServiceDiscovery.h@439:c57413bf88a9, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:51:55 2015 +0100
- Revision:
- 439:c57413bf88a9
- Parent:
- 438:b55ce5f5715d
- Child:
- 440:21c83c010895
Synchronized with git rev 21c86533
Author: Rohit Grover
turn DiscoveredService into a class.
Who changed what in which revision?
User | Revision | Line number | New 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 | 439:c57413bf88a9 | 31 | void setup(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 | 439:c57413bf88a9 | 38 | const 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 | 438:b55ce5f5715d | 58 | 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 | 431:1c8c592430ec | 66 | struct DiscoveredCharacteristic { |
rgrover1 | 431:1c8c592430ec | 67 | struct Properties_t { |
rgrover1 | 431:1c8c592430ec | 68 | static const uint8_t BROADCAST_PROPERTY_MASK = 0x01; |
rgrover1 | 431:1c8c592430ec | 69 | static const uint8_t READ_PROPERTY_MASK = 0x02; |
rgrover1 | 431:1c8c592430ec | 70 | static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04; |
rgrover1 | 431:1c8c592430ec | 71 | static const uint8_t WRITE_PROPERTY_MASK = 0x08; |
rgrover1 | 431:1c8c592430ec | 72 | static const uint8_t NOTIFY_PROPERTY_MASK = 0x10; |
rgrover1 | 431:1c8c592430ec | 73 | static const uint8_t INDICATE_PROPERTY_MASK = 0x20; |
rgrover1 | 431:1c8c592430ec | 74 | static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40; |
rgrover1 | 431:1c8c592430ec | 75 | |
rgrover1 | 431:1c8c592430ec | 76 | Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) { |
rgrover1 | 431:1c8c592430ec | 77 | /* empty */ |
rgrover1 | 431:1c8c592430ec | 78 | } |
rgrover1 | 431:1c8c592430ec | 79 | |
rgrover1 | 431:1c8c592430ec | 80 | Properties_t(uint8_t props) : |
rgrover1 | 431:1c8c592430ec | 81 | broadcast(props & BROADCAST_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 82 | read(props & READ_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 83 | write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 84 | write(props & WRITE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 85 | notify(props & NOTIFY_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 86 | indicate(props & INDICATE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 87 | auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) { |
rgrover1 | 431:1c8c592430ec | 88 | /* empty*/ |
rgrover1 | 431:1c8c592430ec | 89 | } |
rgrover1 | 431:1c8c592430ec | 90 | |
rgrover1 | 431:1c8c592430ec | 91 | uint8_t broadcast :1; /**< Broadcasting of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 92 | uint8_t read :1; /**< Reading the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 93 | uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */ |
rgrover1 | 431:1c8c592430ec | 94 | uint8_t write :1; /**< Writing the value with Write Request permitted. */ |
rgrover1 | 431:1c8c592430ec | 95 | uint8_t notify :1; /**< Notications of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 96 | uint8_t indicate :1; /**< Indications of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 97 | uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */ |
rgrover1 | 431:1c8c592430ec | 98 | }; |
rgrover1 | 431:1c8c592430ec | 99 | |
rgrover1 | 438:b55ce5f5715d | 100 | void setup(ShortUUIDBytes_t uuidIn, Properties_t propsIn, GattAttribute::Handle_t declHandleIn, GattAttribute::Handle_t valueHandleIn) { |
rgrover1 | 431:1c8c592430ec | 101 | uuid = uuidIn; |
rgrover1 | 431:1c8c592430ec | 102 | props = propsIn; |
rgrover1 | 431:1c8c592430ec | 103 | declHandle = declHandleIn; |
rgrover1 | 431:1c8c592430ec | 104 | valueHandle = valueHandleIn; |
rgrover1 | 431:1c8c592430ec | 105 | } |
rgrover1 | 431:1c8c592430ec | 106 | |
rgrover1 | 438:b55ce5f5715d | 107 | ShortUUIDBytes_t uuid; |
rgrover1 | 438:b55ce5f5715d | 108 | Properties_t props; |
rgrover1 | 438:b55ce5f5715d | 109 | GattAttribute::Handle_t declHandle; |
rgrover1 | 438:b55ce5f5715d | 110 | GattAttribute::Handle_t valueHandle; |
rgrover1 | 431:1c8c592430ec | 111 | }; |
rgrover1 | 431:1c8c592430ec | 112 | |
rgrover1 | 431:1c8c592430ec | 113 | public: |
rgrover1 | 431:1c8c592430ec | 114 | typedef void (*ServiceCallback_t)(const DiscoveredService &); |
rgrover1 | 431:1c8c592430ec | 115 | typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &); |
rgrover1 | 431:1c8c592430ec | 116 | |
rgrover1 | 431:1c8c592430ec | 117 | public: |
rgrover1 | 431:1c8c592430ec | 118 | static ble_error_t launch(Gap::Handle_t connectionHandle, |
rgrover1 | 431:1c8c592430ec | 119 | ServiceCallback_t sc, |
rgrover1 | 431:1c8c592430ec | 120 | CharacteristicCallback_t cc = NULL); |
rgrover1 | 431:1c8c592430ec | 121 | static ble_error_t launch(Gap::Handle_t connectionHandle, |
rgrover1 | 431:1c8c592430ec | 122 | UUID matchingServiceUUIDIn, |
rgrover1 | 431:1c8c592430ec | 123 | ServiceCallback_t sc, |
rgrover1 | 431:1c8c592430ec | 124 | UUID matchingCharacteristicUUIDIn = ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 431:1c8c592430ec | 125 | CharacteristicCallback_t cc = NULL); |
rgrover1 | 431:1c8c592430ec | 126 | |
rgrover1 | 431:1c8c592430ec | 127 | static void terminate(void); |
rgrover1 | 431:1c8c592430ec | 128 | |
rgrover1 | 431:1c8c592430ec | 129 | protected: |
rgrover1 | 431:1c8c592430ec | 130 | Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */ |
rgrover1 | 431:1c8c592430ec | 131 | UUID matchingServiceUUID; |
rgrover1 | 431:1c8c592430ec | 132 | ServiceCallback_t serviceCallback; |
rgrover1 | 431:1c8c592430ec | 133 | UUID matchingCharacteristicUUID; |
rgrover1 | 431:1c8c592430ec | 134 | CharacteristicCallback_t characteristicCallback; |
rgrover1 | 431:1c8c592430ec | 135 | }; |
rgrover1 | 431:1c8c592430ec | 136 | |
rgrover1 | 431:1c8c592430ec | 137 | #endif // ifndef __SERVICE_DISOVERY_H__ |