5 #ifndef HERALD_BLE_CONCRETE_H
6 #define HERALD_BLE_CONCRETE_H
8 #include "ble_concrete_database.h"
9 #include "ble_database.h"
10 #include "ble_receiver.h"
11 #include "ble_sensor.h"
12 #include "ble_transmitter.h"
13 #include "ble_concrete.h"
14 #include "ble_protocols.h"
15 #include "bluetooth_state_manager.h"
16 #include "ble_device_delegate.h"
17 #include "filter/ble_advert_parser.h"
18 #include "../payload/payload_data_supplier.h"
19 #include "../context.h"
20 #include "../data/sensor_logger.h"
21 #include "ble_sensor_configuration.h"
22 #include "ble_coordinator.h"
23 #include "../datatype/bluetooth_state.h"
28 #include "zephyr/concrete_ble_receiver.h"
30 #include "default/concrete_ble_receiver.h"
32 #include "zephyr/concrete_ble_transmitter.h"
35 #include "default/concrete_ble_receiver.h"
36 #include "default/concrete_ble_transmitter.h"
47 using namespace herald::ble::filter;
48 using namespace herald::payload;
58 template <
typename ContextT,
typename PayloadDataSupplierT,
typename SensorDelegateSetT, std::
size_t DBSize = 10>
63 PayloadDataSupplierT& payloadDataSupplier, SensorDelegateSetT& dels)
66 stateManager(bluetoothStateManager),
67 transmitter(ctx, bluetoothStateManager, payloadDataSupplier, database, dels),
68 receiver(ctx, bluetoothStateManager, payloadDataSupplier, database, dels),
70 coordinator(ctx, database, receiver),
71 addedSelfAsDelegate(
false)
72 HLOGGERINIT(ctx,
"sensor",
"ConcreteBLESensor")
83 std::optional<std::reference_wrapper<CoordinationProvider>> coordinationProvider() {
85 if (m_context.getSensorConfiguration().scanningEnabled) {
86 HTDBG(
"Providing a BLECoordinationProvider");
90 HTDBG(
"Scanning not supported - so not returning a BLECoordinationProvider");
95 return receiver.immediateSend(data,targetIdentifier);
98 bool immediateSendAll(
Data data) {
99 return receiver.immediateSendAll(data);
104 if (!addedSelfAsDelegate) {
105 stateManager.add(*
this);
107 addedSelfAsDelegate =
true;
112 delegates.sensor(SensorType::BLE, SensorState::on);
120 delegates.sensor(SensorType::BLE, SensorState::off);
125 void bleDatabaseDidCreate(
const BLEDevice& device)
override {
127 delegates.sensor(SensorType::BLE, device.identifier());
131 void bleDatabaseDidUpdate(
const BLEDevice& device,
const BLEDeviceAttribute attribute)
override {
133 case BLEDeviceAttribute::rssi: {
134 auto rssi = device.rssi();
135 if (rssi.intValue() != 0) {
136 double rssiValue = (double)rssi.intValue();
137 auto prox =
Proximity{.unit=ProximityMeasurementUnit::RSSI, .value=rssiValue};
139 delegates.sensor(SensorType::BLE,
145 auto payload = device.payloadData();
146 if (payload.size() > 0) {
148 delegates.sensor(SensorType::BLE,
158 case BLEDeviceAttribute::payloadData: {
159 auto payload = device.payloadData();
160 if (payload.size() > 0) {
162 delegates.sensor(SensorType::BLE,
168 auto rssi = device.rssi();
169 if (rssi.intValue() != 0) {
170 double rssiValue = (double)rssi.intValue();
171 auto prox =
Proximity{.unit=ProximityMeasurementUnit::RSSI, .value=rssiValue};
173 delegates.sensor(SensorType::BLE,
189 void bleDatabaseDidDelete(
const BLEDevice& device)
override {
195 void bluetoothStateManager(BluetoothState didUpdateState)
override {
196 if (BluetoothState::poweredOff == didUpdateState) {
199 if (BluetoothState::poweredOn == didUpdateState) {
202 if (BluetoothState::unsupported == didUpdateState) {
204 delegates.sensor(SensorType::BLE, SensorState::unavailable);
221 SensorDelegateSetT& delegates;
229 bool addedSelfAsDelegate;
Definition: ble_database_delegate.h:15
Definition: ble_device.h:181
Definition: bluetooth_state_manager_delegate.h:16
Definition: bluetooth_state_manager.h:19
Definition: ble_concrete_database.h:46
Dummy implementation of a ConcreteBLEReceiver that does nothing (used for testing)
Definition: concrete_ble_receiver.h:24
Definition: ble_concrete.h:60
Dummy implementation of a ConcreteBLETransmitter that does nothing (used for testing)
Definition: concrete_ble_transmitter.h:39
Definition: ble_coordinator.h:27
The main data workhorse class of the Herald API.
Definition: data.h:33
Definition: target_identifier.h:17
Contains all low-level Herald datatype implementations.
Definition: base64_string.h:14
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
Definition: proximity.h:17