merging a cherry pick for improving constructor for GattCharacteristic
This commit is contained in:
commit
36bc3dc050
3 changed files with 26 additions and 77 deletions
|
@ -306,12 +306,12 @@ public:
|
|||
*
|
||||
* @param[in] uuid
|
||||
* The UUID to use for this characteristic
|
||||
* @param[in] props
|
||||
* The 8-bit bit field containing the characteristic's properties
|
||||
* @param[in] initialLen
|
||||
* The min length in bytes of this characteristic's value
|
||||
* @param[in] maxLen
|
||||
* The max length in bytes of this characteristic's value
|
||||
* @param[in] props
|
||||
* The 8-bit bit field containing the characteristic's properties
|
||||
*
|
||||
* @section EXAMPLE
|
||||
*
|
||||
|
@ -348,14 +348,17 @@ public:
|
|||
uint16_t getMaxLength(void) const {
|
||||
return _lenMax;
|
||||
}
|
||||
uint8_t *getValuePtr(void) {
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
UUID _uuid; /* Characteristic UUID */
|
||||
uint8_t *_value;
|
||||
uint16_t _initialLen; /* Initial length of the value */
|
||||
uint16_t _lenMax; /* Maximum length of the value */
|
||||
uint16_t _handle;
|
||||
uint8_t _properties;
|
||||
UUID _uuid; /* Characteristic UUID */
|
||||
uint8_t *_value;
|
||||
uint16_t _initialLen; /* Initial length of the value */
|
||||
uint16_t _lenMax; /* Maximum length of the value */
|
||||
uint16_t _handle;
|
||||
uint8_t _properties;
|
||||
};
|
||||
|
||||
#endif // ifndef __GATT_CHARACTERISTIC_H__
|
||||
|
|
|
@ -36,56 +36,8 @@
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GattService::GattService(UUID uuid) :
|
||||
primaryServiceID(uuid),
|
||||
characteristicCount(0),
|
||||
characteristics(),
|
||||
handle(0)
|
||||
GattService::GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
|
||||
_primaryServiceID(uuid), _characteristicCount(numCharacteristics), _characteristics(characteristics), _handle(0)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GattService::~GattService(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adds a GattCharacterisic to the service.
|
||||
|
||||
@note This function will not update the .handle field in the
|
||||
GattCharacteristic. This value is updated when the parent
|
||||
service is added via the radio driver.
|
||||
|
||||
@param[in] characteristic
|
||||
The GattCharacteristic object describing the characteristic
|
||||
to add to this service
|
||||
|
||||
@returns BLE_ERROR_NONE (0) if everything executed correctly, or an
|
||||
error code if there was a problem
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed correctly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
|
||||
{
|
||||
/* ToDo: Make sure we don't overflow the array, etc. */
|
||||
/* ToDo: Make sure this characteristic UUID doesn't already exist */
|
||||
/* ToDo: Basic validation */
|
||||
|
||||
characteristics[characteristicCount] = &characteristic;
|
||||
characteristicCount++;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "UUID.h"
|
||||
#include "GattCharacteristic.h"
|
||||
|
||||
#define BLE_SERVICE_MAX_CHARACTERISTICS (5)
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
@ -31,13 +30,8 @@
|
|||
/**************************************************************************/
|
||||
class GattService
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
GattService(UUID uuid);
|
||||
virtual ~GattService(void);
|
||||
|
||||
ble_error_t addCharacteristic(GattCharacteristic &);
|
||||
GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics);
|
||||
|
||||
enum {
|
||||
UUID_ALERT_NOTIFICATION_SERVICE = 0x1811,
|
||||
|
@ -61,30 +55,30 @@ public:
|
|||
};
|
||||
|
||||
const UUID &getUUID(void) const {
|
||||
return primaryServiceID;
|
||||
}
|
||||
uint16_t *getHandlePtr(void) {
|
||||
return &handle;
|
||||
return _primaryServiceID;
|
||||
}
|
||||
uint16_t getHandle(void) const {
|
||||
return handle;
|
||||
return _handle;
|
||||
}
|
||||
void setHandle(uint16_t handle) {
|
||||
_handle = handle;
|
||||
}
|
||||
uint8_t getCharacteristicCount(void) const {
|
||||
return characteristicCount;
|
||||
return _characteristicCount;
|
||||
}
|
||||
GattCharacteristic *getCharacteristic(uint8_t index) {
|
||||
if (index >= characteristicCount) {
|
||||
if (index >= _characteristicCount) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return characteristics[index];
|
||||
return _characteristics[index];
|
||||
}
|
||||
|
||||
private:
|
||||
UUID primaryServiceID;
|
||||
uint8_t characteristicCount;
|
||||
GattCharacteristic *characteristics[BLE_SERVICE_MAX_CHARACTERISTICS];
|
||||
uint16_t handle;
|
||||
UUID _primaryServiceID;
|
||||
uint8_t _characteristicCount;
|
||||
GattCharacteristic **_characteristics;
|
||||
uint16_t _handle;
|
||||
};
|
||||
|
||||
#endif // ifndef __GATT_SERVICE_H__
|
||||
|
|
Loading…
Reference in a new issue