nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
beacon.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_BEACON
8 #define NRFCXX_SD_BEACON
9 #pragma once
10 
11 #include <pabigot/ble/gap.hpp>
12 
13 #include <nrfcxx/clock.hpp>
14 
15 #include "ble.h"
16 
17 namespace nrfcxx {
18 namespace sd {
19 
68 class Beacon
69 {
70  struct ref_next
71  {
72  using pointer_type = Beacon*;
73  pointer_type& operator() (Beacon& bcn) noexcept
74  {
75  return bcn.next_ready_;
76  }
77  };
78 
79  using queue_type = pabigot::container::forward_chain<Beacon, ref_next>;
80 
81 public:
83  using crc_type = uint16_t;
84 
89  static constexpr size_t MAX_MSD_LENGTH = 19 + sizeof(crc_type);
90 
100  enum state_e : uint8_t
101  {
109  INVALID = 0,
110 
117 
123 
128 
138 
147 
155 
162  };
163 
167  {
173  uint64_t total_uptime;
174 
179  unsigned int previous_adv;
180 
182  unsigned int current_adv;
183 
187  uint32_t adv_cnt () const
188  {
189  return current_adv;
190  }
191 
195  uint32_t aggr_adv_cnt () const
196  {
197  return previous_adv + current_adv;
198  }
199 
203  uint32_t sec_cnt () const
204  {
205  using clock::uptime;
206  return (10 * uptime::now()) / uptime::Frequency_Hz;
207  }
208 
212  uint32_t aggr_sec_cnt () const
213  {
214  using clock::uptime;
215  return (10 * (total_uptime + uptime::now())) / uptime::Frequency_Hz;
216  }
217  };
218 
221  {
222  return telemetry_state_;
223  }
224 
229  static constexpr uint16_t COMPANY_ID = -1;
230 
236  static constexpr uint8_t APP_FRAME_TYPE_BASE = 0x80;
237 
243  static constexpr uint8_t APP_FRAME_TYPE_LIMIT = 0xEF;
244 
246  static constexpr uint8_t FRAME_TYPE_TEST = 0xFF;
247 
254  {
261 
266  uint8_t flags = 0;
267  } __attribute__((__packed__));
268 
270  /* You can't move or copy these because that would invalidate the
271  * links in the ready queue. */
272  Beacon (const Beacon&) = delete;
273  Beacon& operator= (const Beacon&) = delete;
274  Beacon (Beacon&&) = delete;
275  Beacon& operator= (Beacon&&) = delete;
279  virtual ~Beacon ();
280 
286  state_e state () const
287  {
288  return state_;
289  }
290 
297  int validate () const;
298 
300  unsigned int min_interval_utt () const
301  {
302  return min_interval_;
303  }
304 
306  unsigned int interval_utt () const
307  {
308  return interval_;
309  }
310 
312  unsigned int max_interval_utt () const
313  {
314  return max_interval_;
315  }
316 
320  unsigned int prepare_backoff_utt () const
321  {
322  return prepare_backoff_;
323  }
324 
333  int set_interval (unsigned int utt)
334  {
335  return set_interval(utt, utt);
336  }
337 
354  int set_interval (unsigned int min_utt,
355  unsigned int max_utt);
356 
383  unsigned int backoff_utt);
384 
392  {
393  tx_notify_ = notify;
394  }
395 
397  uint8_t dt_flags () const
398  {
399  return dt_flags_;
400  }
401 
403  void dt_flags (uint8_t v);
404 
406  int8_t dt_tx_power () const
407  {
408  return dt_tx_power_;
409  }
410 
412  void dt_tx_power (int8_t v);
413 
438  int reset_interval ();
439 
449  int activate ();
450 
452  int deactivate ();
453 
455  unsigned int tx_count () const
456  {
457  return tx_count_;
458  }
459 
472  template <typename FT>
474  {
475  return update_crc_(reinterpret_cast<uint8_t*>(bp), sizeof (*bp));
476  }
477 
478  static const Beacon* active ()
479  {
480  return active_;
481  }
482 
485  static void set_notify (notifier_type notify);
486 
489  static int process_event ();
490 
493  static int process_completion ();
494 
501  static void telemetry_state_setup (const systemState::state_type& ss,
502  bool is_reset,
503  bool retained);
504 
505 protected:
507  Beacon ();
508 
511  virtual int pre_activate_ ()
512  {
513  return 0;
514  }
515 
524  crc_type update_crc_ (uint8_t* sp, size_t span);
525 
547  virtual int populate_ (pabigot::ble::gap::adv_data& ad)
548  {
549  return -EINVAL;
550  }
551 
552 private:
554  static bool alarm_callback (clock::alarm& alarm);
555 
558  static void requeue_active_ ();
559 
562  static notifier_type notify_;
563 
565  static Beacon* active_;
566 
568  static queue_type readyq_;
569 
571  static telemetry_state_type telemetry_state_;
572 
574  static void checked_notify_ ();
575 
577  Beacon* reschedule_ ();
578 
579  clock::alarm alarm_;
580 
581  notifier_type prepare_notify_;
582  notifier_type tx_notify_;
583  unsigned int tx_count_ = 0;
584 
585  unsigned int interval_ = 0;
586  unsigned int min_interval_ = 0;
587  unsigned int max_interval_ = 0;
588  unsigned int prepare_backoff_ = 0;
589 
592  unsigned int last_due_ = 0;
593 
595  queue_type::pointer_type next_ready_ = queue_type::unlinked_ptr();
596 
597  state_e volatile state_ = INVALID;
598  uint8_t dt_flags_ = pabigot::ble::gap::FDT_LE_NON_DISCOVERABLE;
599  int8_t dt_tx_power_ = 0;
600 
601  /* Although S130 will store the PDU in SD RAM, S132 appears to
602  * transmit from an application-owned buffer. Have the beacon
603  * instance own the data regardless of soft device. */
604  std::array<uint8_t, pabigot::ble::gap::ASR_DATA_SIZE> pdu_;
605 
606 #if (NRFCXX_SOFTDEVICE_IS_S130 - 0)
607 #elif ((NRFCXX_SOFTDEVICE_IS_S132 - 0) || (NRFCXX_SOFTDEVICE_IS_S140 - 0))
608  /* S132 and S140 use a handle to identify the advertising set
609  * characteristics, but contrary to the implication you can only
610  * define one advertising set.
611  *
612  * See https://devzone.nordicsemi.com/f/nordic-q-a/35200/sd_ble_gap_adv_set_configure-returning-error-4-nrf_error_no_mem */
613  static uint8_t handle_;
614 #else // NRFCXX_SOFTDEVICE_IS_
615 #error softdevice not supported
616 #endif // NRFCXX_SOFTDEVICE_IS_
617 };
618 
636 template <typename CONTENT_TYPE,
637  uint8_t ID>
639 {
640 public:
641  using content_type = CONTENT_TYPE;
642  static constexpr uint8_t FRAME_TYPE = ID;
643  static constexpr size_t content_span = CONTENT_TYPE::SPAN;
644 
650  struct frame_s
651  {
656 
658  uint8_t content[0];
659  } __attribute__((__packed__));
660 
662  content_type content{};
663 
665  uint8_t flags = 0;
666 
671  bool ready = false;
672 
673 protected:
674  int populate_ (pabigot::ble::gap::adv_data& ad) override
675  {
676  static_assert(content_span <= sizeof(content_type),
677  "span overruns content");
678  if (!ready) {
679  return 0;
680  }
681  auto beacon_span = sizeof(frame_s) + content_span;
682  auto bp = static_cast<frame_s *>(ad.set_ManufacturerSpecificData(COMPANY_ID, beacon_span));
683  if (bp) {
684  bp->prefix = {FRAME_TYPE, flags};
685  memcpy(bp->content, &content, content_span);
686  }
687  return 1;
688  }
689 };
690 
700 class TelemetryBeacon : public Beacon
701 {
702 public:
704  static constexpr uint8_t FRAME_TYPE = 0;
705 
712  typedef unsigned int (* power_level_type) (unsigned int);
713 
717  enum frame_flag_e : uint8_t
718  {
732 
737 
740 
749 
757 
764 
765  //
766  // Bits 6-7 are undefined and should be zero.
767  };
768 
770  struct frame_s
771  {
774 
787  uint16_t pwr_mV;
788 
797  uint32_t adv_cnt;
798 
809  uint32_t sec_cnt;
810 
815  uint16_t reset_cnt;
816 
824  uint16_t sleep_n16;
825 
833  uint16_t radio_n16;
834 
841  uint8_t optional[0];
842  } __attribute__((__packed__));
843 
846 
849 
861  void update_pwr_mV (uint16_t pwr_mV,
862  bool is_vdd = false)
863  {
864  pwr_mV_ = pwr_mV;
865  if (is_vdd) {
867  } else {
869  }
870  }
871 
881  uint8_t mutate_flags (uint8_t set,
882  uint8_t clear)
883  {
884  flags_ = set | (flags_ & ~clear);
885  return flags_;
886  }
887 
894  {
895  power_level_ = fn;
896  }
897 
898 private:
899  int populate_ (pabigot::ble::gap::adv_data& ad) override;
900  power_level_type power_level_{};
901  uint16_t pwr_mV_ = 0;
902  uint8_t flags_ = 0;
903 };
904 
918 class SystemStateBeacon : public Beacon
919 {
920 public:
922  static constexpr uint8_t FRAME_TYPE = 1;
923 
925  struct frame_s
926  {
929 
930  uint32_t last_pc;
931  uint32_t code;
932  uint32_t sdfault_id;
933  uint16_t reset_count;
934  uint16_t reset_reas;
935  uint8_t wdt_status;
936 
941  uint8_t heap_use;
942 
947  uint8_t stack_use;
948  } __attribute__((__packed__));
949 
952 
955 
956 private:
957  int populate_ (pabigot::ble::gap::adv_data& ad) override;
958 };
959 
971 {
972 public:
974  static constexpr uint8_t FRAME_TYPE = 2;
975 
1001  enum frame_flag_e : uint8_t
1002  {
1017 
1030 
1044 
1054 
1064 
1074 
1085  };
1086 
1092 
1094  struct instance_s
1095  {
1097  std::array<uint8_t, MAX_MSD_LENGTH> buffer;
1098 
1102  uint8_t span;
1103  };
1104 
1113  {
1116 
1118  uint16_t humidity_pptt;
1119 
1121  uint32_t abs_cPa;
1122 
1124  uint16_t diff_cPa;
1125 
1127  uint16_t eCO2_ppm;
1128 
1130  uint16_t eTVOC_ppb;
1131 
1133  uint8_t light_1;
1134  };
1135 
1160  int significantChange (const instance_s& from,
1161  const threshold_s& thr) const;
1162 
1168  const instance_s& instance () const
1169  {
1170  return instance_;
1171  }
1172 
1173  EnvSensorBeacon ();
1174 
1175  EnvSensorBeacon& resetInstance ();
1176  EnvSensorBeacon& addTemperature (int16_t value_cCel);
1177  EnvSensorBeacon& addHumidity (uint16_t value_pptt);
1178  EnvSensorBeacon& addAbsPressure (unsigned int value_cPa);
1179  EnvSensorBeacon& addDiffPressure (int16_t value_cPa);
1180  EnvSensorBeacon& addECO2 (uint16_t value_ppm);
1181  EnvSensorBeacon& addETVOC (uint16_t value_ppb);
1182  EnvSensorBeacon& addLightIntensity (uint8_t value_1);
1183  EnvSensorBeacon& addThermistor (int16_t value_cCel);
1184  int finalizeInstance();
1185 
1186 private:
1195  bool append_ (const void* vp, size_t len);
1196 
1202  void setFlag_ (uint8_t flag)
1203  {
1204  auto fp = reinterpret_cast<frame_s *>(instance_.buffer.data());
1205  if (fp->flags & (~(flag - 1))) {
1207  }
1208  fp->flags |= flag;
1209  }
1210 
1212  instance_s instance_;
1213 
1221  uint8_t bi_ = 0;
1222 
1223  int populate_ (pabigot::ble::gap::adv_data& ad) override;
1224 };
1225 
1240 {
1241 public:
1243  static constexpr uint8_t FRAME_TYPE = 3;
1244 
1246  struct frame_s
1247  {
1249  frame_prefix_s prefix;
1250 
1252  uint32_t app_crc;
1253 
1260  uint16_t sd_fwid;
1261 
1267  uint8_t llver;
1268 
1274  uint8_t stack_KiBy;
1275 
1280  uint8_t heap_KiBy;
1281 
1282  } __attribute__((__packed__));
1283 
1286 
1295  void prepare (const systemState& system_state,
1296  const ble_version_t& fwid);
1297 
1298 private:
1299  int pre_activate_ () override;
1300 
1301  frame_s frame_;
1302  int populate_ (pabigot::ble::gap::adv_data& ad) override;
1303 };
1304 
1305 } // namespace sd
1306 } // namespace nrfcxx
1307 
1308 #endif /* NRFCXX_SD_BEACON */
nrfcxx::sd::GenericBeacon::content
content_type content
The content that will be copied into the beacon by populate_().
Definition: beacon.hpp:662
nrfcxx::sd::SystemStateBeacon::frame_s::last_pc
uint32_t last_pc
nrfcxx::systemState::state_type::last_pc
Definition: beacon.hpp:930
nrfcxx::sd::Beacon::state
state_e state() const
Return the current beacon state.
Definition: beacon.hpp:286
nrfcxx::sd::TelemetryBeacon::frame_s::sleep_n16
uint16_t sleep_n16
Relative time spent in sleep mode since reset.
Definition: beacon.hpp:824
nrfcxx::sd::Beacon::ACTIVE
Indicates the beacon is actively transmitting.
Definition: beacon.hpp:161
nrfcxx::sd::TelemetryBeacon::FT_FLAG_MAINS_POWER
Set to indicate that the device is being powered by mains.
Definition: beacon.hpp:731
nrfcxx::sd::EnvSensorBeacon::threshold_s::abs_cPa
uint32_t abs_cPa
Threshold for FT_FLAG_ABS_PRESSURE.
Definition: beacon.hpp:1121
nrfcxx::sd::GenericBeacon::flags
uint8_t flags
The flags that will be used by populate_().
Definition: beacon.hpp:665
nrfcxx::sd::Beacon::set_notify
static void set_notify(notifier_type notify)
Register the notifier that signals application to process a beacon event.
nrfcxx::sd::SystemStateBeacon::frame_s::reset_count
uint16_t reset_count
nrfcxx::systemState::state_type::reset_count
Definition: beacon.hpp:933
nrfcxx::sd::Beacon::telemetry_state_type::sec_cnt
uint32_t sec_cnt() const
Uptime since reset, in deciseconds.
Definition: beacon.hpp:203
nrfcxx::failsafe
void failsafe(FailSafeCode code)
Record a critical system failure and reset the system.
Definition: core.hpp:1692
nrfcxx::sd::EnvSensorBeacon::threshold_s::temperature_cCel
uint16_t temperature_cCel
Threshold for FT_FLAG_TEMPERATURE and for thermistors.
Definition: beacon.hpp:1115
nrfcxx::sd::EnvSensorBeacon::threshold_s::humidity_pptt
uint16_t humidity_pptt
Threshold for FT_FLAG_HUMIDITY.
Definition: beacon.hpp:1118
nrfcxx::sd::EnvSensorBeacon::significantChange
int significantChange(const instance_s &from, const threshold_s &thr) const
Assess whether the current instance differs from a previous instance significantly.
nrfcxx::sd::TelemetryBeacon::frame_s::adv_cnt
uint32_t adv_cnt
Number of beacons sent since system reset or installation.
Definition: beacon.hpp:797
nrfcxx::sd::Beacon
Helper to schedule and construct beacons.
Definition: beacon.hpp:68
nrfcxx::sd::Beacon::COMPANY_ID
static constexpr uint16_t COMPANY_ID
The value to be used as the company ID for manufacturer specific data.
Definition: beacon.hpp:229
nrfcxx::sd::SystemStateBeacon::frame_s
Frame content for this beacon.
Definition: beacon.hpp:925
nrfcxx::sd::ApplicationIdBeacon::frame_s::llver
uint8_t llver
Bluetooth Link Layer Version parameter.
Definition: beacon.hpp:1267
nrfcxx::sd::Beacon::activate
int activate()
Enable the beacon.
nrfcxx::sd::SystemStateBeacon::frame_s::wdt_status
uint8_t wdt_status
nrfcxx::systemState::state_type::wdt_status
Definition: beacon.hpp:935
nrfcxx::sd::SystemStateBeacon::system_state
const systemState & system_state
The systemState instance from which information is taken.
Definition: beacon.hpp:954
nrfcxx::sd::Beacon::CANCELLED
Indicates a beacon that was deactivated while it was active.
Definition: beacon.hpp:127
nrfcxx::sd::TelemetryBeacon::update_pwr_mV
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
nrfcxx::sd::Beacon::~Beacon
virtual ~Beacon()
The beacon is stopped on destruction.
nrfcxx::sd::Beacon::update_crc
crc_type update_crc(FT *bp)
Helper to store a checksum immediately following a frame instance.
Definition: beacon.hpp:473
nrfcxx::sd::Beacon::Beacon
Beacon()
Construct a new beacon.
nrfcxx::sd::ApplicationIdBeacon::ApplicationIdBeacon
ApplicationIdBeacon()
Constructor for beacon requires a systemState reference.
nrfcxx::sd::TelemetryBeacon::frame_s
Frame content for this beacon.
Definition: beacon.hpp:770
nrfcxx::sd::TelemetryBeacon::power_level
void power_level(power_level_type fn)
Provide a function that can estimate power source level from measured voltage.
Definition: beacon.hpp:893
nrfcxx::sd::TelemetryBeacon::frame_flag_e
frame_flag_e
Bits used in frame_prefix_s::flags to refine content of the frame.
Definition: beacon.hpp:717
nrfcxx::sd::TelemetryBeacon::frame_s::prefix
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:773
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_DIFF_PRESSURE
Flag indicating that the frame contains a differential pressure measurement.
Definition: beacon.hpp:1053
nrfcxx::sd::Beacon::validate
int validate() const
Test whether the beacon is in a valid state.
nrfcxx::sd::Beacon::dt_flags
uint8_t dt_flags() const
Get the GAP ASD Flags data type value to use in the beacon.
Definition: beacon.hpp:397
nrfcxx::sd::Beacon::set_tx_notify
void set_tx_notify(notifier_type notify)
Configure notification that a beacon is being sent.
Definition: beacon.hpp:391
nrfcxx::sd::TelemetryBeacon::FT_FLAG_PWR_IS_Vdd
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
nrfcxx::sd::Beacon::FRAME_TYPE_TEST
static constexpr uint8_t FRAME_TYPE_TEST
Frame type reserved for test applications.
Definition: beacon.hpp:246
nrfcxx::sd::Beacon::FAILED
Indicates that an attempt to transmit the beacon failed.
Definition: beacon.hpp:116
clock.hpp
Core clock-related functionality.
nrfcxx::sd::TelemetryBeacon::FT_FLAG_HAS_RESET_COUNT
Set to indicate that the field formerly used for wfe_cnt carries reset_count instead.
Definition: beacon.hpp:763
nrfcxx::sd::Beacon::INVALID
Indicates that the beacon is unusable.
Definition: beacon.hpp:109
nrfcxx::sd::Beacon::SCHEDULED_PREPARE
Indicates that the beacon is scheduled for a pre-transmission notification.
Definition: beacon.hpp:137
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_LIGHT_INTENSITY
Flag indicating that the frame contains a relative light intensity measurement that's proportional to...
Definition: beacon.hpp:1084
nrfcxx::FailSafeCode::API_VIOLATION
Application tried something that isn't allowed.
nrfcxx::sd::ApplicationIdBeacon::frame_s::heap_KiBy
uint8_t heap_KiBy
Total reserved heap space, in kilobytes.
Definition: beacon.hpp:1280
nrfcxx::clock::uptime
Support for a persistent system clock with 32 KiHz resolution.
Definition: clock.hpp:243
nrfcxx::sd::Beacon::pre_activate_
virtual int pre_activate_()
Called by activate() to make sure everything needed for activation is present.
Definition: beacon.hpp:511
nrfcxx::sd::Beacon::READY
Indicates the beacon should transmit as soon as the radio is available.
Definition: beacon.hpp:154
nrfcxx::sd::Beacon::telemetry_state_type::aggr_sec_cnt
uint32_t aggr_sec_cnt() const
Total uptime since reset, in deciseconds.
Definition: beacon.hpp:212
nrfcxx::sd::EnvSensorBeacon::threshold_s::diff_cPa
uint16_t diff_cPa
Threshold for FT_FLAG_DIFF_PRESSURE.
Definition: beacon.hpp:1124
nrfcxx::sd::Beacon::APP_FRAME_TYPE_BASE
static constexpr uint8_t APP_FRAME_TYPE_BASE
Minimum value for frame_prefix_s::frame_type available for application beacons.
Definition: beacon.hpp:236
nrfcxx::sd::Beacon::telemetry_state_type::aggr_adv_cnt
uint32_t aggr_adv_cnt() const
Total number of advertisements sent since installation.
Definition: beacon.hpp:195
nrfcxx::sd::Beacon::telemetry_state_setup
static void telemetry_state_setup(const systemState::state_type &ss, bool is_reset, bool retained)
Function to maintain beacon telemetry state across resets.
nrfcxx::sd::Beacon::APP_FRAME_TYPE_LIMIT
static constexpr uint8_t APP_FRAME_TYPE_LIMIT
Maximum value for frame_prefix_s::frame_type available for application beacons.
Definition: beacon.hpp:243
nrfcxx::sd::GenericBeacon::frame_s::prefix
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:655
nrfcxx::sd::Beacon::telemetry_state_type::previous_adv
unsigned int previous_adv
Aggregate number of advertisements sent over all previous sessions.
Definition: beacon.hpp:179
nrfcxx::sd::SystemStateBeacon::FRAME_TYPE
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:922
nrfcxx::sd::ApplicationIdBeacon
Beacon providing application identification information.
Definition: beacon.hpp:1239
nrfcxx::sd::TelemetryBeacon::FRAME_TYPE
static constexpr uint8_t FRAME_TYPE
frame_prefix_s::frame_type value for this beacon.
Definition: beacon.hpp:704
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_TEMPERATURE
Flag indicating that the frame contains a temperature measurement.
Definition: beacon.hpp:1016
nrfcxx::sd::Beacon::max_interval_utt
unsigned int max_interval_utt() const
Maximum interval between transmissions, in uptime ticks.
Definition: beacon.hpp:312
nrfcxx::sd::Beacon::process_event
static int process_event()
Method to be invoked by main loop when a beacon-related event occurs.
nrfcxx::sd::ApplicationIdBeacon::frame_s::prefix
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:1249
nrfcxx::sd::EnvSensorBeacon
Beacon providing information derived from environmental sensors.
Definition: beacon.hpp:970
nrfcxx::sd::ApplicationIdBeacon::prepare
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.
nrfcxx::sd::Beacon::frame_prefix_s::frame_type
uint8_t frame_type
Identifies packet content.
Definition: beacon.hpp:260
nrfcxx::sd::GenericBeacon::frame_s
Frame content for this beacon is the first #content_span octets of a #content_type instance.
Definition: beacon.hpp:650
nrfcxx::sd::Beacon::reset_interval
int reset_interval()
Reset the interval so the beacon is retransmitted as quickly as possible.
nrfcxx::sd::Beacon::prepare_backoff_utt
unsigned int prepare_backoff_utt() const
Duration before beacon transmission that a pre-transmission notification will occur,...
Definition: beacon.hpp:320
nrfcxx::sd::SystemStateBeacon::SystemStateBeacon
SystemStateBeacon(const systemState &system_state)
Constructor for beacon requires a systemState reference.
nrfcxx::sd::EnvSensorBeacon::threshold_s::eCO2_ppm
uint16_t eCO2_ppm
Threshold for FT_FLAG_IAQ_ECO2.
Definition: beacon.hpp:1127
nrfcxx::sd::SystemStateBeacon::frame_s::heap_use
uint8_t heap_use
Heap use relative to reserved heap memory.
Definition: beacon.hpp:941
nrfcxx::sd::SystemStateBeacon::frame_s::prefix
frame_prefix_s prefix
Common prefix for all infrastructure beacons.
Definition: beacon.hpp:928
nrfcxx::sd::TelemetryBeacon::system_state
const systemState & system_state
The systemState instance from which information is taken.
Definition: beacon.hpp:848
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_HUMIDITY
Flag indicating that the frame contains a relative humidity measurement.
Definition: beacon.hpp:1029
nrfcxx::sd::Beacon::telemetry_state_type::total_uptime
uint64_t total_uptime
Aggregate uptime from all previous sessions.
Definition: beacon.hpp:173
nrfcxx::sd::ApplicationIdBeacon::frame_s::sd_fwid
uint16_t sd_fwid
Soft-device firmware identifier.
Definition: beacon.hpp:1260
nrfcxx::sd::Beacon::deactivate
int deactivate()
Disable the beacon.
nrfcxx::sd::EnvSensorBeacon::instance
const instance_s & instance() const
Get a reference to the built-up content.
Definition: beacon.hpp:1168
nrfcxx::sd::EnvSensorBeacon::instance_s
Generic frame data holder.
Definition: beacon.hpp:1094
nrfcxx::sd::TelemetryBeacon::TelemetryBeacon
TelemetryBeacon(const systemState &system_state)
Constructor for beacon requires a systemState reference.
nrfcxx::systemState::state_type
The raw data supporting cross-reset state transfer.
Definition: core.hpp:993
nrfcxx::sd::Beacon::telemetry_state
static const telemetry_state_type & telemetry_state()
Access the current telemetry state.
Definition: beacon.hpp:220
nrfcxx::sd::SystemStateBeacon::frame_s::sdfault_id
uint32_t sdfault_id
nrfcxx::systemState::state_type::sdfault_id
Definition: beacon.hpp:932
nrfcxx::sd::EnvSensorBeacon::frame_flag_e
frame_flag_e
Bits used in frame_prefix_s::flags to identify the content of the frame.
Definition: beacon.hpp:1001
nrfcxx::sd::Beacon::interval_utt
unsigned int interval_utt() const
Current interval between transmissions, in uptime ticks.
Definition: beacon.hpp:306
nrfcxx::sd::TelemetryBeacon::FT_FLAG_CHARGING
Set to indicate that the battery is being charged.
Definition: beacon.hpp:739
nrfcxx::sd::EnvSensorBeacon::instance_s::buffer
std::array< uint8_t, MAX_MSD_LENGTH > buffer
A buffer used to hold frame content.
Definition: beacon.hpp:1097
nrfcxx::sd::ApplicationIdBeacon::frame_s
Frame content for this beacon.
Definition: beacon.hpp:1246
nrfcxx::sd::ApplicationIdBeacon::frame_s::stack_KiBy
uint8_t stack_KiBy
Total reserved stack space, in kilobytes.
Definition: beacon.hpp:1274
nrfcxx::sd::SystemStateBeacon::frame_s::code
uint32_t code
nrfcxx::systemState::state_type::code
Definition: beacon.hpp:931
nrfcxx::sd::EnvSensorBeacon::FRAME_TYPE
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:974
nrfcxx::sd::TelemetryBeacon
Beacon providing telemetry information.
Definition: beacon.hpp:700
nrfcxx::sd::Beacon::INACTIVE
Indicates the beacon is not scheduled to transmit, but may be activated in the future.
Definition: beacon.hpp:122
nrfcxx::notifier_type
std::function< void()> notifier_type
Type used to hold a notifier.
Definition: core.hpp:514
nrfcxx::sd::Beacon::process_completion
static int process_completion()
Method to be invoked by main loop when the beacon has been transmitted.
nrfcxx::systemState
A class supporting watchdog configuration and cross-reset retention of state.
Definition: core.hpp:853
nrfcxx::sd::Beacon::crc_type
uint16_t crc_type
Natively-supported checksum is CRC-16/DNP.
Definition: beacon.hpp:83
nrfcxx::clock::alarm
Class supporting an alarm with custom callback and repeatability.
Definition: clock.hpp:498
nrfcxx::sd::TelemetryBeacon::FT_FLAG_HAS_POWER_LEVEL
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
nrfcxx::sd::SystemStateBeacon::frame_s::stack_use
uint8_t stack_use
Maximum observed stack use relative to reserved stack memory.
Definition: beacon.hpp:947
nrfcxx::sd::GenericBeacon::ready
bool ready
Set to true when content has been updated.
Definition: beacon.hpp:671
nrfcxx::sd::Beacon::telemetry_state_type::current_adv
unsigned int current_adv
Number of advertisements sent during this session.
Definition: beacon.hpp:182
nrfcxx::sd::Beacon::MAX_MSD_LENGTH
static constexpr size_t MAX_MSD_LENGTH
The maximum length of a Manufacturer Specific Data PDU.
Definition: beacon.hpp:89
nrfcxx::sd::EnvSensorBeacon::threshold_s::eTVOC_ppb
uint16_t eTVOC_ppb
Threshold for FT_FLAG_IAQ_ETVOC.
Definition: beacon.hpp:1130
nrfcxx::sd::TelemetryBeacon::frame_s::radio_n16
uint16_t radio_n16
Relative time spent with radio on since reset.
Definition: beacon.hpp:833
nrfcxx::sd::Beacon::telemetry_state_type
State retained across resets that is used in telemetry beacons.
Definition: beacon.hpp:166
nrfcxx::sd::TelemetryBeacon::frame_s::optional
uint8_t optional[0]
Storage for optional content, presense indicated by the following flags, in this order:
Definition: beacon.hpp:841
nrfcxx::sd::Beacon::tx_count
unsigned int tx_count() const
Return the number of transmissions since activation.
Definition: beacon.hpp:455
nrfcxx::sd::ApplicationIdBeacon::frame_s::app_crc
uint32_t app_crc
The value from application_crc32().
Definition: beacon.hpp:1252
nrfcxx::sd::EnvSensorBeacon::instance_s::span
uint8_t span
The length of the MSD content, including terminating CRC.
Definition: beacon.hpp:1102
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_IAQ_ECO2
Flag indicating that the frame contains an equivalent CO2 air quality measurement.
Definition: beacon.hpp:1063
nrfcxx::sd::Beacon::set_interval
int set_interval(unsigned int utt)
Configure a fixed interval.
Definition: beacon.hpp:333
nrfcxx::sd::GenericBeacon::frame_s::content
uint8_t content[0]
Where the first #content_span octets of content is copied.
Definition: beacon.hpp:658
nrfcxx::sd::TelemetryBeacon::mutate_flags
uint8_t mutate_flags(uint8_t set, uint8_t clear)
Modify the content of frame_prefix_s::flags.
Definition: beacon.hpp:881
nrfcxx::sd::Beacon::frame_prefix_s
Structure providing the prefix for most beacon content.
Definition: beacon.hpp:253
nrfcxx::sd::GenericBeacon::populate_
int populate_(pabigot::ble::gap::adv_data &ad) override
Function that must be overridden to fill in beacon content.
Definition: beacon.hpp:674
nrfcxx::sd::SystemStateBeacon
Beacon providing system state information.
Definition: beacon.hpp:918
nrfcxx::sd::Beacon::dt_tx_power
int8_t dt_tx_power() const
Get the GAP ASD Tx Power data type value to use in the beacon.
Definition: beacon.hpp:406
nrfcxx::sd::TelemetryBeacon::frame_s::reset_cnt
uint16_t reset_cnt
Low bits of a low-level ARM event counter.
Definition: beacon.hpp:815
nrfcxx::sd::Beacon::set_prepare_backoff
int set_prepare_backoff(notifier_type notify, unsigned int backoff_utt)
Configure notification that a beacon will transmit soon.
nrfcxx::sd::GenericBeacon
Infrastructure to manage a beacon with a fixed payload.
Definition: beacon.hpp:638
nrfcxx::sd::Beacon::state_e
state_e
Values representing the beacon state.
Definition: beacon.hpp:100
nrfcxx::sd::EnvSensorBeacon::threshold_s::light_1
uint8_t light_1
Threshold for FT_FLAG_LIGHT_INTENSITY.
Definition: beacon.hpp:1133
nrfcxx::sd::Beacon::populate_
virtual int populate_(pabigot::ble::gap::adv_data &ad)
Function that must be overridden to fill in beacon content.
Definition: beacon.hpp:547
nrfcxx::sd::SystemStateBeacon::frame_s::reset_reas
uint16_t reset_reas
nrfcxx::systemState::state_type::reset_reas
Definition: beacon.hpp:934
nrfcxx::sd::ApplicationIdBeacon::FRAME_TYPE
static constexpr uint8_t FRAME_TYPE
Value used for frame_s::frame_type.
Definition: beacon.hpp:1243
nrfcxx::sd::TelemetryBeacon::FT_FLAG_AGGREGATE_UPTIME
Set to indicate that frame_s::adv_cnt and frame_s::sec_cnt are aggregates since installation (or powe...
Definition: beacon.hpp:748
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_IAQ_ETVOC
Flag indicating that the frame contains an equivalent Total Volatile Organic Compound air quality mea...
Definition: beacon.hpp:1073
nrfcxx::sd::Beacon::telemetry_state_type::adv_cnt
uint32_t adv_cnt() const
Number of advertisements sent since reset.
Definition: beacon.hpp:187
nrfcxx::sd::TelemetryBeacon::power_level_type
unsigned int(* power_level_type)(unsigned int)
Function type for calculating power source level from power voltage.
Definition: beacon.hpp:712
nrfcxx::sd::EnvSensorBeacon::FT_FLAG_ABS_PRESSURE
Flag indicating that the frame contains an absolute atmospheric pressure measurement.
Definition: beacon.hpp:1043
nrfcxx
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
nrfcxx::sd::Beacon::frame_prefix_s::flags
uint8_t flags
Flags that provide additional information about the beacon content.
Definition: beacon.hpp:266
nrfcxx::sd::EnvSensorBeacon::threshold_s
Thresholds for detecting significant changes in readings.
Definition: beacon.hpp:1112
nrfcxx::sd::Beacon::min_interval_utt
unsigned int min_interval_utt() const
Minimum interval between transmissions, in uptime ticks.
Definition: beacon.hpp:300
nrfcxx::sd::Beacon::update_crc_
crc_type update_crc_(uint8_t *sp, size_t span)
Function to calculate a checksum and store it after the data.
nrfcxx::sd::Beacon::SCHEDULED
Indicates the beacon is scheduled for a future transmission.
Definition: beacon.hpp:146
nrfcxx::sd::TelemetryBeacon::frame_s::sec_cnt
uint32_t sec_cnt
Time since system system reset or installation.
Definition: beacon.hpp:809
nrfcxx::sd::TelemetryBeacon::frame_s::pwr_mV
uint16_t pwr_mV
Measured system power source voltage in millivolts.
Definition: beacon.hpp:787