Skip to content

Commit

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

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

* Use template classes to simplify definitions of GattCharacteristic within services.

Bugfixes
~~~~~~~~

Compatibility
~~~~~~~~~~~~~

This release is API compatible with 0.2.4.
  • Loading branch information
Rohit Grover committed Jan 22, 2015
1 parent 9dc7849 commit 4a268db
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 60 deletions.
66 changes: 62 additions & 4 deletions public/GattCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ class GattCharacteristic {
* determine the authorization reply for a read request.
* @param params to capture the context of the read-auth request.
*
* @NOTE: To authorize/deny the read the params->authorizationReply field
* @NOTE: To authorize/deny the read the params->authorizationReply field
* should be set to true/false.
*
* If the read is approved and params->data is unchanged (NULL),
* If the read is approved and params->data is unchanged (NULL),
* the current characteristic value will be used.
*
* If the read is approved, a new value can be provided by setting
* the params->data pointer and params->len fields.
* If the read is approved, a new value can be provided by setting
* the params->data pointer and params->len fields.
*
* @return true if the read is authorized to proceed.
*/
Expand Down Expand Up @@ -441,4 +441,62 @@ class GattCharacteristic {
GattCharacteristic& operator=(const GattCharacteristic &);
};

template <typename T>
class ReadOnlyGattCharacteristic : public GattCharacteristic {
public:
ReadOnlyGattCharacteristic<T>(const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties) {
/* empty */
}
};

template <typename T>
class WriteOnlyGattCharacteristic : public GattCharacteristic {
public:
WriteOnlyGattCharacteristic<T>(const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties) {
/* empty */
}
};

template <typename T>
class ReadWriteGattCharacteristic : public GattCharacteristic {
public:
ReadWriteGattCharacteristic<T>(const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T), sizeof(T),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties) {
/* empty */
}
};

template <typename T, unsigned NUM_ELEMENTS>
class WriteOnlyArrayGattCharacteristic : public GattCharacteristic {
public:
WriteOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties) {
/* empty */
}
};

template <typename T, unsigned NUM_ELEMENTS>
class ReadOnlyArrayGattCharacteristic : public GattCharacteristic {
public:
ReadOnlyArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | additionalProperties) {
/* empty */
}
};

template <typename T, unsigned NUM_ELEMENTS>
class ReadWriteArrayGattCharacteristic : public GattCharacteristic {
public:
ReadWriteArrayGattCharacteristic<T, NUM_ELEMENTS>(const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE) :
GattCharacteristic(uuid, reinterpret_cast<uint8_t *>(valuePtr), sizeof(T) * NUM_ELEMENTS, sizeof(T) * NUM_ELEMENTS,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | additionalProperties) {
/* empty */
}
};

#endif // ifndef __GATT_CHARACTERISTIC_H__
10 changes: 5 additions & 5 deletions services/BatteryService.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class BatteryService {
BatteryService(BLEDevice &_ble, uint8_t level = 100) :
ble(_ble),
batteryLevel(level),
batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, sizeof(batteryLevel), sizeof(batteryLevel),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {

static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */
if (serviceAdded) {
Expand All @@ -64,9 +63,10 @@ class BatteryService {
}

private:
BLEDevice &ble;
uint8_t batteryLevel;
GattCharacteristic batteryLevelCharacteristic;
BLEDevice &ble;

uint8_t batteryLevel;
ReadOnlyGattCharacteristic<uint8_t> batteryLevelCharacteristic;
};

#endif /* #ifndef __BLE_BATTERY_SERVICE_H__*/
5 changes: 2 additions & 3 deletions services/DFUService.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class DFUService {
ble(_ble),
controlBytes(),
packetBytes(),
controlPoint(DFUServiceControlCharacteristicUUID, controlBytes, SIZEOF_CONTROL_BYTES, SIZEOF_CONTROL_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
controlPoint(DFUServiceControlCharacteristicUUID, controlBytes, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
packet(DFUServicePacketCharacteristicUUID, packetBytes, SIZEOF_PACKET_BYTES, SIZEOF_PACKET_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE) {
static bool serviceAdded = false; /* We should only ever need to add the DFU service once. */
Expand Down Expand Up @@ -120,7 +119,7 @@ class DFUService {
/**< Writing to the control characteristic triggers the handover to dfu-
* bootloader. At present, writing anything will do the trick--this needs
* to be improved. */
GattCharacteristic controlPoint;
WriteOnlyArrayGattCharacteristic<uint8_t, SIZEOF_CONTROL_BYTES> controlPoint;

/**< The packet characteristic in this service doesn't do anything meaningful, but
* is only a placeholder to mimic the corresponding characteristic in the
Expand Down
15 changes: 6 additions & 9 deletions services/HealthThermometerService.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ class HealthThermometerService {
HealthThermometerService(BLEDevice &_ble, float initialTemp, uint8_t _location) :
ble(_ble),
valueBytes(initialTemp),
tempMeasurement(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, valueBytes.getPointer(),
sizeof(TemperatureValueBytes), sizeof(TemperatureValueBytes),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
tempLocation(GattCharacteristic::UUID_TEMPERATURE_TYPE_CHAR, (uint8_t *)&_location, sizeof(_location), sizeof(_location),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) {
tempMeasurement(GattCharacteristic::UUID_TEMPERATURE_MEASUREMENT_CHAR, (TemperatureValueBytes *)valueBytes.getPointer(), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
tempLocation(GattCharacteristic::UUID_TEMPERATURE_TYPE_CHAR, &_location) {

GattCharacteristic *hrmChars[] = {&tempMeasurement, &tempLocation, };
GattService hrmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *));
Expand Down Expand Up @@ -144,10 +141,10 @@ class HealthThermometerService {
};

private:
BLEDevice &ble;
TemperatureValueBytes valueBytes;
GattCharacteristic tempMeasurement;
GattCharacteristic tempLocation;
BLEDevice &ble;
TemperatureValueBytes valueBytes;
ReadOnlyGattCharacteristic<TemperatureValueBytes> tempMeasurement;
ReadOnlyGattCharacteristic<uint8_t> tempLocation;
};

#endif /* #ifndef __BLE_HEALTH_THERMOMETER_SERVICE_H__*/
20 changes: 9 additions & 11 deletions services/HeartRateService.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ class HeartRateService {
hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(),
valueBytes.getNumValueBytes(), HeartRateValueBytes::MAX_VALUE_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&location, sizeof(location), sizeof(location),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
controlPoint(GattCharacteristic::UUID_HEART_RATE_CONTROL_POINT_CHAR, (uint8_t *)&controlPointValue,
sizeof(controlPointValue), sizeof(controlPointValue), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) {
hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, &location),
controlPoint(GattCharacteristic::UUID_HEART_RATE_CONTROL_POINT_CHAR, &controlPointValue) {
setupService();
}

Expand All @@ -82,10 +80,8 @@ class HeartRateService {
hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(),
valueBytes.getNumValueBytes(), HeartRateValueBytes::MAX_VALUE_BYTES,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, (uint8_t *)&location, sizeof(location), sizeof(location),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
controlPoint(GattCharacteristic::UUID_HEART_RATE_CONTROL_POINT_CHAR, (uint8_t *)&controlPointValue,
sizeof(controlPointValue), sizeof(controlPointValue), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) {
hrmLocation(GattCharacteristic::UUID_BODY_SENSOR_LOCATION_CHAR, &location),
controlPoint(GattCharacteristic::UUID_HEART_RATE_CONTROL_POINT_CHAR, &controlPointValue) {
setupService();
}

Expand Down Expand Up @@ -193,11 +189,13 @@ class HeartRateService {

private:
BLEDevice &ble;

HeartRateValueBytes valueBytes;
uint8_t controlPointValue;
GattCharacteristic hrmRate;
GattCharacteristic hrmLocation;
GattCharacteristic controlPoint;

GattCharacteristic hrmRate;
ReadOnlyGattCharacteristic<uint8_t> hrmLocation;
WriteOnlyGattCharacteristic<uint8_t> controlPoint;
};

#endif /* #ifndef __BLE_HEART_RATE_SERVICE_H__*/
12 changes: 6 additions & 6 deletions services/LinkLossService.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class LinkLossService {
ble(bleIn),
alertLevel(levelIn),
callback(callbackIn),
alertLevelChar(GattCharacteristic::UUID_ALERT_LEVEL_CHAR, reinterpret_cast<uint8_t *>(&alertLevel), sizeof(uint8_t), sizeof(uint8_t),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) {
alertLevelChar(GattCharacteristic::UUID_ALERT_LEVEL_CHAR, reinterpret_cast<uint8_t *>(&alertLevel)) {
static bool serviceAdded = false; /* We should only ever add one LinkLoss service. */
if (serviceAdded) {
return;
Expand Down Expand Up @@ -94,10 +93,11 @@ class LinkLossService {
}

private:
BLEDevice &ble;
AlertLevel_t alertLevel;
callback_t callback;
GattCharacteristic alertLevelChar;
BLEDevice &ble;
AlertLevel_t alertLevel;
callback_t callback;

ReadWriteGattCharacteristic<uint8_t> alertLevelChar;
};

#endif /* __BLE_LINK_LOSS_SERVICE_H__ */
40 changes: 18 additions & 22 deletions services/URIBeaconConfigService.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,15 @@ class URIBeaconConfigService {
flags(flagsIn),
powerLevels(),
beaconPeriod(beaconPeriodIn),
lockedStateChar(lockedStateCharUUID, reinterpret_cast<uint8_t *>(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ),
lockChar(lockCharUUID, lockBits, SIZEOF_LOCK_BITS, SIZEOF_LOCK_BITS, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
unlockChar(unlockCharUUID, lockBits, SIZEOF_LOCK_BITS, SIZEOF_LOCK_BITS, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
uriDataChar(uriDataCharUUID, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE, MAX_SIZE_URI_DATA_CHAR_VALUE,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
flagsChar(flagsCharUUID, &flags, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
txPowerLevelsChar(txPowerLevelsCharUUID, reinterpret_cast<uint8_t *>(powerLevels), sizeof(powerLevels), sizeof(powerLevels),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
txPowerModeChar(txPowerModeCharUUID, reinterpret_cast<uint8_t *>(&txPowerMode), sizeof(uint8_t), sizeof(uint8_t),
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
beaconPeriodChar(beaconPeriodCharUUID, reinterpret_cast<uint8_t *>(&beaconPeriod), 2, 2,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
resetChar(resetCharUUID, reinterpret_cast<uint8_t *>(&resetFlag), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE)
lockedStateChar(lockedStateCharUUID, &lockedState),
lockChar(lockCharUUID, lockBits),
unlockChar(unlockCharUUID, lockBits),
uriDataChar(uriDataCharUUID, uriData),
flagsChar(flagsCharUUID, &flags),
txPowerLevelsChar(txPowerLevelsCharUUID, powerLevels),
txPowerModeChar(txPowerModeCharUUID, &txPowerMode),
beaconPeriodChar(beaconPeriodCharUUID, &beaconPeriod),
resetChar(resetCharUUID, &resetFlag)
{
if ((uriDataIn == NULL) || ((uriDataLength = strlen(uriDataIn)) == 0) || (uriDataLength > MAX_SIZE_URI_DATA_CHAR_VALUE)) {
return;
Expand Down Expand Up @@ -536,15 +532,15 @@ class URIBeaconConfigService {
uint16_t beaconPeriod;
bool resetFlag;

GattCharacteristic lockedStateChar;
GattCharacteristic lockChar;
GattCharacteristic unlockChar;
GattCharacteristic uriDataChar;
GattCharacteristic flagsChar;
GattCharacteristic txPowerLevelsChar;
GattCharacteristic txPowerModeChar;
GattCharacteristic beaconPeriodChar;
GattCharacteristic resetChar;
ReadOnlyGattCharacteristic<bool> lockedStateChar;
WriteOnlyArrayGattCharacteristic<uint8_t, SIZEOF_LOCK_BITS> lockChar;
WriteOnlyArrayGattCharacteristic<uint8_t, SIZEOF_LOCK_BITS> unlockChar;
ReadWriteArrayGattCharacteristic<uint8_t, MAX_SIZE_URI_DATA_CHAR_VALUE> uriDataChar;
ReadWriteGattCharacteristic<uint8_t> flagsChar;
ReadWriteArrayGattCharacteristic<int8_t, NUM_POWER_MODES> txPowerLevelsChar;
ReadWriteGattCharacteristic<TXPowerModes_t> txPowerModeChar;
ReadWriteGattCharacteristic<uint16_t> beaconPeriodChar;
WriteOnlyGattCharacteristic<bool> resetChar;
};

#endif /* #ifndef __BLE_URI_BEACON_CONFIG_SERVICE_H__*/

0 comments on commit 4a268db

Please sign in to comment.