nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
broadcaster.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright 2018-2019 Peter A. Bigot */
3 
7 #ifndef NRFCXX_SD_BROADCASTER
8 #define NRFCXX_SD_BROADCASTER
9 #pragma once
10 
11 #include <nrfcxx/core.hpp>
12 #include <nrfcxx/sd/beacon.hpp>
13 #include <nrfcxx/sensor/adc.hpp>
14 
15 namespace nrfcxx {
16 namespace sd {
17 
46 {
47 public:
48  /* NB: Events below 0x0010 are reserved for the Broadcaster
49  * internals. Available bits below EVT_APP_BASE: 0xC80 */
50 
56  static constexpr event_set::event_type EVT_SD = 0x0010;
57 
61  static constexpr event_set::event_type EVT_RADIO_ON = 0x0020;
62 
66  static constexpr event_set::event_type EVT_RADIO_OFF = 0x0040;
67 
86  static constexpr event_set::event_type EVT_VDD_REQUIRED = 0x0100;
87 
93  static constexpr event_set::event_type EVT_VDD_UPDATED = 0x0200;
94 
103  static constexpr event_set::event_type EVT_APP_BASE = 0x1000;
104 
111  static void state_setup (const systemState::state_type& ss,
112  bool is_reset,
113  bool retained);
114 
123  Broadcaster (const systemState& cs);
124 
126  ~Broadcaster ();
127 
135 
146  int start ();
147 
152  void stop ();
153 
164 
176  uint16_t vdd_mV () const
177  {
178  return vdd_mV_;
179  }
180 
183 
186 
189 
205 
218  int ram_delta () const
219  {
220  return ram_delta_;
221  }
222 
224  const ble_gap_addr_t& address () const
225  {
226  return addr_;
227  }
228 
231  const ble_version_t& fwid () const
232  {
233  return fwid_;
234  }
235 
236 private:
238  static void vdd_callback (uint16_t vdd_mV);
239 
241  void vdd_callback_ (uint16_t vdd_mV);
242 
243  int ram_delta_ = 0;
244  ble_version_t fwid_{};
245  ble_gap_addr_t addr_{};
246  uint16_t vdd_mV_ = 0;
247 };
248 
249 } // namespace sd
250 } // namespace nrfcxx
251 
252 #endif /* NRFCXX_SD_BROADCASTER */
nrfcxx::sd::Broadcaster::make_setter
notifier_type make_setter(event_set::event_type bits) const
Construct a setter for the specified bits.
nrfcxx::sd::Broadcaster::address
const ble_gap_addr_t & address() const
Reference the Bluetooth device address used in GAP.
Definition: broadcaster.hpp:224
nrfcxx::sd::Broadcaster::EVT_VDD_UPDATED
static constexpr event_set::event_type EVT_VDD_UPDATED
Event set when Vdd_mV() has been updated.
Definition: broadcaster.hpp:93
beacon.hpp
Infrastructure supporting BLE beacons.
nrfcxx::sd::Broadcaster::~Broadcaster
~Broadcaster()
stop() is invoked when broadcaster is destructed.
nrfcxx::sd::Broadcaster::sys_beacon
SystemStateBeacon sys_beacon
The owned system state beacon.
Definition: broadcaster.hpp:182
nrfcxx::sd::Broadcaster::vdd_sensor
sensor::adc::vdd vdd_sensor
A sensor instance that collects Vdd information for TelemetryBeacon.
Definition: broadcaster.hpp:204
nrfcxx::sd::Broadcaster
Infrastructure that starts and stops the soft device and provides a main event loop for the applicati...
Definition: broadcaster.hpp:45
nrfcxx::sd::Broadcaster::wait_for_event
event_set_copy wait_for_event()
Sleep until an event occurs.
nrfcxx::sd::Broadcaster::Broadcaster
Broadcaster(const systemState &cs)
Instantiate the broadcaster instance.
nrfcxx::sd::Broadcaster::EVT_RADIO_OFF
static constexpr event_set::event_type EVT_RADIO_OFF
Event set when the radio has turned off.
Definition: broadcaster.hpp:66
nrfcxx::sd::Broadcaster::ram_delta
int ram_delta() const
Get the difference between required and available soft-device RAM.
Definition: broadcaster.hpp:218
nrfcxx::sd::ApplicationIdBeacon
Beacon providing application identification information.
Definition: beacon.hpp:1239
nrfcxx::sd::Broadcaster::EVT_APP_BASE
static constexpr event_set::event_type EVT_APP_BASE
Base event available for application use.
Definition: broadcaster.hpp:103
nrfcxx::sd::Broadcaster::tlm_beacon
TelemetryBeacon tlm_beacon
The owned telemetry beacon.
Definition: broadcaster.hpp:185
nrfcxx::event_set_copy
A helper class for processing snapshot nrfcxx::event_set values.
Definition: core.hpp:654
nrfcxx::sd::Broadcaster::appid_beacon
ApplicationIdBeacon appid_beacon
The owned application identity beacon.
Definition: broadcaster.hpp:188
adc.hpp
Specializations of nrfcxx::periph::ADC for common ADC operations.
nrfcxx::sd::Broadcaster::stop
void stop()
Stop the broadcast infrastructure.
nrfcxx::systemState::state_type
The raw data supporting cross-reset state transfer.
Definition: core.hpp:993
nrfcxx::sd::Broadcaster::EVT_RADIO_ON
static constexpr event_set::event_type EVT_RADIO_ON
Event set when the radio has turned on.
Definition: broadcaster.hpp:61
nrfcxx::sd::Broadcaster::vdd_mV
uint16_t vdd_mV() const
Return the most recently read system voltage.
Definition: broadcaster.hpp:176
nrfcxx::sd::TelemetryBeacon
Beacon providing telemetry information.
Definition: beacon.hpp:700
nrfcxx::notifier_type
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
nrfcxx::systemState
A class supporting watchdog configuration and cross-reset retention of state.
Definition: core.hpp:853
nrfcxx::sd::Broadcaster::EVT_SD
static constexpr event_set::event_type EVT_SD
Event informing the application that a soft-device interrupt has occured.
Definition: broadcaster.hpp:56
nrfcxx::sd::SystemStateBeacon
Beacon providing system state information.
Definition: beacon.hpp:918
core.hpp
Primary header for nrfcxx interface dependencies.
nrfcxx::event_set::event_type
unsigned int event_type
The type used to represent a (set of) event(s).
Definition: core.hpp:547
nrfcxx::sd::Broadcaster::EVT_VDD_REQUIRED
static constexpr event_set::event_type EVT_VDD_REQUIRED
Event set when the broadcaster requires an updated Vdd measurement.
Definition: broadcaster.hpp:86
nrfcxx::sensor::adc::vdd
ADC instance to measure board Vdd.
Definition: adc.hpp:27
nrfcxx::sd::Broadcaster::state_setup
static void state_setup(const systemState::state_type &ss, bool is_reset, bool retained)
Function to maintain broadcaster state across resets.
nrfcxx::sd::Broadcaster::fwid
const ble_version_t & fwid() const
Reference the firmware version structure collected during start().
Definition: broadcaster.hpp:231
nrfcxx::sd::Broadcaster::start
int start()
Start the broadcast infrastructure.
nrfcxx
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17