Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Service.h
Go to the documentation of this file.
1
10#pragma once
11
13#include <ble/cs_Stack.h>
14#include <cfg/cs_Strings.h>
15#include <common/cs_BaseClass.h>
16#include <common/cs_Tuple.h>
17#include <drivers/cs_Timer.h>
18#include <util/cs_BleError.h>
19
20class Stack;
22
26class Service : public BaseClass<1> {
27public:
29
31
39 virtual ~Service() {}
40
44 void init(Stack* stack);
45
51 void setUUID(const UUID& uuid);
52
53 Stack* getStack() { return _stack; }
54
55 const UUID& getUUID() const { return _uuid; }
56
57 uint16_t getHandle() { return _handle; }
58
60
61 virtual void createCharacteristics() = 0;
62
63 void onBleEvent(const ble_evt_t* event);
64
65 void onConnect(uint16_t connectionHandle, const ble_gap_evt_connected_t& event);
66
67 void onDisconnect(uint16_t connectionHandle, const ble_gap_evt_disconnected_t& event);
68
69 bool onWrite(const ble_gatts_evt_write_t& event, uint16_t gattHandle);
70
71 void onTxComplete(const ble_common_evt_t* event);
72
77
78 void updatedCharacteristics() { _characteristics.shrink_to_fit(); }
79
80private:
82 Stack* _stack = nullptr;
83
85
87 uint16_t _handle = BLE_CONN_HANDLE_INVALID;
88
91};
BaseClass.
Definition: cs_BaseClass.h:15
Base class for a BLE characteristic.
Definition: cs_CharacteristicBase.h:42
Base class for a BLE service.
Definition: cs_Service.h:26
void init(Stack *stack)
Initialize the service: register it at the softdevice.
tuple< CharacteristicBase * > _characteristics
List of characteristics.
Definition: cs_Service.h:90
Stack * _stack
Back reference to the stack.
Definition: cs_Service.h:82
uint16_t _handle
Service handle will be obtained from SoftDevice.
Definition: cs_Service.h:87
const UUID & getUUID() const
Definition: cs_Service.h:55
void setUUID(const UUID &uuid)
Set the UUID.
UUID _uuid
Definition: cs_Service.h:84
void onTxComplete(const ble_common_evt_t *event)
void updatedCharacteristics()
Definition: cs_Service.h:78
condition_t
Definition: cs_Service.h:28
@ C_SERVICE_INITIALIZED
Definition: cs_Service.h:28
void addCharacteristic(CharacteristicBase *characteristic)
Add a single characteristic to the list @characteristic Characteristic to add.
void onDisconnect(uint16_t connectionHandle, const ble_gap_evt_disconnected_t &event)
void onConnect(uint16_t connectionHandle, const ble_gap_evt_connected_t &event)
void onBleEvent(const ble_evt_t *event)
virtual ~Service()
Default empty destructor.
Definition: cs_Service.h:39
bool onWrite(const ble_gatts_evt_write_t &event, uint16_t gattHandle)
uint16_t getHandle()
Definition: cs_Service.h:57
Stack * getStack()
Definition: cs_Service.h:53
virtual void createCharacteristics()=0
tuple< CharacteristicBase * > getCharacteristics()
Definition: cs_Service.h:59
nRF51822 specific implementation of the BLEStack
Definition: cs_Stack.h:41
Class that enables the use of 128 bit service UUIDs.
Definition: cs_UUID.h:35
A tuple is a vector with a templated type and a public constructor.
Definition: cs_Tuple.h:18
Bluetooth Low Energy characteristics.
Manufacturing data.