BLE_API for nRF51

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Jun 19 15:52:07 2015 +0100
Revision:
527:493185cebc03
Child:
540:1fb1e0b809eb
Synchronized with git rev 532535b1
Author: Rohit Grover
Merge branch 'gattClient' into develop

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 527:493185cebc03 41 * services/characteristics. isActive() can be used to determine status; and
rgrover1 527:493185cebc03 42 * a termination callback (if setup) will be invoked at the end. Service
rgrover1 527:493185cebc03 43 * discovery can be terminated prematurely if needed using terminate().
rgrover1 527:493185cebc03 44 *
rgrover1 527:493185cebc03 45 * @param connectionHandle
rgrover1 527:493185cebc03 46 * Handle for the connection with the peer.
rgrover1 527:493185cebc03 47 * @param sc
rgrover1 527:493185cebc03 48 * This is the application callback for matching service.
rgrover1 527:493185cebc03 49 * @param cc
rgrover1 527:493185cebc03 50 * This is the application callback for matching characteristic.
rgrover1 527:493185cebc03 51 * @param matchingServiceUUID
rgrover1 527:493185cebc03 52 * UUID based filter for specifying a service in which the application is
rgrover1 527:493185cebc03 53 * interested.
rgrover1 527:493185cebc03 54 * @param matchingCharacteristicUUIDIn
rgrover1 527:493185cebc03 55 * UUID based filter for specifying characteristic in which the application
rgrover1 527:493185cebc03 56 * is interested.
rgrover1 527:493185cebc03 57 *
rgrover1 527:493185cebc03 58 * @Note Using wildcard values for both service-UUID and characteristic-
rgrover1 527:493185cebc03 59 * UUID will result in complete service discovery--callbacks being
rgrover1 527:493185cebc03 60 * called for every service and characteristic.
rgrover1 527:493185cebc03 61 *
rgrover1 527:493185cebc03 62 * @return
rgrover1 527:493185cebc03 63 * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
rgrover1 527:493185cebc03 64 */
rgrover1 527:493185cebc03 65 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
rgrover1 527:493185cebc03 66 ServiceDiscovery::ServiceCallback_t sc = NULL,
rgrover1 527:493185cebc03 67 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
rgrover1 527:493185cebc03 68 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
rgrover1 527:493185cebc03 69 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) = 0;
rgrover1 527:493185cebc03 70
rgrover1 527:493185cebc03 71 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) = 0;
rgrover1 527:493185cebc03 72
rgrover1 527:493185cebc03 73 /**
rgrover1 527:493185cebc03 74 * Is service-discovery currently active?
rgrover1 527:493185cebc03 75 */
rgrover1 527:493185cebc03 76 virtual bool isServiceDiscoveryActive(void) const = 0;
rgrover1 527:493185cebc03 77
rgrover1 527:493185cebc03 78 /**
rgrover1 527:493185cebc03 79 * Terminate an ongoing service-discovery. This should result in an
rgrover1 527:493185cebc03 80 * invocation of the TerminationCallback if service-discovery is active.
rgrover1 527:493185cebc03 81 */
rgrover1 527:493185cebc03 82 virtual void terminateServiceDiscovery(void) = 0;
rgrover1 527:493185cebc03 83
rgrover1 527:493185cebc03 84 /* Initiate a Gatt Client read procedure by attribute-handle.*/
rgrover1 527:493185cebc03 85 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const = 0;
rgrover1 527:493185cebc03 86
rgrover1 527:493185cebc03 87 virtual ble_error_t write(GattClient::WriteOp_t cmd,
rgrover1 527:493185cebc03 88 Gap::Handle_t connHandle,
rgrover1 527:493185cebc03 89 GattAttribute::Handle_t attributeHandle,
rgrover1 527:493185cebc03 90 size_t length,
rgrover1 527:493185cebc03 91 const uint8_t *value) const = 0;
rgrover1 527:493185cebc03 92
rgrover1 527:493185cebc03 93 protected:
rgrover1 527:493185cebc03 94 GattClient() {
rgrover1 527:493185cebc03 95 /* empty */
rgrover1 527:493185cebc03 96 }
rgrover1 527:493185cebc03 97
rgrover1 527:493185cebc03 98 private:
rgrover1 527:493185cebc03 99 /* disallow copy and assignment */
rgrover1 527:493185cebc03 100 GattClient(const GattClient &);
rgrover1 527:493185cebc03 101 GattClient& operator=(const GattClient &);
rgrover1 527:493185cebc03 102 };
rgrover1 527:493185cebc03 103
rgrover1 527:493185cebc03 104 #endif // ifndef __GATT_CLIENT_H__