Michael Galis / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Fri Jun 19 15:55:30 2015 +0100
Revision:
317:943ad03c93ef
Parent:
315:044071756a8d
Child:
324:1cb5b26ecaca
Synchronized with git rev 3630fb0c
Author: Rohit Grover
remove printfs from nRFDiscoveredCharacteristic::read()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 315:044071756a8d 1 /* mbed Microcontroller Library
rgrover1 315:044071756a8d 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 315:044071756a8d 3 *
rgrover1 315:044071756a8d 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 315:044071756a8d 5 * you may not use this file except in compliance with the License.
rgrover1 315:044071756a8d 6 * You may obtain a copy of the License at
rgrover1 315:044071756a8d 7 *
rgrover1 315:044071756a8d 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 315:044071756a8d 9 *
rgrover1 315:044071756a8d 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 315:044071756a8d 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 315:044071756a8d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 315:044071756a8d 13 * See the License for the specific language governing permissions and
rgrover1 315:044071756a8d 14 * limitations under the License.
rgrover1 315:044071756a8d 15 */
rgrover1 315:044071756a8d 16
rgrover1 315:044071756a8d 17 #ifndef __NRF_DISCOVERED_CHARACTERISTIC_H__
rgrover1 315:044071756a8d 18 #define __NRF_DISCOVERED_CHARACTERISTIC_H__
rgrover1 315:044071756a8d 19
rgrover1 315:044071756a8d 20 class nRFDiscoveredCharacteristic : public DiscoveredCharacteristic {
rgrover1 315:044071756a8d 21 public:
rgrover1 315:044071756a8d 22 void setup(Gap::Handle_t connectionHandleIn,
rgrover1 315:044071756a8d 23 Properties_t propsIn,
rgrover1 315:044071756a8d 24 GattAttribute::Handle_t declHandleIn,
rgrover1 315:044071756a8d 25 GattAttribute::Handle_t valueHandleIn) {
rgrover1 315:044071756a8d 26 connHandle = connectionHandleIn;
rgrover1 315:044071756a8d 27 props = propsIn;
rgrover1 315:044071756a8d 28 declHandle = declHandleIn;
rgrover1 315:044071756a8d 29 valueHandle = valueHandleIn;
rgrover1 315:044071756a8d 30 }
rgrover1 315:044071756a8d 31
rgrover1 315:044071756a8d 32 void setup(Gap::Handle_t connectionHandleIn,
rgrover1 315:044071756a8d 33 UUID::ShortUUIDBytes_t uuidIn,
rgrover1 315:044071756a8d 34 Properties_t propsIn,
rgrover1 315:044071756a8d 35 GattAttribute::Handle_t declHandleIn,
rgrover1 315:044071756a8d 36 GattAttribute::Handle_t valueHandleIn) {
rgrover1 315:044071756a8d 37 connHandle = connectionHandleIn;
rgrover1 315:044071756a8d 38 uuid = uuidIn;
rgrover1 315:044071756a8d 39 props = propsIn;
rgrover1 315:044071756a8d 40 declHandle = declHandleIn;
rgrover1 315:044071756a8d 41 valueHandle = valueHandleIn;
rgrover1 315:044071756a8d 42 }
rgrover1 315:044071756a8d 43
rgrover1 315:044071756a8d 44 public:
rgrover1 315:044071756a8d 45 /**
rgrover1 315:044071756a8d 46 * Initiate (or continue) a read for the value attribute, optionally at a
rgrover1 315:044071756a8d 47 * given offset. If the Characteristic or Descriptor to be read is longer
rgrover1 315:044071756a8d 48 * than ATT_MTU - 1, this function must be called multiple times with
rgrover1 315:044071756a8d 49 * appropriate offset to read the complete value.
rgrover1 315:044071756a8d 50 *
rgrover1 315:044071756a8d 51 * @return BLE_ERROR_NONE if a read has been initiated, else
rgrover1 315:044071756a8d 52 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
rgrover1 315:044071756a8d 53 * BLE_STACK_BUSY if some client procedure already in progress.
rgrover1 315:044071756a8d 54 */
rgrover1 315:044071756a8d 55 virtual ble_error_t read(uint16_t offset = 0) const {
rgrover1 315:044071756a8d 56 uint32_t rc = sd_ble_gattc_read(connHandle, valueHandle, offset);
rgrover1 315:044071756a8d 57 if (rc == NRF_SUCCESS) {
rgrover1 315:044071756a8d 58 return BLE_ERROR_NONE;
rgrover1 315:044071756a8d 59 }
rgrover1 315:044071756a8d 60 switch (rc) {
rgrover1 315:044071756a8d 61 case NRF_ERROR_BUSY:
rgrover1 315:044071756a8d 62 return BLE_STACK_BUSY;
rgrover1 315:044071756a8d 63 case BLE_ERROR_INVALID_CONN_HANDLE:
rgrover1 315:044071756a8d 64 case NRF_ERROR_INVALID_STATE:
rgrover1 315:044071756a8d 65 case NRF_ERROR_INVALID_ADDR:
rgrover1 315:044071756a8d 66 default:
rgrover1 315:044071756a8d 67 return BLE_ERROR_INVALID_STATE;
rgrover1 315:044071756a8d 68 }
rgrover1 315:044071756a8d 69 }
rgrover1 315:044071756a8d 70 };
rgrover1 315:044071756a8d 71
rgrover1 315:044071756a8d 72 #endif /* __NRF_DISCOVERED_CHARACTERISTIC_H__ */