From 0d55096d82524a6843dac515cdfe8e52df979171 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 6 Jul 2015 09:31:37 +0100 Subject: [PATCH] fix #53: add GattClient::onHVX() and GattHVXCallbackParams --- ble/GattCallbackParamTypes.h | 8 ++++++++ ble/GattClient.h | 18 ++++++++++++++++++ ble/blecommon.h | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/ble/GattCallbackParamTypes.h b/ble/GattCallbackParamTypes.h index fd6d40e..ce2a6c9 100644 --- a/ble/GattCallbackParamTypes.h +++ b/ble/GattCallbackParamTypes.h @@ -75,4 +75,12 @@ struct GattReadAuthCallbackParams { * request is to proceed; false otherwise. */ }; +/* For encapsulating handle-value update events (notifications or indications) generated at the remote server. */ +struct GattHVXCallbackParams { + GattAttribute::Handle_t handle; /**< Attribute Handle to which the HVx operation applies. */ + HVXType_t type; /**< Indication or Notification, see @ref HVXType_t. */ + uint16_t len; /**< Attribute data length. */ + const uint8_t *data; /**< Attribute data, variable length. */ +}; + #endif /*__GATT_CALLBACK_PARAM_TYPES_H__*/ diff --git a/ble/GattClient.h b/ble/GattClient.h index ec0da5e..f6bc06b 100644 --- a/ble/GattClient.h +++ b/ble/GattClient.h @@ -34,6 +34,8 @@ public: typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); + typedef void (*HVXCallback_t)(const GattHVXCallbackParams *params); + /* * The following functions are meant to be overridden in the platform-specific sub-class. */ @@ -263,6 +265,15 @@ public: /* default implementation; override this API if this capability is supported. */ } + /** + * Setup a callback for when GattClient receives an update event + * corresponding to a change in value of a characteristic on the remote + * GattServer. + */ + void onHVX(HVXCallback_t callback) { + onHVXCallback = callback; + } + protected: GattClient() { /* empty */ @@ -282,9 +293,16 @@ public: } } + void processHVXEvent(const GattHVXCallbackParams *params) { + if (onHVXCallback) { + onHVXCallback(params); + } + } + protected: ReadCallback_t onDataReadCallback; WriteCallback_t onDataWriteCallback; + HVXCallback_t onHVXCallback; private: /* disallow copy and assignment */ diff --git a/ble/blecommon.h b/ble/blecommon.h index b572f08..07e5b63 100644 --- a/ble/blecommon.h +++ b/ble/blecommon.h @@ -129,6 +129,11 @@ enum ble_error_t { /** @brief Default MTU size. */ static const unsigned BLE_GATT_MTU_SIZE_DEFAULT = 23; +enum HVXType_t { + BLE_HVX_NOTIFICATION = 0x01, /**< Handle Value Notification. */ + BLE_HVX_INDICATION = 0x02, /**< Handle Value Indication. */ +}; + #ifdef __cplusplus } #endif