test code 123

Dependencies:   mbed

Fork of LinkNode-Test by Qi Yao

Committer:
youkee
Date:
Fri Oct 28 13:04:10 2016 +0000
Revision:
1:b0d4fbbdb244
Parent:
0:1ad0e04b1bc5
ghhbfdd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
youkee 0:1ad0e04b1bc5 1 /* mbed Microcontroller Library
youkee 0:1ad0e04b1bc5 2 * Copyright (c) 2006-2013 ARM Limited
youkee 0:1ad0e04b1bc5 3 *
youkee 0:1ad0e04b1bc5 4 * Licensed under the Apache License, Version 2.0 (the "License");
youkee 0:1ad0e04b1bc5 5 * you may not use this file except in compliance with the License.
youkee 0:1ad0e04b1bc5 6 * You may obtain a copy of the License at
youkee 0:1ad0e04b1bc5 7 *
youkee 0:1ad0e04b1bc5 8 * http://www.apache.org/licenses/LICENSE-2.0
youkee 0:1ad0e04b1bc5 9 *
youkee 0:1ad0e04b1bc5 10 * Unless required by applicable law or agreed to in writing, software
youkee 0:1ad0e04b1bc5 11 * distributed under the License is distributed on an "AS IS" BASIS,
youkee 0:1ad0e04b1bc5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
youkee 0:1ad0e04b1bc5 13 * See the License for the specific language governing permissions and
youkee 0:1ad0e04b1bc5 14 * limitations under the License.
youkee 0:1ad0e04b1bc5 15 */
youkee 0:1ad0e04b1bc5 16
youkee 0:1ad0e04b1bc5 17 #ifndef __DISCOVERED_CHARACTERISTIC_H__
youkee 0:1ad0e04b1bc5 18 #define __DISCOVERED_CHARACTERISTIC_H__
youkee 0:1ad0e04b1bc5 19
youkee 0:1ad0e04b1bc5 20 #include "UUID.h"
youkee 0:1ad0e04b1bc5 21 #include "Gap.h"
youkee 0:1ad0e04b1bc5 22 #include "GattAttribute.h"
youkee 0:1ad0e04b1bc5 23 #include "GattClient.h"
youkee 0:1ad0e04b1bc5 24
youkee 0:1ad0e04b1bc5 25 /**
youkee 0:1ad0e04b1bc5 26 * Structure for holding information about the service and the characteristics
youkee 0:1ad0e04b1bc5 27 * found during the discovery process.
youkee 0:1ad0e04b1bc5 28 */
youkee 0:1ad0e04b1bc5 29 class DiscoveredCharacteristic {
youkee 0:1ad0e04b1bc5 30 public:
youkee 0:1ad0e04b1bc5 31 struct Properties_t {
youkee 0:1ad0e04b1bc5 32 uint8_t _broadcast :1; /**< Broadcasting the value permitted. */
youkee 0:1ad0e04b1bc5 33 uint8_t _read :1; /**< Reading the value permitted. */
youkee 0:1ad0e04b1bc5 34 uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
youkee 0:1ad0e04b1bc5 35 uint8_t _write :1; /**< Writing the value with Write Request permitted. */
youkee 0:1ad0e04b1bc5 36 uint8_t _notify :1; /**< Notications of the value permitted. */
youkee 0:1ad0e04b1bc5 37 uint8_t _indicate :1; /**< Indications of the value permitted. */
youkee 0:1ad0e04b1bc5 38 uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
youkee 0:1ad0e04b1bc5 39
youkee 0:1ad0e04b1bc5 40 public:
youkee 0:1ad0e04b1bc5 41 bool broadcast(void) const {return _broadcast; }
youkee 0:1ad0e04b1bc5 42 bool read(void) const {return _read; }
youkee 0:1ad0e04b1bc5 43 bool writeWoResp(void) const {return _writeWoResp; }
youkee 0:1ad0e04b1bc5 44 bool write(void) const {return _write; }
youkee 0:1ad0e04b1bc5 45 bool notify(void) const {return _notify; }
youkee 0:1ad0e04b1bc5 46 bool indicate(void) const {return _indicate; }
youkee 0:1ad0e04b1bc5 47 bool authSignedWrite(void) const {return _authSignedWrite;}
youkee 0:1ad0e04b1bc5 48
youkee 0:1ad0e04b1bc5 49 private:
youkee 0:1ad0e04b1bc5 50 operator uint8_t() const; /* Disallow implicit conversion into an integer. */
youkee 0:1ad0e04b1bc5 51 operator unsigned() const; /* Disallow implicit conversion into an integer. */
youkee 0:1ad0e04b1bc5 52 };
youkee 0:1ad0e04b1bc5 53
youkee 0:1ad0e04b1bc5 54 /**
youkee 0:1ad0e04b1bc5 55 * Structure for holding information about the service and the characteristics
youkee 0:1ad0e04b1bc5 56 * found during the discovery process.
youkee 0:1ad0e04b1bc5 57 */
youkee 0:1ad0e04b1bc5 58 struct DiscoveredDescriptor {
youkee 0:1ad0e04b1bc5 59 GattAttribute::Handle_t handle; /**< Descriptor Handle. */
youkee 0:1ad0e04b1bc5 60 UUID uuid; /**< Descriptor UUID. */
youkee 0:1ad0e04b1bc5 61 };
youkee 0:1ad0e04b1bc5 62
youkee 0:1ad0e04b1bc5 63 /**
youkee 0:1ad0e04b1bc5 64 * Callback type for when a characteristic descriptor is found during descriptor-
youkee 0:1ad0e04b1bc5 65 * discovery. The receiving function is passed in a pointer to a
youkee 0:1ad0e04b1bc5 66 * DiscoveredDescriptor object which will remain valid for the lifetime
youkee 0:1ad0e04b1bc5 67 * of the callback. Memory for this object is owned by the BLE_API eventing
youkee 0:1ad0e04b1bc5 68 * framework. The application can safely make a persistent shallow-copy of
youkee 0:1ad0e04b1bc5 69 * this object in order to work with the characteristic beyond the callback.
youkee 0:1ad0e04b1bc5 70 */
youkee 0:1ad0e04b1bc5 71 typedef void (*DescriptorCallback_t)(const DiscoveredDescriptor *);
youkee 0:1ad0e04b1bc5 72
youkee 0:1ad0e04b1bc5 73 /**
youkee 0:1ad0e04b1bc5 74 * Initiate (or continue) a read for the value attribute, optionally at a
youkee 0:1ad0e04b1bc5 75 * given offset. If the characteristic or descriptor to be read is longer
youkee 0:1ad0e04b1bc5 76 * than ATT_MTU - 1, this function must be called multiple times with
youkee 0:1ad0e04b1bc5 77 * appropriate offset to read the complete value.
youkee 0:1ad0e04b1bc5 78 *
youkee 0:1ad0e04b1bc5 79 * @return BLE_ERROR_NONE if a read has been initiated, or
youkee 0:1ad0e04b1bc5 80 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
youkee 0:1ad0e04b1bc5 81 * BLE_STACK_BUSY if some client procedure is already in progress, or
youkee 0:1ad0e04b1bc5 82 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
youkee 0:1ad0e04b1bc5 83 */
youkee 0:1ad0e04b1bc5 84 ble_error_t read(uint16_t offset = 0) const;
youkee 0:1ad0e04b1bc5 85
youkee 0:1ad0e04b1bc5 86 ble_error_t read(uint16_t offset, const GattClient::ReadCallback_t& onRead) const;
youkee 0:1ad0e04b1bc5 87
youkee 0:1ad0e04b1bc5 88 /**
youkee 0:1ad0e04b1bc5 89 * Perform a write without response procedure.
youkee 0:1ad0e04b1bc5 90 *
youkee 0:1ad0e04b1bc5 91 * @param length
youkee 0:1ad0e04b1bc5 92 * The amount of data being written.
youkee 0:1ad0e04b1bc5 93 * @param value
youkee 0:1ad0e04b1bc5 94 * The bytes being written.
youkee 0:1ad0e04b1bc5 95 *
youkee 0:1ad0e04b1bc5 96 * @note It is important to note that a write without response will generate
youkee 0:1ad0e04b1bc5 97 * an onDataSent() callback when the packet has been transmitted. There
youkee 0:1ad0e04b1bc5 98 * will be a BLE-stack specific limit to the number of pending
youkee 0:1ad0e04b1bc5 99 * writeWoResponse operations; the user may want to use the onDataSent()
youkee 0:1ad0e04b1bc5 100 * callback for flow-control.
youkee 0:1ad0e04b1bc5 101 *
youkee 0:1ad0e04b1bc5 102 * @retval BLE_ERROR_NONE Successfully started the Write procedure, or
youkee 0:1ad0e04b1bc5 103 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
youkee 0:1ad0e04b1bc5 104 * BLE_STACK_BUSY if some client procedure is already in progress, or
youkee 0:1ad0e04b1bc5 105 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
youkee 0:1ad0e04b1bc5 106 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
youkee 0:1ad0e04b1bc5 107 */
youkee 0:1ad0e04b1bc5 108 ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
youkee 0:1ad0e04b1bc5 109
youkee 0:1ad0e04b1bc5 110 /**
youkee 0:1ad0e04b1bc5 111 * Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic.
youkee 0:1ad0e04b1bc5 112 *
youkee 0:1ad0e04b1bc5 113 * @param callback
youkee 0:1ad0e04b1bc5 114 * @param matchingUUID
youkee 0:1ad0e04b1bc5 115 * Filter for descriptors. Defaults to wildcard which will discover all descriptors.
youkee 0:1ad0e04b1bc5 116 *
youkee 0:1ad0e04b1bc5 117 * @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error.
youkee 0:1ad0e04b1bc5 118 */
youkee 0:1ad0e04b1bc5 119 ble_error_t discoverDescriptors(DescriptorCallback_t callback, const UUID &matchingUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) const;
youkee 0:1ad0e04b1bc5 120
youkee 0:1ad0e04b1bc5 121 /**
youkee 0:1ad0e04b1bc5 122 * Perform a write procedure.
youkee 0:1ad0e04b1bc5 123 *
youkee 0:1ad0e04b1bc5 124 * @param length
youkee 0:1ad0e04b1bc5 125 * The amount of data being written.
youkee 0:1ad0e04b1bc5 126 * @param value
youkee 0:1ad0e04b1bc5 127 * The bytes being written.
youkee 0:1ad0e04b1bc5 128 *
youkee 0:1ad0e04b1bc5 129 * @note It is important to note that a write will generate
youkee 0:1ad0e04b1bc5 130 * an onDataWritten() callback when the peer acknowledges the request.
youkee 0:1ad0e04b1bc5 131 *
youkee 0:1ad0e04b1bc5 132 * @retval BLE_ERROR_NONE Successfully started the Write procedure, or
youkee 0:1ad0e04b1bc5 133 * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
youkee 0:1ad0e04b1bc5 134 * BLE_STACK_BUSY if some client procedure is already in progress, or
youkee 0:1ad0e04b1bc5 135 * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
youkee 0:1ad0e04b1bc5 136 * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
youkee 0:1ad0e04b1bc5 137 */
youkee 0:1ad0e04b1bc5 138 ble_error_t write(uint16_t length, const uint8_t *value) const;
youkee 0:1ad0e04b1bc5 139
youkee 0:1ad0e04b1bc5 140 /**
youkee 0:1ad0e04b1bc5 141 * Same as above but register the callback wich will be called once the data has been written
youkee 0:1ad0e04b1bc5 142 */
youkee 0:1ad0e04b1bc5 143 ble_error_t write(uint16_t length, const uint8_t *value, const GattClient::WriteCallback_t& onRead) const;
youkee 0:1ad0e04b1bc5 144
youkee 0:1ad0e04b1bc5 145 void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::ByteOrder_t order = UUID::MSB) {
youkee 0:1ad0e04b1bc5 146 uuid.setupLong(longUUID, order);
youkee 0:1ad0e04b1bc5 147 }
youkee 0:1ad0e04b1bc5 148
youkee 0:1ad0e04b1bc5 149 public:
youkee 0:1ad0e04b1bc5 150 const UUID& getUUID(void) const {
youkee 0:1ad0e04b1bc5 151 return uuid;
youkee 0:1ad0e04b1bc5 152 }
youkee 0:1ad0e04b1bc5 153
youkee 0:1ad0e04b1bc5 154 const Properties_t& getProperties(void) const {
youkee 0:1ad0e04b1bc5 155 return props;
youkee 0:1ad0e04b1bc5 156 }
youkee 0:1ad0e04b1bc5 157
youkee 0:1ad0e04b1bc5 158 const GattAttribute::Handle_t& getDeclHandle(void) const {
youkee 0:1ad0e04b1bc5 159 return declHandle;
youkee 0:1ad0e04b1bc5 160 }
youkee 0:1ad0e04b1bc5 161 const GattAttribute::Handle_t& getValueHandle(void) const {
youkee 0:1ad0e04b1bc5 162 return valueHandle;
youkee 0:1ad0e04b1bc5 163 }
youkee 0:1ad0e04b1bc5 164
youkee 0:1ad0e04b1bc5 165 public:
youkee 0:1ad0e04b1bc5 166 DiscoveredCharacteristic() : gattc(NULL),
youkee 0:1ad0e04b1bc5 167 uuid(UUID::ShortUUIDBytes_t(0)),
youkee 0:1ad0e04b1bc5 168 props(),
youkee 0:1ad0e04b1bc5 169 declHandle(GattAttribute::INVALID_HANDLE),
youkee 0:1ad0e04b1bc5 170 valueHandle(GattAttribute::INVALID_HANDLE) {
youkee 0:1ad0e04b1bc5 171 /* empty */
youkee 0:1ad0e04b1bc5 172 }
youkee 0:1ad0e04b1bc5 173
youkee 0:1ad0e04b1bc5 174 protected:
youkee 0:1ad0e04b1bc5 175 GattClient *gattc;
youkee 0:1ad0e04b1bc5 176
youkee 0:1ad0e04b1bc5 177 protected:
youkee 0:1ad0e04b1bc5 178 UUID uuid;
youkee 0:1ad0e04b1bc5 179 Properties_t props;
youkee 0:1ad0e04b1bc5 180 GattAttribute::Handle_t declHandle;
youkee 0:1ad0e04b1bc5 181 GattAttribute::Handle_t valueHandle;
youkee 0:1ad0e04b1bc5 182
youkee 0:1ad0e04b1bc5 183 Gap::Handle_t connHandle;
youkee 0:1ad0e04b1bc5 184 };
youkee 0:1ad0e04b1bc5 185
youkee 0:1ad0e04b1bc5 186 #endif /*__DISCOVERED_CHARACTERISTIC_H__*/