High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
public/ServiceDiscovery.h@438:b55ce5f5715d, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:51:55 2015 +0100
- Revision:
- 438:b55ce5f5715d
- Parent:
- 431:1c8c592430ec
- Child:
- 439:c57413bf88a9
Synchronized with git rev b2c77f03
Author: Rohit Grover
should use GattAttribute::Handle_t
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 | 431:1c8c592430ec | 26 | /**@brief Structure for holding information about the service and the characteristics found during |
rgrover1 | 431:1c8c592430ec | 27 | * the discovery process. |
rgrover1 | 431:1c8c592430ec | 28 | */ |
rgrover1 | 431:1c8c592430ec | 29 | struct DiscoveredService { |
rgrover1 | 431:1c8c592430ec | 30 | void setup(ShortUUIDBytes_t uuidIn, Gap::Handle_t start, Gap::Handle_t end) { |
rgrover1 | 431:1c8c592430ec | 31 | uuid = uuidIn; |
rgrover1 | 431:1c8c592430ec | 32 | startHandle = start; |
rgrover1 | 431:1c8c592430ec | 33 | endHandle = end; |
rgrover1 | 431:1c8c592430ec | 34 | } |
rgrover1 | 431:1c8c592430ec | 35 | |
rgrover1 | 438:b55ce5f5715d | 36 | ShortUUIDBytes_t uuid; /**< UUID of the service. */ |
rgrover1 | 438:b55ce5f5715d | 37 | GattAttribute::Handle_t startHandle; /**< Service Handle Range. */ |
rgrover1 | 438:b55ce5f5715d | 38 | GattAttribute::Handle_t endHandle; /**< Service Handle Range. */ |
rgrover1 | 431:1c8c592430ec | 39 | }; |
rgrover1 | 431:1c8c592430ec | 40 | |
rgrover1 | 431:1c8c592430ec | 41 | /**@brief Structure for holding information about the service and the characteristics found during |
rgrover1 | 431:1c8c592430ec | 42 | * the discovery process. |
rgrover1 | 431:1c8c592430ec | 43 | */ |
rgrover1 | 431:1c8c592430ec | 44 | struct DiscoveredCharacteristic { |
rgrover1 | 431:1c8c592430ec | 45 | struct Properties_t { |
rgrover1 | 431:1c8c592430ec | 46 | static const uint8_t BROADCAST_PROPERTY_MASK = 0x01; |
rgrover1 | 431:1c8c592430ec | 47 | static const uint8_t READ_PROPERTY_MASK = 0x02; |
rgrover1 | 431:1c8c592430ec | 48 | static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04; |
rgrover1 | 431:1c8c592430ec | 49 | static const uint8_t WRITE_PROPERTY_MASK = 0x08; |
rgrover1 | 431:1c8c592430ec | 50 | static const uint8_t NOTIFY_PROPERTY_MASK = 0x10; |
rgrover1 | 431:1c8c592430ec | 51 | static const uint8_t INDICATE_PROPERTY_MASK = 0x20; |
rgrover1 | 431:1c8c592430ec | 52 | static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40; |
rgrover1 | 431:1c8c592430ec | 53 | |
rgrover1 | 431:1c8c592430ec | 54 | Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) { |
rgrover1 | 431:1c8c592430ec | 55 | /* empty */ |
rgrover1 | 431:1c8c592430ec | 56 | } |
rgrover1 | 431:1c8c592430ec | 57 | |
rgrover1 | 431:1c8c592430ec | 58 | Properties_t(uint8_t props) : |
rgrover1 | 431:1c8c592430ec | 59 | broadcast(props & BROADCAST_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 60 | read(props & READ_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 61 | write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 62 | write(props & WRITE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 63 | notify(props & NOTIFY_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 64 | indicate(props & INDICATE_PROPERTY_MASK), |
rgrover1 | 431:1c8c592430ec | 65 | auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) { |
rgrover1 | 431:1c8c592430ec | 66 | /* empty*/ |
rgrover1 | 431:1c8c592430ec | 67 | } |
rgrover1 | 431:1c8c592430ec | 68 | |
rgrover1 | 431:1c8c592430ec | 69 | uint8_t broadcast :1; /**< Broadcasting of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 70 | uint8_t read :1; /**< Reading the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 71 | uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */ |
rgrover1 | 431:1c8c592430ec | 72 | uint8_t write :1; /**< Writing the value with Write Request permitted. */ |
rgrover1 | 431:1c8c592430ec | 73 | uint8_t notify :1; /**< Notications of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 74 | uint8_t indicate :1; /**< Indications of the value permitted. */ |
rgrover1 | 431:1c8c592430ec | 75 | uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */ |
rgrover1 | 431:1c8c592430ec | 76 | }; |
rgrover1 | 431:1c8c592430ec | 77 | |
rgrover1 | 438:b55ce5f5715d | 78 | void setup(ShortUUIDBytes_t uuidIn, Properties_t propsIn, GattAttribute::Handle_t declHandleIn, GattAttribute::Handle_t valueHandleIn) { |
rgrover1 | 431:1c8c592430ec | 79 | uuid = uuidIn; |
rgrover1 | 431:1c8c592430ec | 80 | props = propsIn; |
rgrover1 | 431:1c8c592430ec | 81 | declHandle = declHandleIn; |
rgrover1 | 431:1c8c592430ec | 82 | valueHandle = valueHandleIn; |
rgrover1 | 431:1c8c592430ec | 83 | } |
rgrover1 | 431:1c8c592430ec | 84 | |
rgrover1 | 438:b55ce5f5715d | 85 | ShortUUIDBytes_t uuid; |
rgrover1 | 438:b55ce5f5715d | 86 | Properties_t props; |
rgrover1 | 438:b55ce5f5715d | 87 | GattAttribute::Handle_t declHandle; |
rgrover1 | 438:b55ce5f5715d | 88 | GattAttribute::Handle_t valueHandle; |
rgrover1 | 431:1c8c592430ec | 89 | }; |
rgrover1 | 431:1c8c592430ec | 90 | |
rgrover1 | 431:1c8c592430ec | 91 | public: |
rgrover1 | 431:1c8c592430ec | 92 | typedef void (*ServiceCallback_t)(const DiscoveredService &); |
rgrover1 | 431:1c8c592430ec | 93 | typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic &); |
rgrover1 | 431:1c8c592430ec | 94 | |
rgrover1 | 431:1c8c592430ec | 95 | public: |
rgrover1 | 431:1c8c592430ec | 96 | static ble_error_t launch(Gap::Handle_t connectionHandle, |
rgrover1 | 431:1c8c592430ec | 97 | ServiceCallback_t sc, |
rgrover1 | 431:1c8c592430ec | 98 | CharacteristicCallback_t cc = NULL); |
rgrover1 | 431:1c8c592430ec | 99 | static ble_error_t launch(Gap::Handle_t connectionHandle, |
rgrover1 | 431:1c8c592430ec | 100 | UUID matchingServiceUUIDIn, |
rgrover1 | 431:1c8c592430ec | 101 | ServiceCallback_t sc, |
rgrover1 | 431:1c8c592430ec | 102 | UUID matchingCharacteristicUUIDIn = ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 431:1c8c592430ec | 103 | CharacteristicCallback_t cc = NULL); |
rgrover1 | 431:1c8c592430ec | 104 | |
rgrover1 | 431:1c8c592430ec | 105 | static void terminate(void); |
rgrover1 | 431:1c8c592430ec | 106 | |
rgrover1 | 431:1c8c592430ec | 107 | protected: |
rgrover1 | 431:1c8c592430ec | 108 | Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */ |
rgrover1 | 431:1c8c592430ec | 109 | UUID matchingServiceUUID; |
rgrover1 | 431:1c8c592430ec | 110 | ServiceCallback_t serviceCallback; |
rgrover1 | 431:1c8c592430ec | 111 | UUID matchingCharacteristicUUID; |
rgrover1 | 431:1c8c592430ec | 112 | CharacteristicCallback_t characteristicCallback; |
rgrover1 | 431:1c8c592430ec | 113 | }; |
rgrover1 | 431:1c8c592430ec | 114 | |
rgrover1 | 431:1c8c592430ec | 115 | #endif // ifndef __SERVICE_DISOVERY_H__ |