just a fork

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:08 2015 +0100
Revision:
540:1fb1e0b809eb
Parent:
527:493185cebc03
Child:
559:1ee5106d3763
Synchronized with git rev 5a93322a
Author: Rohit Grover
remove GATTClient related APIs from BLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 527:493185cebc03 1 /* mbed Microcontroller Library
rgrover1 527:493185cebc03 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 527:493185cebc03 3 *
rgrover1 527:493185cebc03 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 527:493185cebc03 5 * you may not use this file except in compliance with the License.
rgrover1 527:493185cebc03 6 * You may obtain a copy of the License at
rgrover1 527:493185cebc03 7 *
rgrover1 527:493185cebc03 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 527:493185cebc03 9 *
rgrover1 527:493185cebc03 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 527:493185cebc03 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 527:493185cebc03 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 527:493185cebc03 13 * See the License for the specific language governing permissions and
rgrover1 527:493185cebc03 14 * limitations under the License.
rgrover1 527:493185cebc03 15 */
rgrover1 527:493185cebc03 16
rgrover1 527:493185cebc03 17 #ifndef __GATT_CLIENT_H__
rgrover1 527:493185cebc03 18 #define __GATT_CLIENT_H__
rgrover1 527:493185cebc03 19
rgrover1 527:493185cebc03 20 #include "Gap.h"
rgrover1 527:493185cebc03 21 #include "GattAttribute.h"
rgrover1 527:493185cebc03 22 #include "ServiceDiscovery.h"
rgrover1 527:493185cebc03 23
rgrover1 527:493185cebc03 24 #include "GattCallbackParamTypes.h"
rgrover1 527:493185cebc03 25
rgrover1 527:493185cebc03 26 class GattClient {
rgrover1 527:493185cebc03 27 public:
rgrover1 527:493185cebc03 28 typedef void (*ReadCallback_t)(const GattReadCallbackParams *params);
rgrover1 527:493185cebc03 29
rgrover1 527:493185cebc03 30 enum WriteOp_t {
rgrover1 527:493185cebc03 31 GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */
rgrover1 527:493185cebc03 32 GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */
rgrover1 527:493185cebc03 33 };
rgrover1 527:493185cebc03 34
rgrover1 527:493185cebc03 35 typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params);
rgrover1 527:493185cebc03 36
rgrover1 527:493185cebc03 37 public:
rgrover1 527:493185cebc03 38 /**
rgrover1 527:493185cebc03 39 * Launch service discovery. Once launched, service discovery will remain
rgrover1 527:493185cebc03 40 * active with callbacks being issued back into the application for matching
rgrover1 540:1fb1e0b809eb 41 * services/characteristics. isServiceDiscoveryActive() can be used to
rgrover1 540:1fb1e0b809eb 42 * determine status; and a termination callback (if setup) will be invoked
rgrover1 540:1fb1e0b809eb 43 * at the end. Service discovery can be terminated prematurely if needed
rgrover1 540:1fb1e0b809eb 44 * using terminateServiceDiscovery().
rgrover1 527:493185cebc03 45 *
rgrover1 527:493185cebc03 46 * @param connectionHandle
rgrover1 527:493185cebc03 47 * Handle for the connection with the peer.
rgrover1 527:493185cebc03 48 * @param sc
rgrover1 540:1fb1e0b809eb 49 * This is the application callback for matching service. Taken as
rgrover1 540:1fb1e0b809eb 50 * NULL by default. Note: service discovery may still be active
rgrover1 540:1fb1e0b809eb 51 * when this callback is issued; calling asynchronous BLE-stack
rgrover1 540:1fb1e0b809eb 52 * APIs from within this application callback might cause the
rgrover1 540:1fb1e0b809eb 53 * stack to abort service discovery. If this becomes an issue, it
rgrover1 540:1fb1e0b809eb 54 * may be better to make local copy of the discoveredService and
rgrover1 540:1fb1e0b809eb 55 * wait for service discovery to terminate before operating on the
rgrover1 540:1fb1e0b809eb 56 * service.
rgrover1 527:493185cebc03 57 * @param cc
rgrover1 527:493185cebc03 58 * This is the application callback for matching characteristic.
rgrover1 540:1fb1e0b809eb 59 * Taken as NULL by default. Note: service discovery may still be
rgrover1 540:1fb1e0b809eb 60 * active when this callback is issued; calling asynchronous
rgrover1 540:1fb1e0b809eb 61 * BLE-stack APIs from within this application callback might cause
rgrover1 540:1fb1e0b809eb 62 * the stack to abort service discovery. If this becomes an issue,
rgrover1 540:1fb1e0b809eb 63 * it may be better to make local copy of the discoveredCharacteristic
rgrover1 540:1fb1e0b809eb 64 * and wait for service discovery to terminate before operating on the
rgrover1 540:1fb1e0b809eb 65 * characteristic.
rgrover1 527:493185cebc03 66 * @param matchingServiceUUID
rgrover1 527:493185cebc03 67 * UUID based filter for specifying a service in which the application is
rgrover1 540:1fb1e0b809eb 68 * interested. By default it is set as the wildcard UUID_UNKNOWN,
rgrover1 540:1fb1e0b809eb 69 * in which case it matches all services. If characteristic-UUID
rgrover1 540:1fb1e0b809eb 70 * filter (below) is set to the wildcard value, then a service
rgrover1 540:1fb1e0b809eb 71 * callback will be invoked for the matching service (or for every
rgrover1 540:1fb1e0b809eb 72 * service if the service filter is a wildcard).
rgrover1 527:493185cebc03 73 * @param matchingCharacteristicUUIDIn
rgrover1 527:493185cebc03 74 * UUID based filter for specifying characteristic in which the application
rgrover1 540:1fb1e0b809eb 75 * is interested. By default it is set as the wildcard UUID_UKNOWN
rgrover1 540:1fb1e0b809eb 76 * to match against any characteristic. If both service-UUID
rgrover1 540:1fb1e0b809eb 77 * filter and characteristic-UUID filter are used with non- wildcard
rgrover1 540:1fb1e0b809eb 78 * values, then only a single characteristic callback is
rgrover1 540:1fb1e0b809eb 79 * invoked for the matching characteristic.
rgrover1 527:493185cebc03 80 *
rgrover1 540:1fb1e0b809eb 81 * @note Using wildcard values for both service-UUID and characteristic-
rgrover1 527:493185cebc03 82 * UUID will result in complete service discovery--callbacks being
rgrover1 527:493185cebc03 83 * called for every service and characteristic.
rgrover1 527:493185cebc03 84 *
rgrover1 540:1fb1e0b809eb 85
rgrover1 540:1fb1e0b809eb 86 * @note Providing NULL for the characteristic callback will result in
rgrover1 540:1fb1e0b809eb 87 * characteristic discovery being skipped. This allows for an
rgrover1 540:1fb1e0b809eb 88 * inexpensive method to discover services.
rgrover1 540:1fb1e0b809eb 89 *
rgrover1 527:493185cebc03 90 * @return
rgrover1 527:493185cebc03 91 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
rgrover1 527:493185cebc03 92 */
rgrover1 527:493185cebc03 93 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
rgrover1 527:493185cebc03 94 ServiceDiscovery::ServiceCallback_t sc = NULL,
rgrover1 527:493185cebc03 95 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
rgrover1 527:493185cebc03 96 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 527:493185cebc03 97 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) = 0;
rgrover1 527:493185cebc03 98
rgrover1 540:1fb1e0b809eb 99 /**
rgrover1 540:1fb1e0b809eb 100 * Setup callback for when serviceDiscovery terminates.
rgrover1 540:1fb1e0b809eb 101 */
rgrover1 527:493185cebc03 102 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) = 0;
rgrover1 527:493185cebc03 103
rgrover1 527:493185cebc03 104 /**
rgrover1 527:493185cebc03 105 * Is service-discovery currently active?
rgrover1 527:493185cebc03 106 */
rgrover1 527:493185cebc03 107 virtual bool isServiceDiscoveryActive(void) const = 0;
rgrover1 527:493185cebc03 108
rgrover1 527:493185cebc03 109 /**
rgrover1 527:493185cebc03 110 * Terminate an ongoing service-discovery. This should result in an
rgrover1 527:493185cebc03 111 * invocation of the TerminationCallback if service-discovery is active.
rgrover1 527:493185cebc03 112 */
rgrover1 527:493185cebc03 113 virtual void terminateServiceDiscovery(void) = 0;
rgrover1 527:493185cebc03 114
rgrover1 527:493185cebc03 115 /* Initiate a Gatt Client read procedure by attribute-handle.*/
rgrover1 527:493185cebc03 116 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const = 0;
rgrover1 527:493185cebc03 117
rgrover1 540:1fb1e0b809eb 118 /**
rgrover1 540:1fb1e0b809eb 119 * Initiate a GATT Client write procedure.
rgrover1 540:1fb1e0b809eb 120 *
rgrover1 540:1fb1e0b809eb 121 * @param[in] cmd
rgrover1 540:1fb1e0b809eb 122 * Command can be either a write-request (which generates a
rgrover1 540:1fb1e0b809eb 123 * matching response from the peripheral), or a write-command,
rgrover1 540:1fb1e0b809eb 124 * which doesn't require the connected peer to respond.
rgrover1 540:1fb1e0b809eb 125 * @param[in] connHandle
rgrover1 540:1fb1e0b809eb 126 * Connection handle.
rgrover1 540:1fb1e0b809eb 127 * @param[in] attributeHandle
rgrover1 540:1fb1e0b809eb 128 * handle for the target attribtue on the remote GATT server.
rgrover1 540:1fb1e0b809eb 129 * @param[in] length
rgrover1 540:1fb1e0b809eb 130 * length of the new value.
rgrover1 540:1fb1e0b809eb 131 * @param[in] value
rgrover1 540:1fb1e0b809eb 132 * new value being written.
rgrover1 540:1fb1e0b809eb 133 */
rgrover1 527:493185cebc03 134 virtual ble_error_t write(GattClient::WriteOp_t cmd,
rgrover1 527:493185cebc03 135 Gap::Handle_t connHandle,
rgrover1 527:493185cebc03 136 GattAttribute::Handle_t attributeHandle,
rgrover1 527:493185cebc03 137 size_t length,
rgrover1 527:493185cebc03 138 const uint8_t *value) const = 0;
rgrover1 527:493185cebc03 139
rgrover1 527:493185cebc03 140 protected:
rgrover1 527:493185cebc03 141 GattClient() {
rgrover1 527:493185cebc03 142 /* empty */
rgrover1 527:493185cebc03 143 }
rgrover1 527:493185cebc03 144
rgrover1 527:493185cebc03 145 private:
rgrover1 527:493185cebc03 146 /* disallow copy and assignment */
rgrover1 527:493185cebc03 147 GattClient(const GattClient &);
rgrover1 527:493185cebc03 148 GattClient& operator=(const GattClient &);
rgrover1 527:493185cebc03 149 };
rgrover1 527:493185cebc03 150
rgrover1 527:493185cebc03 151 #endif // ifndef __GATT_CLIENT_H__