Bluenet  5.4.0
Bluenet, the firmware for the Crownstone power outlet
Loading...
Searching...
No Matches
CharacteristicGeneric< T > Class Template Reference

Characteristic of generic type T. More...

#include <cs_Characteristic.h>

Inheritance diagram for CharacteristicGeneric< T >:
Collaboration diagram for CharacteristicGeneric< T >:

Public Types

typedef function< void(const EncryptionAccessLevel, const T &, uint16_t length)> callback_on_write_t
 Format of callback on write (from user)
 

Public Member Functions

virtual ~CharacteristicGeneric ()
 Default empty destructor.
 
T & getValue ()
 Return the value In the case of aes encryption, this is the unencrypted value.
 
void onWrite (const callback_on_write_t &closure)
 Register an on write callback which will be triggered when a characteristic is written over ble.
 
 operator T& ()
 CharacteristicGeneric() returns value object In the case of aes encryption, this is the unencrypted value. More...
 
void operator= (const T &val)
 Assign a new value to the characteristic so that it can be read over ble. More...
 
void setDefaultValue (const T &t)
 Set the default value.
 
- Public Member Functions inherited from CharacteristicBase
 CharacteristicBase ()
 Unit. More...
 
virtual ~CharacteristicBase ()
 Empty destructor.
 
void init (Service *svc)
 Initialize the characteristic: add it to the softdevice. More...
 
void setName (const char *const name)
 Set the name of this characteristic.
 
void setWritable (bool writable)
 Set this characteristic to be writable.
 
void setNotifies (bool notifies)
 Set this characteristic to be notifiable.
 
bool isNotifyingEnabled ()
 
void setNotifyingEnabled (bool enabled)
 
void setIndicates (bool indicates)
 
void setUUID (const UUID &uuid)
 
uint16_t getValueHandle ()
 
uint16_t getCccdHandle ()
 
void setSharedEncryptionBuffer (bool val)
 
virtual uint16_t getGattValueMaxLength ()=0
 Return the maximum length of the value used by the gatt server In the case of aes encryption, this is the maximum length that the value can be when encrypted. More...
 
virtual void setGattValueLength (uint16_t)
 Set the length of the value used by the gatt server In the case of aes encryption, this is the length of the encrypted value otherwise it's the same as the value length which is a fixed value for normal types (arithmetic types and strings) but has to be set for buffer values because they have dynamic length. More...
 
virtual uint16_t getGattValueLength ()=0
 Return the actual length of the value used by the gatt server In the case of aes encryption, this is the length of the encrypted value otherwise it's the same as the value length. More...
 
uint8_t * getGattValuePtr ()
 Return the pointer to the memory where the value is accessed by the gatt server. More...
 
virtual uint8_t * getValuePtr ()=0
 Return the pointer to the memory where the value is stored In the case of aes encryption, this is the pointer to the unencrypted value. More...
 
virtual void setValueLength (uint16_t)
 Set the actual length of the data @length the length of the data to which the value points. More...
 
virtual uint16_t getValueLength ()=0
 Return the actual length of the value In the case of aes encryption, this is the length of the unencrypted data. More...
 
virtual void onWrite (uint16_t len)=0
 Helper function which is called when a characteristic is written over BLE. More...
 
uint32_t updateValue (ConnectionEncryptionType encryptionType=ConnectionEncryptionType::CTR)
 Update the value in the gatt server so that the value can be read over BLE If somebody is also listening to notifications for the characteristic notifications will be sent.
 
virtual uint32_t notify ()
 Notify any listening party. More...
 
void onNotifyTxError ()
 Callback function if a notify tx error occurs. More...
 
virtual void onTxComplete (const ble_common_evt_t *p_ble_evt)
 Callback function once tx operations complete @p_ble_evt the event object which triggered the onTxComplete callback. More...
 
void setAesEncrypted (bool encrypted)
 Enable / Disable aes encryption. More...
 
bool isAesEnabled ()
 Check if aes encryption is enabled.
 
void setMinAccessLevel (EncryptionAccessLevel level)
 
buffer_ptr_t & getEncryptionBuffer ()
 get the buffer used for encryption
 
ServicegetService ()
 

Protected Member Functions

void onWrite (uint16_t len)
 Helper function if a characteristic is written over ble. More...
 
virtual bool configurePresentationFormat (ble_gatts_char_pf_t &presentation_format)
 Configure the characteristic value format (ble specific) More...
 
void initEncryptionBuffer ()
 Initialize / allocate a buffer for encryption. More...
 
void freeEncryptionBuffer ()
 Free / release the encryption buffer. More...
 
virtual void initEncryptionBuffer ()=0
 Initialize the encryption buffer to hold the encrypted value. More...
 
virtual void freeEncryptionBuffer ()=0
 Free / release the encryption buffer. More...
 
virtual bool configurePresentationFormat (ble_gatts_char_pf_t &)
 Configure the characteristic value format (ble specific) More...
 

Protected Attributes

_value
 The generic type is physically located in this field in this class (by value, not just by reference) In the case of aes encryption, this is the unencrypted value.
 
callback_on_write_t _callbackOnWrite
 The callback to call on a write coming from the softdevice (and originating from the user)
 
- Protected Attributes inherited from CharacteristicBase
const char * _name = nullptr
 Name of this characteristic.
 
UUID _uuid
 UUID of this characteristic.
 
ble_gatts_char_handles_t _handles
 Handles.
 
Service_service = nullptr
 Reference to corresponding service.
 
Status _status
 Status of CharacteristicBase (basically a bunch of 1-bit flags)
 
buffer_ptr_t _encryptionBuffer = nullptr
 
EncryptionAccessLevel _minAccessLevel = ADMIN
 used for encryption. More...
 

Friends

class Service
 

Detailed Description

template<class T>
class CharacteristicGeneric< T >

Characteristic of generic type T.

Parameters
TGeneric type T

A characteristic first of all contains a templated "value" which might be a string, an integer, or a buffer, depending on the need at hand. It allows also for callbacks to be defined on writing to the characteristic, or reading from the characteristic.

Member Function Documentation

◆ configurePresentationFormat()

template<class T >
virtual bool CharacteristicGeneric< T >::configurePresentationFormat ( ble_gatts_char_pf_t &  )
inlineprotectedvirtual

Configure the characteristic value format (ble specific)

Reimplemented from CharacteristicBase.

◆ freeEncryptionBuffer()

template<class T >
void CharacteristicGeneric< T >::freeEncryptionBuffer ( )
inlineprotectedvirtual

Free / release the encryption buffer.

Implements CharacteristicBase.

◆ initEncryptionBuffer()

template<class T >
void CharacteristicGeneric< T >::initEncryptionBuffer ( )
inlineprotectedvirtual

Initialize / allocate a buffer for encryption.

Implements CharacteristicBase.

◆ onWrite()

template<class T >
void CharacteristicGeneric< T >::onWrite ( uint16_t  len)
inlineprotectedvirtual

Helper function if a characteristic is written over ble.

updates the length values for dynamic length types, decrypts the value if aes encryption enabled. then calls the on write callback.

Implements CharacteristicBase.

◆ operator T&()

template<class T >
CharacteristicGeneric< T >::operator T& ( )
inline

CharacteristicGeneric() returns value object In the case of aes encryption, this is the unencrypted value.

Returns
value object

◆ operator=()

template<class T >
void CharacteristicGeneric< T >::operator= ( const T &  val)
inline

Assign a new value to the characteristic so that it can be read over ble.

In the case of aes encryption, pass the unencrypted value, which will then be encrypted and updated at the gatt server

TODO: Alex - why don't we just use setValue for consistency??


The documentation for this class was generated from the following file: