2015-05-27 14:32:26 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DISCOVERED_CHARACTERISTIC_H__
|
|
|
|
#define __DISCOVERED_CHARACTERISTIC_H__
|
|
|
|
|
|
|
|
#include "UUID.h"
|
2015-06-04 13:44:00 +00:00
|
|
|
#include "Gap.h"
|
2015-05-27 14:32:26 +00:00
|
|
|
#include "GattAttribute.h"
|
2015-06-05 08:20:41 +00:00
|
|
|
#include "GattClient.h"
|
2015-06-04 13:44:00 +00:00
|
|
|
|
2015-06-03 07:47:07 +00:00
|
|
|
/**
|
|
|
|
* Structure for holding information about the service and the characteristics
|
|
|
|
* found during the discovery process.
|
2015-05-27 14:32:26 +00:00
|
|
|
*/
|
|
|
|
class DiscoveredCharacteristic {
|
|
|
|
public:
|
|
|
|
struct Properties_t {
|
2015-06-03 07:47:07 +00:00
|
|
|
uint8_t _broadcast :1; /**< Broadcasting of the value permitted. */
|
|
|
|
uint8_t _read :1; /**< Reading the value permitted. */
|
|
|
|
uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */
|
|
|
|
uint8_t _write :1; /**< Writing the value with Write Request permitted. */
|
|
|
|
uint8_t _notify :1; /**< Notications of the value permitted. */
|
|
|
|
uint8_t _indicate :1; /**< Indications of the value permitted. */
|
|
|
|
uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */
|
2015-05-27 14:32:26 +00:00
|
|
|
|
2015-06-03 07:47:07 +00:00
|
|
|
public:
|
|
|
|
bool broadcast(void) const {return _broadcast; }
|
|
|
|
bool read(void) const {return _read; }
|
|
|
|
bool writeWoResp(void) const {return _writeWoResp; }
|
|
|
|
bool write(void) const {return _write; }
|
|
|
|
bool notify(void) const {return _notify; }
|
|
|
|
bool indicate(void) const {return _indicate; }
|
|
|
|
bool authSignedWrite(void) const {return _authSignedWrite;}
|
2015-05-27 14:32:26 +00:00
|
|
|
|
2015-06-03 07:47:07 +00:00
|
|
|
private:
|
|
|
|
operator uint8_t() const; /* disallow implicit conversion into an integer */
|
|
|
|
operator unsigned() const; /* disallow implicit conversion into an integer */
|
2015-05-27 14:32:26 +00:00
|
|
|
};
|
|
|
|
|
2015-06-19 10:49:03 +00:00
|
|
|
/**
|
|
|
|
* Structure for holding information about the service and the characteristics
|
|
|
|
* found during the discovery process.
|
|
|
|
*/
|
|
|
|
struct DiscoveredDescriptor {
|
|
|
|
GattAttribute::Handle_t handle; /**< Descriptor Handle. */
|
|
|
|
UUID uuid; /**< Descriptor UUID. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback type for when a characteristic descriptor is found during descriptor-
|
|
|
|
* discovery. The receiving function is passed in a pointer to a
|
|
|
|
* DiscoveredDescriptor object which will remain valid for the lifetime
|
|
|
|
* of the callback. Memory for this object is owned by the BLE_API eventing
|
|
|
|
* framework. The application can safely make a persistent shallow-copy of
|
|
|
|
* this object in order to work with the characteristic beyond the callback.
|
|
|
|
*/
|
|
|
|
typedef void (*DescriptorCallback_t)(const DiscoveredDescriptor *);
|
|
|
|
|
2015-05-27 14:43:53 +00:00
|
|
|
/**
|
|
|
|
* Initiate (or continue) a read for the value attribute, optionally at a
|
|
|
|
* given offset. If the Characteristic or Descriptor to be read is longer
|
|
|
|
* than ATT_MTU - 1, this function must be called multiple times with
|
|
|
|
* appropriate offset to read the complete value.
|
2015-05-28 06:45:30 +00:00
|
|
|
*
|
|
|
|
* @return BLE_ERROR_NONE if a read has been initiated, else
|
|
|
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
2015-06-03 07:47:56 +00:00
|
|
|
* BLE_STACK_BUSY if some client procedure already in progress, or
|
|
|
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
2015-05-27 14:43:53 +00:00
|
|
|
*/
|
2015-06-04 13:44:00 +00:00
|
|
|
ble_error_t read(uint16_t offset = 0) const;
|
2015-05-27 14:32:26 +00:00
|
|
|
|
2015-06-02 13:56:27 +00:00
|
|
|
/**
|
|
|
|
* Perform a write without response procedure.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* The amount of data being written.
|
|
|
|
* @param value
|
|
|
|
* The bytes being written.
|
|
|
|
*
|
2015-06-05 07:20:48 +00:00
|
|
|
* @note It is important to note that a write without response will generate
|
|
|
|
* an onDataSent() callback when the packet has been transmitted. There
|
|
|
|
* will be a BLE-stack specific limit to the number of pending
|
|
|
|
* writeWoResponse operations; the user may want to use the onDataSent()
|
|
|
|
* callback for flow-control.
|
2015-06-02 13:56:27 +00:00
|
|
|
*
|
|
|
|
* @retval BLE_ERROR_NONE Successfully started the Write procedure, else
|
|
|
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
|
|
|
* BLE_STACK_BUSY if some client procedure already in progress, or
|
2015-06-03 07:47:56 +00:00
|
|
|
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
|
|
|
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
2015-06-02 13:56:27 +00:00
|
|
|
*/
|
2015-06-04 13:44:00 +00:00
|
|
|
ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const;
|
2015-06-02 13:56:27 +00:00
|
|
|
|
2015-06-19 10:49:03 +00:00
|
|
|
/**
|
|
|
|
* Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic.
|
|
|
|
*
|
|
|
|
* @param callback
|
|
|
|
* @param matchingUUID
|
|
|
|
* filter for descriptors. Defaults to wildcard which will discover all descriptors.
|
|
|
|
*
|
|
|
|
* @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error.
|
|
|
|
*/
|
|
|
|
ble_error_t discoverDescriptors(DescriptorCallback_t callback, const UUID &matchingUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) const;
|
|
|
|
|
2015-06-05 09:40:49 +00:00
|
|
|
/**
|
|
|
|
* Perform a write procedure.
|
|
|
|
*
|
|
|
|
* @param length
|
|
|
|
* The amount of data being written.
|
|
|
|
* @param value
|
|
|
|
* The bytes being written.
|
|
|
|
*
|
2015-06-05 12:30:01 +00:00
|
|
|
* @note It is important to note that a write will generate
|
|
|
|
* an onDataWritten() callback when the peer acknowledges the request.
|
2015-06-05 09:40:49 +00:00
|
|
|
*
|
|
|
|
* @retval BLE_ERROR_NONE Successfully started the Write procedure, else
|
|
|
|
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
|
|
|
|
* BLE_STACK_BUSY if some client procedure already in progress, or
|
|
|
|
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
|
|
|
|
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
|
|
|
|
*/
|
|
|
|
ble_error_t write(uint16_t length, const uint8_t *value) const;
|
2015-06-05 07:20:48 +00:00
|
|
|
|
2015-05-27 14:32:26 +00:00
|
|
|
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
|
|
|
|
uuid.setupLong(longUUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-07-10 15:50:36 +00:00
|
|
|
const UUID& getUUID(void) const {
|
|
|
|
return uuid;
|
2015-05-27 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Properties_t& getProperties(void) const {
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GattAttribute::Handle_t& getDeclHandle(void) const {
|
|
|
|
return declHandle;
|
|
|
|
}
|
|
|
|
const GattAttribute::Handle_t& getValueHandle(void) const {
|
|
|
|
return valueHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-06-03 14:16:08 +00:00
|
|
|
DiscoveredCharacteristic() : gattc(NULL),
|
|
|
|
uuid(UUID::ShortUUIDBytes_t(0)),
|
2015-05-27 14:32:26 +00:00
|
|
|
props(),
|
|
|
|
declHandle(GattAttribute::INVALID_HANDLE),
|
|
|
|
valueHandle(GattAttribute::INVALID_HANDLE) {
|
|
|
|
/* empty */
|
|
|
|
}
|
|
|
|
|
2015-06-03 14:16:08 +00:00
|
|
|
protected:
|
2015-06-19 10:49:19 +00:00
|
|
|
GattClient *gattc;
|
2015-06-03 14:16:08 +00:00
|
|
|
|
2015-05-28 13:48:07 +00:00
|
|
|
protected:
|
2015-06-19 10:49:19 +00:00
|
|
|
UUID uuid;
|
|
|
|
Properties_t props;
|
|
|
|
GattAttribute::Handle_t declHandle;
|
|
|
|
GattAttribute::Handle_t valueHandle;
|
2015-05-27 14:32:26 +00:00
|
|
|
|
2015-06-19 10:49:19 +00:00
|
|
|
Gap::Handle_t connHandle;
|
2015-05-27 14:32:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*__DISCOVERED_CHARACTERISTIC_H__*/
|