BLE_API
public/DiscoveredCharacteristic.h@473:d10415d0a07d, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:51:59 2015 +0100
- Revision:
- 473:d10415d0a07d
- Parent:
- 472:2a040d99104c
- Child:
- 475:eb7fbcfb0e85
Synchronized with git rev 71d64143
Author: Rohit Grover
expand on the comment header for read()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 470:150c2363f776 | 1 | /* mbed Microcontroller Library |
rgrover1 | 470:150c2363f776 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 470:150c2363f776 | 3 | * |
rgrover1 | 470:150c2363f776 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 470:150c2363f776 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 470:150c2363f776 | 6 | * You may obtain a copy of the License at |
rgrover1 | 470:150c2363f776 | 7 | * |
rgrover1 | 470:150c2363f776 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 470:150c2363f776 | 9 | * |
rgrover1 | 470:150c2363f776 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 470:150c2363f776 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 470:150c2363f776 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 470:150c2363f776 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 470:150c2363f776 | 14 | * limitations under the License. |
rgrover1 | 470:150c2363f776 | 15 | */ |
rgrover1 | 470:150c2363f776 | 16 | |
rgrover1 | 470:150c2363f776 | 17 | #ifndef __DISCOVERED_CHARACTERISTIC_H__ |
rgrover1 | 470:150c2363f776 | 18 | #define __DISCOVERED_CHARACTERISTIC_H__ |
rgrover1 | 470:150c2363f776 | 19 | |
rgrover1 | 470:150c2363f776 | 20 | #include "UUID.h" |
rgrover1 | 470:150c2363f776 | 21 | #include "GattAttribute.h" |
rgrover1 | 470:150c2363f776 | 22 | |
rgrover1 | 470:150c2363f776 | 23 | /**@brief Structure for holding information about the service and the characteristics found during |
rgrover1 | 470:150c2363f776 | 24 | * the discovery process. |
rgrover1 | 470:150c2363f776 | 25 | */ |
rgrover1 | 470:150c2363f776 | 26 | class DiscoveredCharacteristic { |
rgrover1 | 470:150c2363f776 | 27 | public: |
rgrover1 | 470:150c2363f776 | 28 | struct Properties_t { |
rgrover1 | 470:150c2363f776 | 29 | static const uint8_t BROADCAST_PROPERTY_MASK = 0x01; |
rgrover1 | 470:150c2363f776 | 30 | static const uint8_t READ_PROPERTY_MASK = 0x02; |
rgrover1 | 470:150c2363f776 | 31 | static const uint8_t WRITE_WO_RESPONSE_PROPERTY_MASK = 0x04; |
rgrover1 | 470:150c2363f776 | 32 | static const uint8_t WRITE_PROPERTY_MASK = 0x08; |
rgrover1 | 470:150c2363f776 | 33 | static const uint8_t NOTIFY_PROPERTY_MASK = 0x10; |
rgrover1 | 470:150c2363f776 | 34 | static const uint8_t INDICATE_PROPERTY_MASK = 0x20; |
rgrover1 | 470:150c2363f776 | 35 | static const uint8_t AUTH_SIGNED_PROPERTY_MASK = 0x40; |
rgrover1 | 470:150c2363f776 | 36 | |
rgrover1 | 470:150c2363f776 | 37 | Properties_t() : broadcast(0), read(0), write_wo_resp(0), write(0), notify(0), indicate(0), auth_signed_wr(0) { |
rgrover1 | 470:150c2363f776 | 38 | /* empty */ |
rgrover1 | 470:150c2363f776 | 39 | } |
rgrover1 | 470:150c2363f776 | 40 | |
rgrover1 | 470:150c2363f776 | 41 | Properties_t(uint8_t props) : |
rgrover1 | 470:150c2363f776 | 42 | broadcast(props & BROADCAST_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 43 | read(props & READ_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 44 | write_wo_resp(props & WRITE_WO_RESPONSE_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 45 | write(props & WRITE_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 46 | notify(props & NOTIFY_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 47 | indicate(props & INDICATE_PROPERTY_MASK), |
rgrover1 | 470:150c2363f776 | 48 | auth_signed_wr(props & AUTH_SIGNED_PROPERTY_MASK) { |
rgrover1 | 470:150c2363f776 | 49 | /* empty*/ |
rgrover1 | 470:150c2363f776 | 50 | } |
rgrover1 | 470:150c2363f776 | 51 | |
rgrover1 | 470:150c2363f776 | 52 | uint8_t broadcast :1; /**< Broadcasting of the value permitted. */ |
rgrover1 | 470:150c2363f776 | 53 | uint8_t read :1; /**< Reading the value permitted. */ |
rgrover1 | 470:150c2363f776 | 54 | uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */ |
rgrover1 | 470:150c2363f776 | 55 | uint8_t write :1; /**< Writing the value with Write Request permitted. */ |
rgrover1 | 470:150c2363f776 | 56 | uint8_t notify :1; /**< Notications of the value permitted. */ |
rgrover1 | 470:150c2363f776 | 57 | uint8_t indicate :1; /**< Indications of the value permitted. */ |
rgrover1 | 470:150c2363f776 | 58 | uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */ |
rgrover1 | 470:150c2363f776 | 59 | }; |
rgrover1 | 470:150c2363f776 | 60 | |
rgrover1 | 470:150c2363f776 | 61 | struct ReadResponse_t { |
rgrover1 | 470:150c2363f776 | 62 | GattAttribute::Handle_t handle; /**< Attribute Handle. */ |
rgrover1 | 470:150c2363f776 | 63 | uint16_t offset; /**< Offset of the attribute data. */ |
rgrover1 | 470:150c2363f776 | 64 | uint16_t len; /**< Attribute data length. */ |
rgrover1 | 470:150c2363f776 | 65 | const uint8_t *data; /**< Attribute data, variable length. */ |
rgrover1 | 470:150c2363f776 | 66 | }; |
rgrover1 | 470:150c2363f776 | 67 | typedef void (*ReadCallback_t)(const ReadResponse_t *params); |
rgrover1 | 470:150c2363f776 | 68 | |
rgrover1 | 470:150c2363f776 | 69 | static void setupOnDataRead(ReadCallback_t callback) { |
rgrover1 | 470:150c2363f776 | 70 | onDataReadCallback = callback; |
rgrover1 | 470:150c2363f776 | 71 | } |
rgrover1 | 470:150c2363f776 | 72 | |
rgrover1 | 471:ed48300978d9 | 73 | /** |
rgrover1 | 471:ed48300978d9 | 74 | * Initiate (or continue) a read for the value attribute, optionally at a |
rgrover1 | 471:ed48300978d9 | 75 | * given offset. If the Characteristic or Descriptor to be read is longer |
rgrover1 | 471:ed48300978d9 | 76 | * than ATT_MTU - 1, this function must be called multiple times with |
rgrover1 | 471:ed48300978d9 | 77 | * appropriate offset to read the complete value. |
rgrover1 | 473:d10415d0a07d | 78 | * |
rgrover1 | 473:d10415d0a07d | 79 | * @return BLE_ERROR_NONE if a read has been initiated, else |
rgrover1 | 473:d10415d0a07d | 80 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 473:d10415d0a07d | 81 | * BLE_STACK_BUSY if some client procedure already in progress. |
rgrover1 | 471:ed48300978d9 | 82 | */ |
rgrover1 | 472:2a040d99104c | 83 | virtual ble_error_t read(uint16_t offset = 0) = 0; |
rgrover1 | 470:150c2363f776 | 84 | |
rgrover1 | 470:150c2363f776 | 85 | public: |
rgrover1 | 470:150c2363f776 | 86 | void setup(Properties_t propsIn, |
rgrover1 | 470:150c2363f776 | 87 | GattAttribute::Handle_t declHandleIn, |
rgrover1 | 470:150c2363f776 | 88 | GattAttribute::Handle_t valueHandleIn) { |
rgrover1 | 470:150c2363f776 | 89 | props = propsIn; |
rgrover1 | 470:150c2363f776 | 90 | declHandle = declHandleIn; |
rgrover1 | 470:150c2363f776 | 91 | valueHandle = valueHandleIn; |
rgrover1 | 470:150c2363f776 | 92 | } |
rgrover1 | 470:150c2363f776 | 93 | |
rgrover1 | 470:150c2363f776 | 94 | void setup(UUID::ShortUUIDBytes_t uuidIn, |
rgrover1 | 470:150c2363f776 | 95 | Properties_t propsIn, |
rgrover1 | 470:150c2363f776 | 96 | GattAttribute::Handle_t declHandleIn, |
rgrover1 | 470:150c2363f776 | 97 | GattAttribute::Handle_t valueHandleIn) { |
rgrover1 | 470:150c2363f776 | 98 | uuid = uuidIn; |
rgrover1 | 470:150c2363f776 | 99 | props = propsIn; |
rgrover1 | 470:150c2363f776 | 100 | declHandle = declHandleIn; |
rgrover1 | 470:150c2363f776 | 101 | valueHandle = valueHandleIn; |
rgrover1 | 470:150c2363f776 | 102 | } |
rgrover1 | 470:150c2363f776 | 103 | |
rgrover1 | 470:150c2363f776 | 104 | void setupLongUUID(UUID::LongUUIDBytes_t longUUID) { |
rgrover1 | 470:150c2363f776 | 105 | uuid.setupLong(longUUID); |
rgrover1 | 470:150c2363f776 | 106 | } |
rgrover1 | 470:150c2363f776 | 107 | |
rgrover1 | 470:150c2363f776 | 108 | public: |
rgrover1 | 470:150c2363f776 | 109 | UUID::ShortUUIDBytes_t getShortUUID(void) const { |
rgrover1 | 470:150c2363f776 | 110 | return uuid.getShortUUID(); |
rgrover1 | 470:150c2363f776 | 111 | } |
rgrover1 | 470:150c2363f776 | 112 | |
rgrover1 | 470:150c2363f776 | 113 | const Properties_t& getProperties(void) const { |
rgrover1 | 470:150c2363f776 | 114 | return props; |
rgrover1 | 470:150c2363f776 | 115 | } |
rgrover1 | 470:150c2363f776 | 116 | |
rgrover1 | 470:150c2363f776 | 117 | const GattAttribute::Handle_t& getDeclHandle(void) const { |
rgrover1 | 470:150c2363f776 | 118 | return declHandle; |
rgrover1 | 470:150c2363f776 | 119 | } |
rgrover1 | 470:150c2363f776 | 120 | const GattAttribute::Handle_t& getValueHandle(void) const { |
rgrover1 | 470:150c2363f776 | 121 | return valueHandle; |
rgrover1 | 470:150c2363f776 | 122 | } |
rgrover1 | 470:150c2363f776 | 123 | |
rgrover1 | 470:150c2363f776 | 124 | public: |
rgrover1 | 470:150c2363f776 | 125 | DiscoveredCharacteristic() : uuid(UUID::ShortUUIDBytes_t(0)), |
rgrover1 | 470:150c2363f776 | 126 | props(), |
rgrover1 | 470:150c2363f776 | 127 | declHandle(GattAttribute::INVALID_HANDLE), |
rgrover1 | 470:150c2363f776 | 128 | valueHandle(GattAttribute::INVALID_HANDLE) { |
rgrover1 | 470:150c2363f776 | 129 | /* empty */ |
rgrover1 | 470:150c2363f776 | 130 | } |
rgrover1 | 470:150c2363f776 | 131 | |
rgrover1 | 470:150c2363f776 | 132 | private: |
rgrover1 | 470:150c2363f776 | 133 | UUID uuid; |
rgrover1 | 470:150c2363f776 | 134 | Properties_t props; |
rgrover1 | 470:150c2363f776 | 135 | GattAttribute::Handle_t declHandle; |
rgrover1 | 470:150c2363f776 | 136 | GattAttribute::Handle_t valueHandle; |
rgrover1 | 470:150c2363f776 | 137 | |
rgrover1 | 470:150c2363f776 | 138 | static ReadCallback_t onDataReadCallback; |
rgrover1 | 470:150c2363f776 | 139 | }; |
rgrover1 | 470:150c2363f776 | 140 | |
rgrover1 | 470:150c2363f776 | 141 | #endif /*__DISCOVERED_CHARACTERISTIC_H__*/ |