nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
Go to the documentation of this file. 7 #ifndef NRFCXX_SD_BEACON 8 #define NRFCXX_SD_BEACON 11 #include <pabigot/ble/gap.hpp> 72 using pointer_type =
Beacon*;
73 pointer_type& operator() (
Beacon& bcn) noexcept
75 return bcn.next_ready_;
79 using queue_type = pabigot::container::forward_chain<Beacon, ref_next>;
206 return (10 * uptime::now()) / uptime::Frequency_Hz;
215 return (10 * (
total_uptime + uptime::now())) / uptime::Frequency_Hz;
222 return telemetry_state_;
267 } __attribute__((__packed__));
302 return min_interval_;
314 return max_interval_;
322 return prepare_backoff_;
355 unsigned int max_utt);
383 unsigned int backoff_utt);
472 template <
typename FT>
475 return update_crc_(reinterpret_cast<uint8_t*>(bp),
sizeof (*bp));
478 static const Beacon* active ()
558 static void requeue_active_ ();
568 static queue_type readyq_;
571 static telemetry_state_type telemetry_state_;
574 static void checked_notify_ ();
583 unsigned int tx_count_ = 0;
585 unsigned int interval_ = 0;
586 unsigned int min_interval_ = 0;
587 unsigned int max_interval_ = 0;
588 unsigned int prepare_backoff_ = 0;
592 unsigned int last_due_ = 0;
595 queue_type::pointer_type next_ready_ = queue_type::unlinked_ptr();
598 uint8_t dt_flags_ = pabigot::ble::gap::FDT_LE_NON_DISCOVERABLE;
599 int8_t dt_tx_power_ = 0;
604 std::array<uint8_t, pabigot::ble::gap::ASR_DATA_SIZE> pdu_;
606 #if (NRFCXX_SOFTDEVICE_IS_S130 - 0) 607 #elif ((NRFCXX_SOFTDEVICE_IS_S132 - 0) || (NRFCXX_SOFTDEVICE_IS_S140 - 0)) 613 static uint8_t handle_;
614 #else // NRFCXX_SOFTDEVICE_IS_ 615 #error softdevice not supported 616 #endif // NRFCXX_SOFTDEVICE_IS_ 636 template <
typename CONTENT_TYPE,
641 using content_type = CONTENT_TYPE;
642 static constexpr uint8_t FRAME_TYPE = ID;
643 static constexpr
size_t content_span = CONTENT_TYPE::SPAN;
659 } __attribute__((__packed__));
674 int populate_ (pabigot::ble::gap::adv_data& ad)
override 676 static_assert(content_span <=
sizeof(content_type),
677 "span overruns content");
681 auto beacon_span =
sizeof(
frame_s) + content_span;
682 auto bp = static_cast<frame_s *>(ad.set_ManufacturerSpecificData(
COMPANY_ID, beacon_span));
684 bp->prefix = {FRAME_TYPE,
flags};
685 memcpy(bp->content, &
content, content_span);
842 } __attribute__((__packed__));
884 flags_ = set | (flags_ & ~clear);
899 int populate_ (pabigot::ble::gap::adv_data& ad)
override;
901 uint16_t pwr_mV_ = 0;
948 } __attribute__((__packed__));
957 int populate_ (pabigot::ble::gap::adv_data& ad)
override;
1184 int finalizeInstance();
1195 bool append_ (
const void* vp,
size_t len);
1202 void setFlag_ (uint8_t flag)
1204 auto fp = reinterpret_cast<frame_s *>(instance_.
buffer.data());
1205 if (fp->flags & (~(flag - 1))) {
1212 instance_s instance_;
1223 int populate_ (pabigot::ble::gap::adv_data& ad)
override;
1282 } __attribute__((__packed__));
1296 const ble_version_t& fwid);
1299 int pre_activate_ ()
override;
1302 int populate_ (pabigot::ble::gap::adv_data& ad)
override;
content_type content
The content that will be copied into the beacon by populate_().
Definition: beacon.hpp:662
uint32_t last_pc
nrfcxx::systemState::state_type::last_pc
Definition: beacon.hpp:930
state_e state() const
Return the current beacon state.
Definition: beacon.hpp:286
uint16_t sleep_n16
Relative time spent in sleep mode since reset.
Definition: beacon.hpp:824
Indicates the beacon is actively transmitting.
Definition: beacon.hpp:161
Set to indicate that the device is being powered by mains.
Definition: beacon.hpp:731
uint32_t abs_cPa
Threshold for FT_FLAG_ABS_PRESSURE.
Definition: beacon.hpp:1121
uint8_t flags
The flags that will be used by populate_().
Definition: beacon.hpp:665
static void set_notify(notifier_type notify)
Register the notifier that signals application to process a beacon event.
uint16_t reset_count
nrfcxx::systemState::state_type::reset_count
Definition: beacon.hpp:933
uint32_t sec_cnt() const
Uptime since reset, in deciseconds.
Definition: beacon.hpp:203
void failsafe(FailSafeCode code)
Record a critical system failure and reset the system.
Definition: core.hpp:1692
uint16_t temperature_cCel
Threshold for FT_FLAG_TEMPERATURE and for thermistors.
Definition: beacon.hpp:1115
uint16_t humidity_pptt
Threshold for FT_FLAG_HUMIDITY.
Definition: beacon.hpp:1118
int significantChange(const instance_s &from, const threshold_s &thr) const
Assess whether the current instance differs from a previous instance significantly.
uint32_t adv_cnt
Number of beacons sent since system reset or installation.
Definition: beacon.hpp:797
Helper to schedule and construct beacons.
Definition: beacon.hpp:68
static constexpr uint16_t COMPANY_ID
The value to be used as the company ID for manufacturer specific data.
Definition: beacon.hpp:229
Frame content for this beacon.
Definition: beacon.hpp:925
uint8_t llver
Bluetooth Link Layer Version parameter.
Definition: beacon.hpp:1267
int activate()
Enable the beacon.
uint8_t wdt_status
nrfcxx::systemState::state_type::wdt_status
Definition: beacon.hpp:935
const systemState & system_state
The systemState instance from which information is taken.
Definition: beacon.hpp:954
Indicates a beacon that was deactivated while it was active.
Definition: beacon.hpp:127
void update_pwr_mV(uint16_t pwr_mV, bool is_vdd=false)
Provide a value for pwr_mV to be used in the next beacon.
Definition: beacon.hpp:861
virtual ~Beacon()
The beacon is stopped on destruction.
crc_type update_crc(FT *bp)
Helper to store a checksum immediately following a frame instance.
Definition: beacon.hpp:473
Beacon()
Construct a new beacon.
ApplicationIdBeacon()
Constructor for beacon requires a systemState reference.
Frame content for this beacon.
Definition: beacon.hpp:770
void power_level(power_level_type fn)
Provide a function that can estimate power source level from measured voltage.
Definition: beacon.hpp:893
frame_flag_e
Bits used in frame_prefix_s::flags to refine content of the frame.
Definition: beacon.hpp:717
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:773
Flag indicating that the frame contains a differential pressure measurement.
Definition: beacon.hpp:1053
int validate() const
Test whether the beacon is in a valid state.
uint8_t dt_flags() const
Get the GAP ASD Flags data type value to use in the beacon.
Definition: beacon.hpp:397
void set_tx_notify(notifier_type notify)
Configure notification that a beacon is being sent.
Definition: beacon.hpp:391
Set to indicate that frame_s::pwr_mV is a measure of system Vdd rather than a measure of some externa...
Definition: beacon.hpp:736
static constexpr uint8_t FRAME_TYPE_TEST
Frame type reserved for test applications.
Definition: beacon.hpp:246
Indicates that an attempt to transmit the beacon failed.
Definition: beacon.hpp:116
Core clock-related functionality.
Set to indicate that the field formerly used for wfe_cnt carries reset_count instead.
Definition: beacon.hpp:763
Indicates that the beacon is unusable.
Definition: beacon.hpp:109
Indicates that the beacon is scheduled for a pre-transmission notification.
Definition: beacon.hpp:137
Flag indicating that the frame contains a relative light intensity measurement that's proportional to...
Definition: beacon.hpp:1084
Application tried something that isn't allowed.
uint8_t heap_KiBy
Total reserved heap space, in kilobytes.
Definition: beacon.hpp:1280
Support for a persistent system clock with 32 KiHz resolution.
Definition: clock.hpp:243
virtual int pre_activate_()
Called by activate() to make sure everything needed for activation is present.
Definition: beacon.hpp:511
Indicates the beacon should transmit as soon as the radio is available.
Definition: beacon.hpp:154
uint32_t aggr_sec_cnt() const
Total uptime since reset, in deciseconds.
Definition: beacon.hpp:212
uint16_t diff_cPa
Threshold for FT_FLAG_DIFF_PRESSURE.
Definition: beacon.hpp:1124
static constexpr uint8_t APP_FRAME_TYPE_BASE
Minimum value for frame_prefix_s::frame_type available for application beacons.
Definition: beacon.hpp:236
uint32_t aggr_adv_cnt() const
Total number of advertisements sent since installation.
Definition: beacon.hpp:195
static void telemetry_state_setup(const systemState::state_type &ss, bool is_reset, bool retained)
Function to maintain beacon telemetry state across resets.
static constexpr uint8_t APP_FRAME_TYPE_LIMIT
Maximum value for frame_prefix_s::frame_type available for application beacons.
Definition: beacon.hpp:243
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:655
unsigned int previous_adv
Aggregate number of advertisements sent over all previous sessions.
Definition: beacon.hpp:179
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:922
Beacon providing application identification information.
Definition: beacon.hpp:1239
static constexpr uint8_t FRAME_TYPE
frame_prefix_s::frame_type value for this beacon.
Definition: beacon.hpp:704
Flag indicating that the frame contains a temperature measurement.
Definition: beacon.hpp:1016
unsigned int max_interval_utt() const
Maximum interval between transmissions, in uptime ticks.
Definition: beacon.hpp:312
static int process_event()
Method to be invoked by main loop when a beacon-related event occurs.
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:1249
Beacon providing information derived from environmental sensors.
Definition: beacon.hpp:970
void prepare(const systemState &system_state, const ble_version_t &fwid)
Function to be invoked once the soft device is running, to populate the beacon content.
uint8_t frame_type
Identifies packet content.
Definition: beacon.hpp:260
Frame content for this beacon is the first #content_span octets of a #content_type instance.
Definition: beacon.hpp:650
int reset_interval()
Reset the interval so the beacon is retransmitted as quickly as possible.
unsigned int prepare_backoff_utt() const
Duration before beacon transmission that a pre-transmission notification will occur,...
Definition: beacon.hpp:320
SystemStateBeacon(const systemState &system_state)
Constructor for beacon requires a systemState reference.
uint16_t eCO2_ppm
Threshold for FT_FLAG_IAQ_ECO2.
Definition: beacon.hpp:1127
uint8_t heap_use
Heap use relative to reserved heap memory.
Definition: beacon.hpp:941
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:928
const systemState & system_state
The systemState instance from which information is taken.
Definition: beacon.hpp:848
Flag indicating that the frame contains a relative humidity measurement.
Definition: beacon.hpp:1029
uint64_t total_uptime
Aggregate uptime from all previous sessions.
Definition: beacon.hpp:173
uint16_t sd_fwid
Soft-device firmware identifier.
Definition: beacon.hpp:1260
int deactivate()
Disable the beacon.
const instance_s & instance() const
Get a reference to the built-up content.
Definition: beacon.hpp:1168
Generic frame data holder.
Definition: beacon.hpp:1094
TelemetryBeacon(const systemState &system_state)
Constructor for beacon requires a systemState reference.
The raw data supporting cross-reset state transfer.
Definition: core.hpp:993
static const telemetry_state_type & telemetry_state()
Access the current telemetry state.
Definition: beacon.hpp:220
uint32_t sdfault_id
nrfcxx::systemState::state_type::sdfault_id
Definition: beacon.hpp:932
frame_flag_e
Bits used in frame_prefix_s::flags to identify the content of the frame.
Definition: beacon.hpp:1001
unsigned int interval_utt() const
Current interval between transmissions, in uptime ticks.
Definition: beacon.hpp:306
Set to indicate that the battery is being charged.
Definition: beacon.hpp:739
std::array< uint8_t, MAX_MSD_LENGTH > buffer
A buffer used to hold frame content.
Definition: beacon.hpp:1097
Frame content for this beacon.
Definition: beacon.hpp:1246
uint8_t stack_KiBy
Total reserved stack space, in kilobytes.
Definition: beacon.hpp:1274
uint32_t code
nrfcxx::systemState::state_type::code
Definition: beacon.hpp:931
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:974
Beacon providing telemetry information.
Definition: beacon.hpp:700
Indicates the beacon is not scheduled to transmit, but may be activated in the future.
Definition: beacon.hpp:122
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
static int process_completion()
Method to be invoked by main loop when the beacon has been transmitted.
A class supporting watchdog configuration and cross-reset retention of state.
Definition: core.hpp:853
uint16_t crc_type
Natively-supported checksum is CRC-16/DNP.
Definition: beacon.hpp:83
Class supporting an alarm with custom callback and repeatability.
Definition: clock.hpp:498
Set to indicate that the fixed content of #frame_s is followed in frame_s::optional by an 8-bit unsig...
Definition: beacon.hpp:756
uint8_t stack_use
Maximum observed stack use relative to reserved stack memory.
Definition: beacon.hpp:947
bool ready
Set to true when content has been updated.
Definition: beacon.hpp:671
unsigned int current_adv
Number of advertisements sent during this session.
Definition: beacon.hpp:182
static constexpr size_t MAX_MSD_LENGTH
The maximum length of a Manufacturer Specific Data PDU.
Definition: beacon.hpp:89
uint16_t eTVOC_ppb
Threshold for FT_FLAG_IAQ_ETVOC.
Definition: beacon.hpp:1130
uint16_t radio_n16
Relative time spent with radio on since reset.
Definition: beacon.hpp:833
State retained across resets that is used in telemetry beacons.
Definition: beacon.hpp:166
uint8_t optional[0]
Storage for optional content, presense indicated by the following flags, in this order:
Definition: beacon.hpp:841
unsigned int tx_count() const
Return the number of transmissions since activation.
Definition: beacon.hpp:455
uint32_t app_crc
The value from application_crc32().
Definition: beacon.hpp:1252
uint8_t span
The length of the MSD content, including terminating CRC.
Definition: beacon.hpp:1102
Flag indicating that the frame contains an equivalent CO2 air quality measurement.
Definition: beacon.hpp:1063
int set_interval(unsigned int utt)
Configure a fixed interval.
Definition: beacon.hpp:333
uint8_t content[0]
Where the first #content_span octets of content is copied.
Definition: beacon.hpp:658
uint8_t mutate_flags(uint8_t set, uint8_t clear)
Modify the content of frame_prefix_s::flags.
Definition: beacon.hpp:881
Structure providing the prefix for most beacon content.
Definition: beacon.hpp:253
int populate_(pabigot::ble::gap::adv_data &ad) override
Function that must be overridden to fill in beacon content.
Definition: beacon.hpp:674
Beacon providing system state information.
Definition: beacon.hpp:918
int8_t dt_tx_power() const
Get the GAP ASD Tx Power data type value to use in the beacon.
Definition: beacon.hpp:406
uint16_t reset_cnt
Low bits of a low-level ARM event counter.
Definition: beacon.hpp:815
int set_prepare_backoff(notifier_type notify, unsigned int backoff_utt)
Configure notification that a beacon will transmit soon.
Infrastructure to manage a beacon with a fixed payload.
Definition: beacon.hpp:638
state_e
Values representing the beacon state.
Definition: beacon.hpp:100
uint8_t light_1
Threshold for FT_FLAG_LIGHT_INTENSITY.
Definition: beacon.hpp:1133
virtual int populate_(pabigot::ble::gap::adv_data &ad)
Function that must be overridden to fill in beacon content.
Definition: beacon.hpp:547
uint16_t reset_reas
nrfcxx::systemState::state_type::reset_reas
Definition: beacon.hpp:934
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:1243
Set to indicate that frame_s::adv_cnt and frame_s::sec_cnt are aggregates since installation (or powe...
Definition: beacon.hpp:748
Flag indicating that the frame contains an equivalent Total Volatile Organic Compound air quality mea...
Definition: beacon.hpp:1073
uint32_t adv_cnt() const
Number of advertisements sent since reset.
Definition: beacon.hpp:187
unsigned int(* power_level_type)(unsigned int)
Function type for calculating power source level from power voltage.
Definition: beacon.hpp:712
Flag indicating that the frame contains an absolute atmospheric pressure measurement.
Definition: beacon.hpp:1043
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
uint8_t flags
Flags that provide additional information about the beacon content.
Definition: beacon.hpp:266
Thresholds for detecting significant changes in readings.
Definition: beacon.hpp:1112
unsigned int min_interval_utt() const
Minimum interval between transmissions, in uptime ticks.
Definition: beacon.hpp:300
crc_type update_crc_(uint8_t *sp, size_t span)
Function to calculate a checksum and store it after the data.
Indicates the beacon is scheduled for a future transmission.
Definition: beacon.hpp:146
uint32_t sec_cnt
Time since system system reset or installation.
Definition: beacon.hpp:809
uint16_t pwr_mV
Measured system power source voltage in millivolts.
Definition: beacon.hpp:787