fork BLE_API to add update adv payload API
Fork of BLE_API by
common/DiscoveredCharacteristic.cpp@512:0584e40bece2, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:52:05 2015 +0100
- Revision:
- 512:0584e40bece2
- Parent:
- 504:817c6240e9d9
Synchronized with git rev 03c87403
Author: Rohit Grover
we now have a working GattClient::write()
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 | 512:0584e40bece2 | 20 | GattClient::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; |
rgrover1 | 512:0584e40bece2 | 21 | GattClient::WriteCallback_t DiscoveredCharacteristic::onDataWriteCallback; |
rgrover1 | 497:926d444599e8 | 22 | |
rgrover1 | 497:926d444599e8 | 23 | ble_error_t |
rgrover1 | 497:926d444599e8 | 24 | DiscoveredCharacteristic::read(uint16_t offset) const |
rgrover1 | 497:926d444599e8 | 25 | { |
rgrover1 | 497:926d444599e8 | 26 | if (!props.read()) { |
rgrover1 | 497:926d444599e8 | 27 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
rgrover1 | 497:926d444599e8 | 28 | } |
rgrover1 | 497:926d444599e8 | 29 | |
rgrover1 | 498:f3cd1e9e1ebc | 30 | if (!gattc) { |
rgrover1 | 498:f3cd1e9e1ebc | 31 | return BLE_ERROR_INVALID_STATE; |
rgrover1 | 498:f3cd1e9e1ebc | 32 | } |
rgrover1 | 498:f3cd1e9e1ebc | 33 | |
rgrover1 | 497:926d444599e8 | 34 | return gattc->read(connHandle, valueHandle, offset); |
rgrover1 | 497:926d444599e8 | 35 | } |
rgrover1 | 497:926d444599e8 | 36 | |
rgrover1 | 497:926d444599e8 | 37 | ble_error_t |
rgrover1 | 512:0584e40bece2 | 38 | DiscoveredCharacteristic::write(uint16_t length, const uint8_t *value) const |
rgrover1 | 512:0584e40bece2 | 39 | { |
rgrover1 | 512:0584e40bece2 | 40 | if (!props.write()) { |
rgrover1 | 512:0584e40bece2 | 41 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
rgrover1 | 512:0584e40bece2 | 42 | } |
rgrover1 | 512:0584e40bece2 | 43 | |
rgrover1 | 512:0584e40bece2 | 44 | if (!gattc) { |
rgrover1 | 512:0584e40bece2 | 45 | return BLE_ERROR_INVALID_STATE; |
rgrover1 | 512:0584e40bece2 | 46 | } |
rgrover1 | 512:0584e40bece2 | 47 | |
rgrover1 | 512:0584e40bece2 | 48 | return gattc->write(GattClient::GATT_OP_WRITE_REQ, connHandle, valueHandle, length, value); |
rgrover1 | 512:0584e40bece2 | 49 | } |
rgrover1 | 512:0584e40bece2 | 50 | |
rgrover1 | 512:0584e40bece2 | 51 | ble_error_t |
rgrover1 | 497:926d444599e8 | 52 | DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value) const |
rgrover1 | 497:926d444599e8 | 53 | { |
rgrover1 | 497:926d444599e8 | 54 | if (!props.writeWoResp()) { |
rgrover1 | 497:926d444599e8 | 55 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
rgrover1 | 497:926d444599e8 | 56 | } |
rgrover1 | 497:926d444599e8 | 57 | |
rgrover1 | 502:557c4a9276ae | 58 | if (!gattc) { |
rgrover1 | 502:557c4a9276ae | 59 | return BLE_ERROR_INVALID_STATE; |
rgrover1 | 502:557c4a9276ae | 60 | } |
rgrover1 | 502:557c4a9276ae | 61 | |
rgrover1 | 512:0584e40bece2 | 62 | return gattc->write(GattClient::GATT_OP_WRITE_CMD, connHandle, valueHandle, length, value); |
rgrover1 | 497:926d444599e8 | 63 | } |