Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
common/DiscoveredCharacteristic.cpp@498:f3cd1e9e1ebc, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:52:03 2015 +0100
- Revision:
- 498:f3cd1e9e1ebc
- Parent:
- 497:926d444599e8
- Child:
- 499:db9bc083f91e
Synchronized with git rev a7cf0629
Author: Rohit Grover
add a sanity check to DiscoveredCharacteristic::read().
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rgrover1 | 497:926d444599e8 | 1 | /* mbed Microcontroller Library |
| rgrover1 | 497:926d444599e8 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| rgrover1 | 497:926d444599e8 | 3 | * |
| rgrover1 | 497:926d444599e8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| rgrover1 | 497:926d444599e8 | 5 | * you may not use this file except in compliance with the License. |
| rgrover1 | 497:926d444599e8 | 6 | * You may obtain a copy of the License at |
| rgrover1 | 497:926d444599e8 | 7 | * |
| rgrover1 | 497:926d444599e8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| rgrover1 | 497:926d444599e8 | 9 | * |
| rgrover1 | 497:926d444599e8 | 10 | * Unless required by applicable law or agreed to in writing, software |
| rgrover1 | 497:926d444599e8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| rgrover1 | 497:926d444599e8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| rgrover1 | 497:926d444599e8 | 13 | * See the License for the specific language governing permissions and |
| rgrover1 | 497:926d444599e8 | 14 | * limitations under the License. |
| rgrover1 | 497:926d444599e8 | 15 | */ |
| rgrover1 | 497:926d444599e8 | 16 | |
| rgrover1 | 497:926d444599e8 | 17 | #include "DiscoveredCharacteristic.h" |
| rgrover1 | 497:926d444599e8 | 18 | #include "GattClient.h" |
| rgrover1 | 497:926d444599e8 | 19 | |
| rgrover1 | 497:926d444599e8 | 20 | DiscoveredCharacteristic::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; |
| rgrover1 | 497:926d444599e8 | 21 | |
| rgrover1 | 497:926d444599e8 | 22 | /** |
| rgrover1 | 497:926d444599e8 | 23 | * Initiate (or continue) a read for the value attribute, optionally at a |
| rgrover1 | 497:926d444599e8 | 24 | * given offset. If the Characteristic or Descriptor to be read is longer |
| rgrover1 | 497:926d444599e8 | 25 | * than ATT_MTU - 1, this function must be called multiple times with |
| rgrover1 | 497:926d444599e8 | 26 | * appropriate offset to read the complete value. |
| rgrover1 | 497:926d444599e8 | 27 | * |
| rgrover1 | 497:926d444599e8 | 28 | * @return BLE_ERROR_NONE if a read has been initiated, else |
| rgrover1 | 497:926d444599e8 | 29 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
| rgrover1 | 497:926d444599e8 | 30 | * BLE_STACK_BUSY if some client procedure already in progress, or |
| rgrover1 | 497:926d444599e8 | 31 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
| rgrover1 | 497:926d444599e8 | 32 | */ |
| rgrover1 | 497:926d444599e8 | 33 | ble_error_t |
| rgrover1 | 497:926d444599e8 | 34 | DiscoveredCharacteristic::read(uint16_t offset) const |
| rgrover1 | 497:926d444599e8 | 35 | { |
| rgrover1 | 497:926d444599e8 | 36 | if (!props.read()) { |
| rgrover1 | 497:926d444599e8 | 37 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
| rgrover1 | 497:926d444599e8 | 38 | } |
| rgrover1 | 497:926d444599e8 | 39 | |
| rgrover1 | 498:f3cd1e9e1ebc | 40 | if (!gattc) { |
| rgrover1 | 498:f3cd1e9e1ebc | 41 | return BLE_ERROR_INVALID_STATE; |
| rgrover1 | 498:f3cd1e9e1ebc | 42 | } |
| rgrover1 | 498:f3cd1e9e1ebc | 43 | |
| rgrover1 | 497:926d444599e8 | 44 | return gattc->read(connHandle, valueHandle, offset); |
| rgrover1 | 497:926d444599e8 | 45 | } |
| rgrover1 | 497:926d444599e8 | 46 | |
| rgrover1 | 497:926d444599e8 | 47 | /** |
| rgrover1 | 497:926d444599e8 | 48 | * Perform a write without response procedure. |
| rgrover1 | 497:926d444599e8 | 49 | * |
| rgrover1 | 497:926d444599e8 | 50 | * @param length |
| rgrover1 | 497:926d444599e8 | 51 | * The amount of data being written. |
| rgrover1 | 497:926d444599e8 | 52 | * @param value |
| rgrover1 | 497:926d444599e8 | 53 | * The bytes being written. |
| rgrover1 | 497:926d444599e8 | 54 | * |
| rgrover1 | 497:926d444599e8 | 55 | * @note It is important to note that a write without response will |
| rgrover1 | 497:926d444599e8 | 56 | * <b>consume an application buffer</b>, and will therefore |
| rgrover1 | 497:926d444599e8 | 57 | * generate a onDataSent() callback when the packet has been |
| rgrover1 | 497:926d444599e8 | 58 | * transmitted. The application should ensure that the buffer is |
| rgrover1 | 497:926d444599e8 | 59 | * valid until the callback. |
| rgrover1 | 497:926d444599e8 | 60 | * |
| rgrover1 | 497:926d444599e8 | 61 | * @retval BLE_ERROR_NONE Successfully started the Write procedure, else |
| rgrover1 | 497:926d444599e8 | 62 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
| rgrover1 | 497:926d444599e8 | 63 | * BLE_STACK_BUSY if some client procedure already in progress, or |
| rgrover1 | 497:926d444599e8 | 64 | * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or |
| rgrover1 | 497:926d444599e8 | 65 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
| rgrover1 | 497:926d444599e8 | 66 | */ |
| rgrover1 | 497:926d444599e8 | 67 | ble_error_t |
| rgrover1 | 497:926d444599e8 | 68 | DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value) const |
| rgrover1 | 497:926d444599e8 | 69 | { |
| rgrover1 | 497:926d444599e8 | 70 | if (!props.writeWoResp()) { |
| rgrover1 | 497:926d444599e8 | 71 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
| rgrover1 | 497:926d444599e8 | 72 | } |
| rgrover1 | 497:926d444599e8 | 73 | |
| rgrover1 | 497:926d444599e8 | 74 | return gattc->write(GattClient::OP_WRITE_CMD, connHandle, length, value); |
| rgrover1 | 497:926d444599e8 | 75 | } |
