nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
Infrastructure that starts and stops the soft device and provides a main event loop for the application, exposed through make_setter(). More...
#include <nrfcxx/sd/broadcaster.hpp>
Public Member Functions | |
Broadcaster (const systemState &cs) | |
Instantiate the broadcaster instance. More... | |
~Broadcaster () | |
stop() is invoked when broadcaster is destructed. | |
notifier_type | make_setter (event_set::event_type bits) const |
Construct a setter for the specified bits. More... | |
int | start () |
Start the broadcast infrastructure. More... | |
void | stop () |
Stop the broadcast infrastructure. More... | |
event_set_copy | wait_for_event () |
Sleep until an event occurs. More... | |
uint16_t | vdd_mV () const |
Return the most recently read system voltage. More... | |
int | ram_delta () const |
Get the difference between required and available soft-device RAM. More... | |
const ble_gap_addr_t & | address () const |
Reference the Bluetooth device address used in GAP. | |
const ble_version_t & | fwid () const |
Reference the firmware version structure collected during start(). | |
Static Public Member Functions | |
static void | state_setup (const systemState::state_type &ss, bool is_reset, bool retained) |
Function to maintain broadcaster state across resets. More... | |
Data Fields | |
SystemStateBeacon | sys_beacon |
The owned system state beacon. | |
TelemetryBeacon | tlm_beacon |
The owned telemetry beacon. | |
ApplicationIdBeacon | appid_beacon |
The owned application identity beacon. | |
sensor::adc::vdd | vdd_sensor |
A sensor instance that collects Vdd information for TelemetryBeacon. More... | |
Static Public Attributes | |
static constexpr event_set::event_type | EVT_SD = 0x0010 |
Event informing the application that a soft-device interrupt has occured. More... | |
static constexpr event_set::event_type | EVT_RADIO_ON = 0x0020 |
Event set when the radio has turned on. More... | |
static constexpr event_set::event_type | EVT_RADIO_OFF = 0x0040 |
Event set when the radio has turned off. More... | |
static constexpr event_set::event_type | EVT_VDD_REQUIRED = 0x0100 |
Event set when the broadcaster requires an updated Vdd measurement. More... | |
static constexpr event_set::event_type | EVT_VDD_UPDATED = 0x0200 |
Event set when Vdd_mV() has been updated. More... | |
static constexpr event_set::event_type | EVT_APP_BASE = 0x1000 |
Base event available for application use. More... | |
Infrastructure that starts and stops the soft device and provides a main event loop for the application, exposed through make_setter().
It also supplies the maintenance operation for both owned and external beacons, including (in preferred activation order):
The owned beacons are created by the broadcaster, and their configurations may be changed by the application prior to starting the broadcaster. The beacons are not started along with the broadcaster; if the application desires them they should be activated once the broadcaster is running.
Any application-specific beacons may also be activated after start(). These do not need to be registered with the broadcaster.
Once activated the notifications associated with beacon maintenance are processed by the broadcaster's event loop. The application should invoke wait_for_event() in its main loop, to receive any application-specific events that it must process.
All owned beacons are deactivated when the broadcaster is stopped.
nrfcxx::sd::Broadcaster::Broadcaster | ( | const systemState & | cs | ) |
Instantiate the broadcaster instance.
cs | reference to the application-controlled system state. Note that the application must have caused state_setup() to be invoked when this state was initialized. |
notifier_type nrfcxx::sd::Broadcaster::make_setter | ( | event_set::event_type | bits | ) | const |
Construct a setter for the specified bits.
bits
includes any bits reserved by the Broadcaster instance.
|
inline |
Get the difference between required and available soft-device RAM.
A postive value indicates that the amount of memory available is that much more than is required.
A negative value indicates that the amount of memory available must be increased by the absolute value in order to allow the system to run. In this case start() will fail with NRF_ERROR_NO_MEM
.
int nrfcxx::sd::Broadcaster::start | ( | ) |
Start the broadcast infrastructure.
|
static |
Function to maintain broadcaster state across resets.
This must be invoked from the application's systemState app_handler to ensure telemetry state is properly managed.
void nrfcxx::sd::Broadcaster::stop | ( | ) |
Stop the broadcast infrastructure.
All owned beacons are deactivated during this process.
|
inline |
Return the most recently read system voltage.
The value will be zero until the first sample of vdd_sensor completes. EVT_VDD_UPDATED is generated when the value changes.
event_set_copy nrfcxx::sd::Broadcaster::wait_for_event | ( | ) |
Sleep until an event occurs.
This checks for pending events, and if none are available drops to the lowest power mode available and waits for an event. When an event is received the set of events is captured, all internal events are processed, and the remaining events are returned to the caller for processing.
|
staticconstexpr |
Base event available for application use.
The application may define and set events at or higher than this bit. For example:
#define EVT_SAMPLE (Broadcaster::EVT_APP_BASE << 0) #define EVT_PROCESS (Broadcaster::EVT_APP_BASE << 1)
|
staticconstexpr |
Event set when the radio has turned off.
The application may ignore this event if it is not relevant.
|
staticconstexpr |
Event set when the radio has turned on.
The application may ignore this event if it is not relevant.
|
staticconstexpr |
Event informing the application that a soft-device interrupt has occured.
Such events are not expected for broadcasters, but probably should be handled anyway.
|
staticconstexpr |
Event set when the broadcaster requires an updated Vdd measurement.
This event should be expected to fire shortly (nominally, 500 ms) before a TelemetryBeacon is transmitted. Inspect tlm_beacon for transmission rates.
The application should initiate a sample using vdd_sensor as soon as feasible after the event is received.
Alternatively the application may calculate the voltage of the system power source (Vbatt, by preference) through other means and provide it to tlm_beacon via TelemetryBeacon::update_pwr_mV().
If no power source voltage has been provided by the time the beacon content is formed the beacon will transmit a zero value.
|
staticconstexpr |
Event set when Vdd_mV() has been updated.
This event will be provided after the application successfully initiates a sample on vdd_sensor.
sensor::adc::vdd nrfcxx::sd::Broadcaster::vdd_sensor |
A sensor instance that collects Vdd information for TelemetryBeacon.
If this sensor is not used and the source voltage not provided through some other mechanism telemetry beacons will not provide source voltage.
The application is responsible for provisioning, enabling, and calibrating periph::ADC, and claiming and releasing the client in response to EVT_VDD_REQUIRED events.