BLE_API for nRF51

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:05 2015 +0100
Revision:
512:0584e40bece2
Parent:
508:31e63ad6923f
Synchronized with git rev 03c87403
Author: Rohit Grover
we now have a working GattClient::write()

Who changed what in which revision?

UserRevisionLine numberNew 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 497:926d444599e8 21 #include "Gap.h"
rgrover1 470:150c2363f776 22 #include "GattAttribute.h"
rgrover1 501:ff6801633d2c 23 #include "GattClient.h"
rgrover1 497:926d444599e8 24
rgrover1 485:313482e1b568 25 /**
rgrover1 485:313482e1b568 26 * Structure for holding information about the service and the characteristics
rgrover1 485:313482e1b568 27 * found during the discovery process.
rgrover1 470:150c2363f776 28 */
rgrover1 470:150c2363f776 29 class DiscoveredCharacteristic {
rgrover1 470:150c2363f776 30 public:
rgrover1 470:150c2363f776 31 struct Properties_t {
rgrover1 485:313482e1b568 32 uint8_t _broadcast :1; /**< Broadcasting of the value permitted. */
rgrover1 485:313482e1b568 33 uint8_t _read :1; /**< Reading the value permitted. */
rgrover1 485:313482e1b568 34 uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
rgrover1 485:313482e1b568 35 uint8_t _write :1; /**< Writing the value with Write Request permitted. */
rgrover1 485:313482e1b568 36 uint8_t _notify :1; /**< Notications of the value permitted. */
rgrover1 485:313482e1b568 37 uint8_t _indicate :1; /**< Indications of the value permitted. */
rgrover1 485:313482e1b568 38 uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
rgrover1 470:150c2363f776 39
rgrover1 485:313482e1b568 40 public:
rgrover1 485:313482e1b568 41 bool broadcast(void) const {return _broadcast; }
rgrover1 485:313482e1b568 42 bool read(void) const {return _read; }
rgrover1 485:313482e1b568 43 bool writeWoResp(void) const {return _writeWoResp; }
rgrover1 485:313482e1b568 44 bool write(void) const {return _write; }
rgrover1 485:313482e1b568 45 bool notify(void) const {return _notify; }
rgrover1 485:313482e1b568 46 bool indicate(void) const {return _indicate; }
rgrover1 485:313482e1b568 47 bool authSignedWrite(void) const {return _authSignedWrite;}
rgrover1 470:150c2363f776 48
rgrover1 485:313482e1b568 49 private:
rgrover1 485:313482e1b568 50 operator uint8_t() const; /* disallow implicit conversion into an integer */
rgrover1 485:313482e1b568 51 operator unsigned() const; /* disallow implicit conversion into an integer */
rgrover1 470:150c2363f776 52 };
rgrover1 470:150c2363f776 53
rgrover1 471:ed48300978d9 54 /**
rgrover1 471:ed48300978d9 55 * Initiate (or continue) a read for the value attribute, optionally at a
rgrover1 471:ed48300978d9 56 * given offset. If the Characteristic or Descriptor to be read is longer
rgrover1 471:ed48300978d9 57 * than ATT_MTU - 1, this function must be called multiple times with
rgrover1 471:ed48300978d9 58 * appropriate offset to read the complete value.
rgrover1 473:d10415d0a07d 59 *
rgrover1 473:d10415d0a07d 60 * @return BLE_ERROR_NONE if a read has been initiated, else
rgrover1 473:d10415d0a07d 61 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
rgrover1 486:bcb77e15d152 62 * BLE_STACK_BUSY if some client procedure already in progress, or
rgrover1 486:bcb77e15d152 63 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 471:ed48300978d9 64 */
rgrover1 497:926d444599e8 65 ble_error_t read(uint16_t offset = 0) const;
rgrover1 470:150c2363f776 66
rgrover1 481:7ab4b9ef92cc 67 /**
rgrover1 481:7ab4b9ef92cc 68 * Perform a write without response procedure.
rgrover1 481:7ab4b9ef92cc 69 *
rgrover1 481:7ab4b9ef92cc 70 * @param length
rgrover1 481:7ab4b9ef92cc 71 * The amount of data being written.
rgrover1 481:7ab4b9ef92cc 72 * @param value
rgrover1 481:7ab4b9ef92cc 73 * The bytes being written.
rgrover1 481:7ab4b9ef92cc 74 *
rgrover1 499:db9bc083f91e 75 * @note It is important to note that a write without response will generate
rgrover1 499:db9bc083f91e 76 * an onDataSent() callback when the packet has been transmitted. There
rgrover1 499:db9bc083f91e 77 * will be a BLE-stack specific limit to the number of pending
rgrover1 499:db9bc083f91e 78 * writeWoResponse operations; the user may want to use the onDataSent()
rgrover1 499:db9bc083f91e 79 * callback for flow-control.
rgrover1 481:7ab4b9ef92cc 80 *
rgrover1 481:7ab4b9ef92cc 81 * @retval BLE_ERROR_NONE Successfully started the Write procedure, else
rgrover1 481:7ab4b9ef92cc 82 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
rgrover1 481:7ab4b9ef92cc 83 * BLE_STACK_BUSY if some client procedure already in progress, or
rgrover1 486:bcb77e15d152 84 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
rgrover1 486:bcb77e15d152 85 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 481:7ab4b9ef92cc 86 */
rgrover1 497:926d444599e8 87 ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
rgrover1 481:7ab4b9ef92cc 88
rgrover1 506:be938b716fe8 89 /**
rgrover1 506:be938b716fe8 90 * Perform a write procedure.
rgrover1 506:be938b716fe8 91 *
rgrover1 506:be938b716fe8 92 * @param length
rgrover1 506:be938b716fe8 93 * The amount of data being written.
rgrover1 506:be938b716fe8 94 * @param value
rgrover1 506:be938b716fe8 95 * The bytes being written.
rgrover1 506:be938b716fe8 96 *
rgrover1 512:0584e40bece2 97 * @note It is important to note that a write will generate
rgrover1 512:0584e40bece2 98 * an onDataWritten() callback when the peer acknowledges the request.
rgrover1 506:be938b716fe8 99 *
rgrover1 506:be938b716fe8 100 * @retval BLE_ERROR_NONE Successfully started the Write procedure, else
rgrover1 506:be938b716fe8 101 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
rgrover1 506:be938b716fe8 102 * BLE_STACK_BUSY if some client procedure already in progress, or
rgrover1 506:be938b716fe8 103 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
rgrover1 506:be938b716fe8 104 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
rgrover1 506:be938b716fe8 105 */
rgrover1 506:be938b716fe8 106 ble_error_t write(uint16_t length, const uint8_t *value) const;
rgrover1 499:db9bc083f91e 107
rgrover1 505:ac825d37e8f2 108 static void setupOnDataRead(GattClient::ReadCallback_t callback) {
rgrover1 492:7e0bd56f4957 109 onDataReadCallback = callback;
rgrover1 492:7e0bd56f4957 110 }
rgrover1 492:7e0bd56f4957 111
rgrover1 512:0584e40bece2 112 static void setupOnDataWrite(GattClient::WriteCallback_t callback) {
rgrover1 512:0584e40bece2 113 onDataWriteCallback = callback;
rgrover1 512:0584e40bece2 114 }
rgrover1 512:0584e40bece2 115
rgrover1 470:150c2363f776 116 void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
rgrover1 470:150c2363f776 117 uuid.setupLong(longUUID);
rgrover1 470:150c2363f776 118 }
rgrover1 470:150c2363f776 119
rgrover1 470:150c2363f776 120 public:
rgrover1 470:150c2363f776 121 UUID::ShortUUIDBytes_t getShortUUID(void) const {
rgrover1 470:150c2363f776 122 return uuid.getShortUUID();
rgrover1 470:150c2363f776 123 }
rgrover1 470:150c2363f776 124
rgrover1 470:150c2363f776 125 const Properties_t& getProperties(void) const {
rgrover1 470:150c2363f776 126 return props;
rgrover1 470:150c2363f776 127 }
rgrover1 470:150c2363f776 128
rgrover1 470:150c2363f776 129 const GattAttribute::Handle_t& getDeclHandle(void) const {
rgrover1 470:150c2363f776 130 return declHandle;
rgrover1 470:150c2363f776 131 }
rgrover1 470:150c2363f776 132 const GattAttribute::Handle_t& getValueHandle(void) const {
rgrover1 470:150c2363f776 133 return valueHandle;
rgrover1 470:150c2363f776 134 }
rgrover1 470:150c2363f776 135
rgrover1 470:150c2363f776 136 public:
rgrover1 493:23cc7ad1b99b 137 DiscoveredCharacteristic() : gattc(NULL),
rgrover1 493:23cc7ad1b99b 138 uuid(UUID::ShortUUIDBytes_t(0)),
rgrover1 470:150c2363f776 139 props(),
rgrover1 470:150c2363f776 140 declHandle(GattAttribute::INVALID_HANDLE),
rgrover1 470:150c2363f776 141 valueHandle(GattAttribute::INVALID_HANDLE) {
rgrover1 470:150c2363f776 142 /* empty */
rgrover1 470:150c2363f776 143 }
rgrover1 470:150c2363f776 144
rgrover1 475:eb7fbcfb0e85 145 protected:
rgrover1 493:23cc7ad1b99b 146 GattClient *gattc;
rgrover1 493:23cc7ad1b99b 147
rgrover1 493:23cc7ad1b99b 148 protected:
rgrover1 470:150c2363f776 149 UUID uuid;
rgrover1 470:150c2363f776 150 Properties_t props;
rgrover1 470:150c2363f776 151 GattAttribute::Handle_t declHandle;
rgrover1 470:150c2363f776 152 GattAttribute::Handle_t valueHandle;
rgrover1 470:150c2363f776 153
rgrover1 475:eb7fbcfb0e85 154 Gap::Handle_t connHandle;
rgrover1 475:eb7fbcfb0e85 155
rgrover1 475:eb7fbcfb0e85 156 public:
rgrover1 512:0584e40bece2 157 static GattClient::ReadCallback_t onDataReadCallback;
rgrover1 512:0584e40bece2 158 static GattClient::WriteCallback_t onDataWriteCallback;
rgrover1 470:150c2363f776 159 };
rgrover1 470:150c2363f776 160
rgrover1 470:150c2363f776 161 #endif /*__DISCOVERED_CHARACTERISTIC_H__*/