Lancaster University's fork of the mbed BLE API. Lives on github, https://github.com/lancaster-university/BLE_API
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
public/DiscoveredCharacteristic.h@486:bcb77e15d152, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:52:01 2015 +0100
- Revision:
- 486:bcb77e15d152
- Parent:
- 485:313482e1b568
- Child:
- 488:bdba688a550f
Synchronized with git rev 0390ccc1
Author: Rohit Grover
DiscoveredCharacteristic: expand comment header for read() and writeWoResponse() to include NOT_PERMITTED.
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 | 485:313482e1b568 | 23 | /** |
rgrover1 | 485:313482e1b568 | 24 | * Structure for holding information about the service and the characteristics |
rgrover1 | 485:313482e1b568 | 25 | * found during the discovery process. |
rgrover1 | 470:150c2363f776 | 26 | */ |
rgrover1 | 470:150c2363f776 | 27 | class DiscoveredCharacteristic { |
rgrover1 | 470:150c2363f776 | 28 | public: |
rgrover1 | 470:150c2363f776 | 29 | struct Properties_t { |
rgrover1 | 485:313482e1b568 | 30 | uint8_t _broadcast :1; /**< Broadcasting of the value permitted. */ |
rgrover1 | 485:313482e1b568 | 31 | uint8_t _read :1; /**< Reading the value permitted. */ |
rgrover1 | 485:313482e1b568 | 32 | uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */ |
rgrover1 | 485:313482e1b568 | 33 | uint8_t _write :1; /**< Writing the value with Write Request permitted. */ |
rgrover1 | 485:313482e1b568 | 34 | uint8_t _notify :1; /**< Notications of the value permitted. */ |
rgrover1 | 485:313482e1b568 | 35 | uint8_t _indicate :1; /**< Indications of the value permitted. */ |
rgrover1 | 485:313482e1b568 | 36 | uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */ |
rgrover1 | 470:150c2363f776 | 37 | |
rgrover1 | 485:313482e1b568 | 38 | public: |
rgrover1 | 485:313482e1b568 | 39 | bool broadcast(void) const {return _broadcast; } |
rgrover1 | 485:313482e1b568 | 40 | bool read(void) const {return _read; } |
rgrover1 | 485:313482e1b568 | 41 | bool writeWoResp(void) const {return _writeWoResp; } |
rgrover1 | 485:313482e1b568 | 42 | bool write(void) const {return _write; } |
rgrover1 | 485:313482e1b568 | 43 | bool notify(void) const {return _notify; } |
rgrover1 | 485:313482e1b568 | 44 | bool indicate(void) const {return _indicate; } |
rgrover1 | 485:313482e1b568 | 45 | bool authSignedWrite(void) const {return _authSignedWrite;} |
rgrover1 | 470:150c2363f776 | 46 | |
rgrover1 | 485:313482e1b568 | 47 | private: |
rgrover1 | 485:313482e1b568 | 48 | operator uint8_t() const; /* disallow implicit conversion into an integer */ |
rgrover1 | 485:313482e1b568 | 49 | operator unsigned() const; /* disallow implicit conversion into an integer */ |
rgrover1 | 470:150c2363f776 | 50 | }; |
rgrover1 | 470:150c2363f776 | 51 | |
rgrover1 | 470:150c2363f776 | 52 | struct ReadResponse_t { |
rgrover1 | 470:150c2363f776 | 53 | GattAttribute::Handle_t handle; /**< Attribute Handle. */ |
rgrover1 | 470:150c2363f776 | 54 | uint16_t offset; /**< Offset of the attribute data. */ |
rgrover1 | 470:150c2363f776 | 55 | uint16_t len; /**< Attribute data length. */ |
rgrover1 | 470:150c2363f776 | 56 | const uint8_t *data; /**< Attribute data, variable length. */ |
rgrover1 | 470:150c2363f776 | 57 | }; |
rgrover1 | 470:150c2363f776 | 58 | typedef void (*ReadCallback_t)(const ReadResponse_t *params); |
rgrover1 | 470:150c2363f776 | 59 | |
rgrover1 | 470:150c2363f776 | 60 | static void setupOnDataRead(ReadCallback_t callback) { |
rgrover1 | 470:150c2363f776 | 61 | onDataReadCallback = callback; |
rgrover1 | 470:150c2363f776 | 62 | } |
rgrover1 | 470:150c2363f776 | 63 | |
rgrover1 | 471:ed48300978d9 | 64 | /** |
rgrover1 | 471:ed48300978d9 | 65 | * Initiate (or continue) a read for the value attribute, optionally at a |
rgrover1 | 471:ed48300978d9 | 66 | * given offset. If the Characteristic or Descriptor to be read is longer |
rgrover1 | 471:ed48300978d9 | 67 | * than ATT_MTU - 1, this function must be called multiple times with |
rgrover1 | 471:ed48300978d9 | 68 | * appropriate offset to read the complete value. |
rgrover1 | 473:d10415d0a07d | 69 | * |
rgrover1 | 473:d10415d0a07d | 70 | * @return BLE_ERROR_NONE if a read has been initiated, else |
rgrover1 | 473:d10415d0a07d | 71 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 486:bcb77e15d152 | 72 | * BLE_STACK_BUSY if some client procedure already in progress, or |
rgrover1 | 486:bcb77e15d152 | 73 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 471:ed48300978d9 | 74 | */ |
rgrover1 | 477:6883ec08f2dd | 75 | virtual ble_error_t read(uint16_t offset = 0) const = 0; |
rgrover1 | 470:150c2363f776 | 76 | |
rgrover1 | 481:7ab4b9ef92cc | 77 | /** |
rgrover1 | 481:7ab4b9ef92cc | 78 | * Perform a write without response procedure. |
rgrover1 | 481:7ab4b9ef92cc | 79 | * |
rgrover1 | 481:7ab4b9ef92cc | 80 | * @param length |
rgrover1 | 481:7ab4b9ef92cc | 81 | * The amount of data being written. |
rgrover1 | 481:7ab4b9ef92cc | 82 | * @param value |
rgrover1 | 481:7ab4b9ef92cc | 83 | * The bytes being written. |
rgrover1 | 481:7ab4b9ef92cc | 84 | * |
rgrover1 | 481:7ab4b9ef92cc | 85 | * @note It is important to note that a write without response will |
rgrover1 | 481:7ab4b9ef92cc | 86 | * <b>consume an application buffer</b>, and will therefore |
rgrover1 | 481:7ab4b9ef92cc | 87 | * generate a onDataSent() callback when the packet has been |
rgrover1 | 481:7ab4b9ef92cc | 88 | * transmitted. The application should ensure that the buffer is |
rgrover1 | 481:7ab4b9ef92cc | 89 | * valid until the callback. |
rgrover1 | 481:7ab4b9ef92cc | 90 | * |
rgrover1 | 481:7ab4b9ef92cc | 91 | * @retval BLE_ERROR_NONE Successfully started the Write procedure, else |
rgrover1 | 481:7ab4b9ef92cc | 92 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 481:7ab4b9ef92cc | 93 | * BLE_STACK_BUSY if some client procedure already in progress, or |
rgrover1 | 486:bcb77e15d152 | 94 | * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or |
rgrover1 | 486:bcb77e15d152 | 95 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 481:7ab4b9ef92cc | 96 | */ |
rgrover1 | 481:7ab4b9ef92cc | 97 | virtual ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const = 0; |
rgrover1 | 481:7ab4b9ef92cc | 98 | |
rgrover1 | 470:150c2363f776 | 99 | void setupLongUUID(UUID::LongUUIDBytes_t longUUID) { |
rgrover1 | 470:150c2363f776 | 100 | uuid.setupLong(longUUID); |
rgrover1 | 470:150c2363f776 | 101 | } |
rgrover1 | 470:150c2363f776 | 102 | |
rgrover1 | 470:150c2363f776 | 103 | public: |
rgrover1 | 470:150c2363f776 | 104 | UUID::ShortUUIDBytes_t getShortUUID(void) const { |
rgrover1 | 470:150c2363f776 | 105 | return uuid.getShortUUID(); |
rgrover1 | 470:150c2363f776 | 106 | } |
rgrover1 | 470:150c2363f776 | 107 | |
rgrover1 | 470:150c2363f776 | 108 | const Properties_t& getProperties(void) const { |
rgrover1 | 470:150c2363f776 | 109 | return props; |
rgrover1 | 470:150c2363f776 | 110 | } |
rgrover1 | 470:150c2363f776 | 111 | |
rgrover1 | 470:150c2363f776 | 112 | const GattAttribute::Handle_t& getDeclHandle(void) const { |
rgrover1 | 470:150c2363f776 | 113 | return declHandle; |
rgrover1 | 470:150c2363f776 | 114 | } |
rgrover1 | 470:150c2363f776 | 115 | const GattAttribute::Handle_t& getValueHandle(void) const { |
rgrover1 | 470:150c2363f776 | 116 | return valueHandle; |
rgrover1 | 470:150c2363f776 | 117 | } |
rgrover1 | 470:150c2363f776 | 118 | |
rgrover1 | 470:150c2363f776 | 119 | public: |
rgrover1 | 470:150c2363f776 | 120 | DiscoveredCharacteristic() : uuid(UUID::ShortUUIDBytes_t(0)), |
rgrover1 | 470:150c2363f776 | 121 | props(), |
rgrover1 | 470:150c2363f776 | 122 | declHandle(GattAttribute::INVALID_HANDLE), |
rgrover1 | 470:150c2363f776 | 123 | valueHandle(GattAttribute::INVALID_HANDLE) { |
rgrover1 | 470:150c2363f776 | 124 | /* empty */ |
rgrover1 | 470:150c2363f776 | 125 | } |
rgrover1 | 470:150c2363f776 | 126 | |
rgrover1 | 475:eb7fbcfb0e85 | 127 | protected: |
rgrover1 | 470:150c2363f776 | 128 | UUID uuid; |
rgrover1 | 470:150c2363f776 | 129 | Properties_t props; |
rgrover1 | 470:150c2363f776 | 130 | GattAttribute::Handle_t declHandle; |
rgrover1 | 470:150c2363f776 | 131 | GattAttribute::Handle_t valueHandle; |
rgrover1 | 470:150c2363f776 | 132 | |
rgrover1 | 475:eb7fbcfb0e85 | 133 | Gap::Handle_t connHandle; |
rgrover1 | 475:eb7fbcfb0e85 | 134 | |
rgrover1 | 475:eb7fbcfb0e85 | 135 | public: |
rgrover1 | 470:150c2363f776 | 136 | static ReadCallback_t onDataReadCallback; |
rgrover1 | 470:150c2363f776 | 137 | }; |
rgrover1 | 470:150c2363f776 | 138 | |
rgrover1 | 470:150c2363f776 | 139 | #endif /*__DISCOVERED_CHARACTERISTIC_H__*/ |