5 #ifndef HERALD_BLE_CONCRETE_TRANSMITTER_H
6 #define HERALD_BLE_CONCRETE_TRANSMITTER_H
8 #include "../ble_database.h"
9 #include "../ble_receiver.h"
10 #include "../ble_sensor.h"
11 #include "../ble_transmitter.h"
12 #include "../ble_protocols.h"
13 #include "../bluetooth_state_manager.h"
14 #include "../ble_device_delegate.h"
15 #include "../filter/ble_advert_parser.h"
16 #include "../../payload/payload_data_supplier.h"
17 #include "../../context.h"
18 #include "../../data/sensor_logger.h"
19 #include "../ble_sensor_configuration.h"
20 #include "../ble_coordinator.h"
21 #include "../../datatype/bluetooth_state.h"
24 #include <bluetooth/bluetooth.h>
25 #include <bluetooth/hci.h>
26 #include <bluetooth/hci_vs.h>
28 #include <sys/byteorder.h>
29 #include <bluetooth/conn.h>
30 #include <bluetooth/uuid.h>
31 #include <bluetooth/gatt.h>
42 using namespace herald::ble::filter;
43 using namespace herald::payload;
49 namespace zephyrinternal {
53 GetPayloadFunction getPayloadDataSupplier();
55 void setPayloadDataSupplier(GetPayloadFunction pds);
58 struct bt_data* getAdvertData();
59 std::size_t getAdvertDataSize();
61 struct bt_le_adv_param* getAdvertParams();
63 void get_tx_power(uint8_t handle_type, uint16_t handle, int8_t *tx_pwr_lvl);
65 ssize_t read_vnd(
struct bt_conn *conn,
const struct bt_gatt_attr *attr,
66 void *buf, uint16_t len, uint16_t offset);
67 ssize_t write_vnd(
struct bt_conn *conn,
const struct bt_gatt_attr *attr,
68 const void *buf, uint16_t len, uint16_t offset,
70 ssize_t read_payload(
struct bt_conn *conn,
const struct bt_gatt_attr *attr,
71 void *buf, uint16_t len, uint16_t offset);
72 ssize_t write_payload(
struct bt_conn *conn,
const struct bt_gatt_attr *attr,
73 const void *buf, uint16_t len, uint16_t offset,
79 template <
typename ContextT,
typename PayloadDataSupplierT,
typename BLEDatabaseT,
typename SensorDelegateSetT>
83 PayloadDataSupplierT& payloadDataSupplier, BLEDatabaseT& bleDatabase, SensorDelegateSetT& dels)
85 m_stateManager(bluetoothStateManager),
86 m_pds(payloadDataSupplier),
91 HLOGGERINIT(ctx,
"Sensor",
"BLE.ConcreteBLETransmitter")
94 return m_pds.payload(pts);
108 std::optional<std::reference_wrapper<CoordinationProvider>> coordinationProvider() {
114 HTDBG(
"ConcreteBLETransmitter::start");
115 if (!m_context.getSensorConfiguration().advertisingEnabled) {
116 HTDBG(
"Sensor Configuration has advertising disabled. Returning.");
119 m_context.getPlatform().getAdvertiser().registerStopCallback([
this] () ->
void {
122 m_context.getPlatform().getAdvertiser().registerStartCallback([
this] () ->
void {
125 HTDBG(
"Advertising callbacks registered");
128 m_context.getPlatform().startBluetooth();
130 HTDBG(
"Bluetooth started. Requesting start of adverts");
136 HTDBG(
"ConcreteBLETransmitter::stop");
137 if (!m_context.getSensorConfiguration().advertisingEnabled) {
138 HTDBG(
"Sensor Configuration has advertising disabled. Returning.");
147 PayloadDataSupplierT& m_pds;
150 SensorDelegateSetT& delegates;
157 void startAdvertising()
160 if (!m_context.getSensorConfiguration().advertisingEnabled) {
161 HTDBG(
"Sensor Configuration has advertising disabled. Returning.");
184 int success = bt_le_adv_start(zephyrinternal::getAdvertParams(), zephyrinternal::getAdvertData(), zephyrinternal::getAdvertDataSize(), NULL, 0);
186 HTDBG(
"Start advertising failed");
194 HTDBG(
"Start advertising completed successfully");
195 isAdvertising =
true;
198 void stopAdvertising()
201 if (!m_context.getSensorConfiguration().advertisingEnabled) {
202 HTDBG(
"Sensor Configuration has advertising disabled. Returning.");
205 if (!isAdvertising) {
209 isAdvertising =
false;
210 int success = bt_le_adv_stop();
212 HTDBG(
"Stop advertising failed");
216 HTDBG(
"Stop advertising completed successfully");
Definition: bluetooth_state_manager.h:19
Dummy implementation of a ConcreteBLETransmitter that does nothing (used for testing)
Definition: concrete_ble_transmitter.h:39
Definition: payload_data.h:13
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: payload_timestamp.h:13