High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
common/DiscoveredCharacteristic.cpp@642:f7c865bde6ff, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:52:58 2015 +0100
- Revision:
- 642:f7c865bde6ff
- Parent:
- 497:926d444599e8
- Child:
- 498:f3cd1e9e1ebc
Synchronized with git rev a7c6dc1a
Author: Rohit Grover
one massive commit to move towards GattClient.
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 | 497:926d444599e8 | 40 | return gattc->read(connHandle, valueHandle, offset); |
rgrover1 | 497:926d444599e8 | 41 | } |
rgrover1 | 497:926d444599e8 | 42 | |
rgrover1 | 497:926d444599e8 | 43 | /** |
rgrover1 | 497:926d444599e8 | 44 | * Perform a write without response procedure. |
rgrover1 | 497:926d444599e8 | 45 | * |
rgrover1 | 497:926d444599e8 | 46 | * @param length |
rgrover1 | 497:926d444599e8 | 47 | * The amount of data being written. |
rgrover1 | 497:926d444599e8 | 48 | * @param value |
rgrover1 | 497:926d444599e8 | 49 | * The bytes being written. |
rgrover1 | 497:926d444599e8 | 50 | * |
rgrover1 | 497:926d444599e8 | 51 | * @note It is important to note that a write without response will |
rgrover1 | 497:926d444599e8 | 52 | * <b>consume an application buffer</b>, and will therefore |
rgrover1 | 497:926d444599e8 | 53 | * generate a onDataSent() callback when the packet has been |
rgrover1 | 497:926d444599e8 | 54 | * transmitted. The application should ensure that the buffer is |
rgrover1 | 497:926d444599e8 | 55 | * valid until the callback. |
rgrover1 | 497:926d444599e8 | 56 | * |
rgrover1 | 497:926d444599e8 | 57 | * @retval BLE_ERROR_NONE Successfully started the Write procedure, else |
rgrover1 | 497:926d444599e8 | 58 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 497:926d444599e8 | 59 | * BLE_STACK_BUSY if some client procedure already in progress, or |
rgrover1 | 497:926d444599e8 | 60 | * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or |
rgrover1 | 497:926d444599e8 | 61 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 497:926d444599e8 | 62 | */ |
rgrover1 | 497:926d444599e8 | 63 | ble_error_t |
rgrover1 | 497:926d444599e8 | 64 | DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value) const |
rgrover1 | 497:926d444599e8 | 65 | { |
rgrover1 | 497:926d444599e8 | 66 | if (!props.writeWoResp()) { |
rgrover1 | 497:926d444599e8 | 67 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
rgrover1 | 497:926d444599e8 | 68 | } |
rgrover1 | 497:926d444599e8 | 69 | |
rgrover1 | 497:926d444599e8 | 70 | return gattc->write(GattClient::OP_WRITE_CMD, connHandle, length, value); |
rgrover1 | 497:926d444599e8 | 71 | } |