Skip to content

Commit

Permalink
Release 0.4.1
Browse files Browse the repository at this point in the history
=============

This is a minor release.

Enhancements
~~~~~~~~~~~~

* Introduce API GattServer::areUpdatesEnabled() to determine notification
  status for a characteristic.
  This is a follow up from #41.
  @jeremybrodt did a lovely job submitting that pull request, but there had
  been too many changes in the neighbouring code recently to merge his
  work directly. I didn't take the trouble of preserving his submission
  in the history; my apologies--credit for this API goes entirely to him.

* Replace DiscoveredCharacteristic::setupOnDataRead() with GattClient::onDataRead().

* Move GATT_MTU_SIZE_DEFAULT into blecommon.h as BLE_GATT_MTU_SIZE_DEFAULT.

* Replace uses of the deprecated updateCharacteristicValue() with ble.gattServer().write().

* Change access levels to protected for various members of the standard services.

* Update LinkLossService with a recent change to the definition of
  GattWriteCallbackParams. Involved renaming member charHandle to handle.

Bugfixes
~~~~~~~~

* None.
  • Loading branch information
Rohit Grover committed Jul 2, 2015
2 parents d80fec8 + 4ac9700 commit 42f99e1
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 75 deletions.
12 changes: 0 additions & 12 deletions ble/DiscoveredCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ class DiscoveredCharacteristic {
*/
ble_error_t write(uint16_t length, const uint8_t *value) const;

static void setupOnDataRead(GattClient::ReadCallback_t callback) {
onDataReadCallback = callback;
}

static void setupOnDataWrite(GattClient::WriteCallback_t callback) {
onDataWriteCallback = callback;
}

void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
uuid.setupLong(longUUID);
}
Expand Down Expand Up @@ -182,10 +174,6 @@ class DiscoveredCharacteristic {
GattAttribute::Handle_t valueHandle;

Gap::Handle_t connHandle;

public:
static GattClient::ReadCallback_t onDataReadCallback;
static GattClient::WriteCallback_t onDataWriteCallback;
};

#endif /*__DISCOVERED_CHARACTERISTIC_H__*/
32 changes: 16 additions & 16 deletions ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Gap {
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t setAddress(AddressType_t type, const Address_t address) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -163,7 +163,7 @@ class Gap {
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -188,7 +188,7 @@ class Gap {
}

virtual ble_error_t stopAdvertising(void) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -197,7 +197,7 @@ class Gap {
* @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
*/
virtual ble_error_t stopScan() {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -219,7 +219,7 @@ class Gap {
Gap::AddressType_t peerAddrType,
const ConnectionParams_t *connectionParams,
const GapScanningParams *scanParams) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -231,7 +231,7 @@ class Gap {
* The reason for disconnection to be sent back to the peer.
*/
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -248,7 +248,7 @@ class Gap {
* altertive which takes a connection handle. It will be dropped in the future.
*/
virtual ble_error_t disconnect(DisconnectionReason_t reason) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -264,7 +264,7 @@ class Gap {
* the given structure pointed to by params.
*/
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -276,7 +276,7 @@ class Gap {
* The structure containing the desired parameters.
*/
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -290,7 +290,7 @@ class Gap {
* the parameters in the PPCP characteristic of the GAP service will be used instead.
*/
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -299,7 +299,7 @@ class Gap {
* The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
*/
virtual ble_error_t setDeviceName(const uint8_t *deviceName) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -321,7 +321,7 @@ class Gap {
* use this information to retry with a suitable buffer size.
*/
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -330,7 +330,7 @@ class Gap {
* The new value for the device-appearance.
*/
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -339,15 +339,15 @@ class Gap {
* The new value for the device-appearance.
*/
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
* Set the radio's transmit power.
* @param[in] txPower Radio transmit power in dBm.
*/
virtual ble_error_t setTxPower(int8_t txPower) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -365,7 +365,7 @@ class Gap {
protected:
/* Override the following in the underlying adaptation layer to provide the functionality of scanning. */
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/*
Expand Down
60 changes: 47 additions & 13 deletions ble/GattClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class GattClient {
typedef void (*ReadCallback_t)(const GattReadCallbackParams *params);

enum WriteOp_t {
GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */
GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */
GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */
GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */
};

typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params);
Expand All @@ -39,12 +39,11 @@ class GattClient {
*/
public:
/**
* Launch service discovery. Once launched, service discovery will remain
* active with callbacks being issued back into the application for matching
* services/characteristics. isServiceDiscoveryActive() can be used to
* determine status; and a termination callback (if setup) will be invoked
* at the end. Service discovery can be terminated prematurely if needed
* using terminateServiceDiscovery().
* Launch service discovery. Once launched, application callbacks will be
* invoked for matching services/characteristics. isServiceDiscoveryActive()
* can be used to determine status; and a termination callback (if setup)
* will be invoked at the end. Service discovery can be terminated prematurely
* if needed using terminateServiceDiscovery().
*
* @param connectionHandle
* Handle for the connection with the peer.
Expand Down Expand Up @@ -98,7 +97,7 @@ class GattClient {
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand Down Expand Up @@ -130,7 +129,7 @@ class GattClient {
virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
ServiceDiscovery::ServiceCallback_t callback,
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand Down Expand Up @@ -161,7 +160,7 @@ class GattClient {
ServiceDiscovery::ServiceCallback_t callback,
GattAttribute::Handle_t startHandle,
GattAttribute::Handle_t endHandle) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -181,7 +180,7 @@ class GattClient {

/* Initiate a Gatt Client read procedure by attribute-handle. */
virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -205,7 +204,24 @@ class GattClient {
GattAttribute::Handle_t attributeHandle,
size_t length,
const uint8_t *value) const {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/* Event callback handlers. */
public:
/**
* Setup a callback for read response events.
*/
void onDataRead(ReadCallback_t callback) {
onDataReadCallback = callback;
}

/**
* Setup a callback for write response events.
* @Note: write commands (issued using writeWoResponse) don't generate a response.
*/
void onDataWrite(WriteCallback_t callback) {
onDataWriteCallback = callback;
}

/**
Expand All @@ -220,6 +236,24 @@ class GattClient {
/* empty */
}

/* Entry points for the underlying stack to report events back to the user. */
public:
void processReadResponse(const GattReadCallbackParams *params) {
if (onDataReadCallback) {
onDataReadCallback(params);
}
}

void processWriteResponse(const GattWriteCallbackParams *params) {
if (onDataWriteCallback) {
onDataWriteCallback(params);
}
}

protected:
ReadCallback_t onDataReadCallback;
WriteCallback_t onDataWriteCallback;

private:
/* disallow copy and assignment */
GattClient(const GattClient &);
Expand Down
49 changes: 40 additions & 9 deletions ble/GattServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GattServer {
* characteristics contained within.
*/
virtual ble_error_t addService(GattService &) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -72,7 +72,7 @@ class GattServer {
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
*/
virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -97,7 +97,7 @@ class GattServer {
* attribtues (such as the CCCDs).
*/
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -119,7 +119,7 @@ class GattServer {
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
*/
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand All @@ -145,7 +145,38 @@ class GattServer {
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
*/
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
* Determine the updates-enabled status (notification/indication) for the current connection from a characteristic's CCCD.
*
* @param characteristic
* The characteristic
* @param[out] enabledP
* Upon return, *enabledP is true if updates are enabled, else false.
*
* @return BLE_ERROR_NONE if the connection and handle are found. false otherwise.
*/
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
* Determine the connection-specific updates-enabled status (notification/indication) from a characteristic's CCCD.
*
* @param connectionHandle
* The connection handle
* @param[out] enabledP
* Upon return, *enabledP is true if updates are enabled, else false.
*
* @param characteristic
* The characteristic
*
* @return BLE_ERROR_NONE if the connection and handle are found. false otherwise.
*/
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP) {
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porter(s): override this API if this capability is supported. */
}

/**
Expand Down Expand Up @@ -267,21 +298,21 @@ class GattServer {
}
}

void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t charHandle) {
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle) {
switch (type) {
case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
if (updatesEnabledCallback) {
updatesEnabledCallback(charHandle);
updatesEnabledCallback(attributeHandle);
}
break;
case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
if (updatesDisabledCallback) {
updatesDisabledCallback(charHandle);
updatesDisabledCallback(attributeHandle);
}
break;
case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
if (confirmationReceivedCallback) {
confirmationReceivedCallback(charHandle);
confirmationReceivedCallback(attributeHandle);
}
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions ble/blecommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ enum ble_error_t {
BLE_ERROR_UNSPECIFIED = 9, /**< Unknown error. */
};

/** @brief Default MTU size. */
static const unsigned BLE_GATT_MTU_SIZE_DEFAULT = 23;

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 42f99e1

Please sign in to comment.