|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
LoRa radio types and driver classes. More...
Classes | |
| struct | cad_info |
| Result of a channel-activity-detection operation. More... | |
| struct | lora_link |
| Complete LoRa link configuration. More... | |
| struct | lora_modulation |
| LoRa modulation parameters. More... | |
| struct | lora_packet_params |
| LoRa packet framing parameters. More... | |
| class | lora_transceiver |
| Abstract base class for LoRa radio transceivers. More... | |
| struct | packet_status |
| Detailed status for the most recent packet. More... | |
| struct | rx_duty_cycle |
| Listen/sleep windows for duty-cycled receive. More... | |
| struct | rx_info |
| Information about a received packet. More... | |
| class | sx126x |
| Concrete LoRa radio driver for the Semtech SX126x family. More... | |
Enumerations | |
| enum class | event_id : uint8_t { tx_done , rx_done , crc_error , cad_done , preamble_detected } |
| Event IDs posted by a radio driver. More... | |
| enum class | chip_mode : uint8_t { sleep , stdby , tx , rx , cad } |
| Top-level radio operating mode. More... | |
| enum class | spreading_factor : uint8_t { sf5 = 5 , sf6 = 6 , sf7 = 7 , sf8 = 8 , sf9 = 9 , sf10 = 10 , sf11 = 11 , sf12 = 12 } |
| LoRa spreading factor. More... | |
| enum class | bandwidth : uint8_t { bw_7_8 , bw_10_4 , bw_15_6 , bw_20_8 , bw_31_25 , bw_41_7 , bw_62_5 , bw_125 , bw_250 , bw_500 } |
| LoRa channel bandwidth. More... | |
| enum class | coding_rate : uint8_t { cr_4_5 = 5 , cr_4_6 = 6 , cr_4_7 = 7 , cr_4_8 = 8 } |
| LoRa forward-error-correction coding rate. More... | |
| enum class | lora_network : uint8_t { private_network , public_network } |
| LoRa network selection. More... | |
| enum class | header_type : uint8_t { variable , fixed } |
| LoRa packet header mode. More... | |
| enum class | ramp_time : uint8_t { us_10 , us_40 , us_200 , us_800 , us_3400 } |
| Power-amplifier ramp-time bucket. More... | |
| enum class | sx126x_irq_flag : uint16_t { tx_done = 1 << 0 , rx_done = 1 << 1 , preamble_detected = 1 << 2 , sync_word_valid = 1 << 3 , header_valid = 1 << 4 , header_err = 1 << 5 , crc_err = 1 << 6 , cad_done = 1 << 7 , cad_detected = 1 << 8 , timeout = 1 << 9 } |
| SX126x IRQ-register bitfield. More... | |
Functions | |
| constexpr std::chrono::microseconds | time_on_air (const lora_modulation &mod, const lora_packet_params &pkt, size_t payload_length) noexcept |
| Computes the time-on-air of a LoRa packet. | |
| constexpr std::optional< rx_duty_cycle > | rx_duty_cycle_for (const lora_modulation &mod, uint16_t sender_preamble, uint16_t min_symbols=8, std::chrono::microseconds min_sleep=default_min_rx_sleep) noexcept |
| Computes duty-cycle receive windows that cannot miss a packet. | |
| IDFXX_EVENT_DEFINE_BASE (radio_events, event_id) | |
| Event base for all radio events. | |
Variables | |
| constexpr std::chrono::microseconds | default_min_rx_sleep {1016} |
| Default shortest sleep window worth duty-cycling for. | |
| constexpr event< event_id > | tx_done {event_id::tx_done} |
| Transmit-complete event. | |
| constexpr event< event_id, rx_info > | rx_done {event_id::rx_done} |
| Receive-complete event, carrying the packet's rx_info. | |
| constexpr event< event_id > | crc_error {event_id::crc_error} |
| CRC-error event. | |
| constexpr event< event_id, cad_info > | cad_done {event_id::cad_done} |
| Channel-scan-complete event, carrying cad_info. | |
| constexpr event< event_id > | preamble_detected {event_id::preamble_detected} |
| Preamble-detected event. | |
LoRa radio types and driver classes.
|
strong |
LoRa channel bandwidth.
Named by the bandwidth in kHz (with underscores for fractional values, so bw_7_8 is 7.8 kHz). Drivers translate these to chip-specific register values.
| Enumerator | |
|---|---|
| bw_7_8 | 7.8 kHz |
| bw_10_4 | 10.4 kHz |
| bw_15_6 | 15.6 kHz |
| bw_20_8 | 20.8 kHz |
| bw_31_25 | 31.25 kHz |
| bw_41_7 | 41.7 kHz |
| bw_62_5 | 62.5 kHz |
| bw_125 | 125 kHz |
| bw_250 | 250 kHz |
| bw_500 | 500 kHz |
|
strong |
Top-level radio operating mode.
Drivers expose the high-level mode their chip is in. Chip-specific sub-modes (e.g. SX126x's stdby_rc vs stdby_xosc) are internal to each driver.
| Enumerator | |
|---|---|
| sleep | Sleep / low-power state. |
| stdby | Standby (radio off, registers active). |
| tx | Transmitting. |
| rx | Receiving. |
| cad | Channel-activity detection. |
|
strong |
|
strong |
Event IDs posted by a radio driver.
| Enumerator | |
|---|---|
| tx_done | Transmit complete. |
| rx_done | Receive complete (carries rx_info). |
| crc_error | Received packet had a CRC error. |
| cad_done | Channel scan finished (carries cad_info). |
| preamble_detected | Preamble detected during continuous RX. |
Definition at line 24 of file events.hpp.
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
SX126x IRQ-register bitfield.
The chip's IRQ register is 16 bits wide; each bit reflects an underlying chip event (Semtech DS_SX1261-2_V2.2 §13.3, table 13-29 "IRQ Registers"). The driver normally translates these into chip-agnostic events from <idfxx/radio/events> — only reach for this surface when you need direct register-level access. Accessible as sx126x::irq_flag after the class definition.
| Enumerator | |
|---|---|
| tx_done | |
| rx_done | |
| preamble_detected | |
| sync_word_valid | |
| header_valid | |
| header_err | |
| crc_err | |
| cad_done | |
| cad_detected | |
| timeout | |
Definition at line 46 of file sx126x.hpp.
| idfxx::radio::IDFXX_EVENT_DEFINE_BASE | ( | radio_events | , |
| event_id | |||
| ) |
Event base for all radio events.
Subscribe to this base on a concrete driver's event loop:
|
constexprnoexcept |
Computes duty-cycle receive windows that cannot miss a packet.
Chooses listen/sleep windows such that, no matter how a sender's transmission aligns with the cycle, the radio is awake for at least min_symbols of the preamble and can detect the packet:
sleep = Tsym · (sender_preamble − 2·min_symbols)
rx = max( (Tsym·(sender_preamble + 1) − (sleep − 1 ms)) / 2,
Tsym·(min_symbols + 1) )
where Tsym = 2^SF / BW is the symbol duration. This is the algorithm RadioLib's startReceiveDutyCycleAuto uses. The sleep window is rounded down and the listen window up, so rounding only ever increases the time spent listening.
Returns std::nullopt when duty-cycling cannot work for the given parameters — when the preamble is too short to sleep inside (2·min_symbols ≥ sender_preamble) or the resulting sleep window is shorter than min_sleep. The caller should then use continuous receive; passing the result straight to lora_transceiver::start_listening does exactly that.
| mod | Modulation parameters (spreading factor and bandwidth are used). |
| sender_preamble | Preamble length, in symbols, that senders on this link use (lora_packet_params::preamble_length). |
| min_symbols | Minimum preamble symbols the radio must observe to detect a packet; must be at least 1. Increase for margin at the cost of longer listen windows. |
| min_sleep | Shortest sleep window worth duty-cycling for. Below this the radio spends the window transitioning in and out of sleep instead of saving power; add the oscillator start-up time (e.g. the TCXO delay on SX126x) when the chip uses one. |
std::nullopt if duty-cycling cannot reliably catch packets and continuous receive should be used.Definition at line 80 of file duty_cycle.hpp.
Referenced by idfxx::radio::lora_transceiver::rx_duty_cycle_for().
|
constexprnoexcept |
Computes the time-on-air of a LoRa packet.
Returns how long the radio occupies the channel transmitting (or receiving) a packet of payload_length bytes under the given modulation and framing, using the classic Semtech air-time equation:
Ts = 2^SF / BW
nPayload = 8 + max(ceil((8·PL − 4·SF + 28 + 16·CRC − 20·IH)
/ (4·(SF − 2·DE))) · (CR + 4), 0)
T = (preamble_length + 4.25)·Ts + nPayload·Ts
where DE is mod.low_data_rate_optimize, IH is set for a fixed (implicit) header, CRC follows pkt.crc_on, and CR is the coding-rate index. The result is rounded to the nearest microsecond. The computation is exact integer arithmetic, so it is usable in static_assert.
| mod | Modulation parameters (spreading factor, bandwidth, coding rate, low-data-rate optimization). |
| pkt | Packet framing (preamble length, header type, CRC). pkt.payload_length is ignored — payload_length is the byte count used. |
| payload_length | Number of payload bytes the packet carries. |
Definition at line 135 of file airtime.hpp.
Referenced by idfxx::radio::lora_transceiver::time_on_air().
Channel-scan-complete event, carrying cad_info.
Definition at line 64 of file events.hpp.
CRC-error event.
Definition at line 61 of file events.hpp.
|
inlineconstexpr |
Default shortest sleep window worth duty-cycling for.
Below this the radio spends the window transitioning in and out of sleep instead of saving power; chips that restart an oscillator on each wake add that start-up time (e.g. the TCXO delay on SX126x).
Definition at line 32 of file duty_cycle.hpp.
Referenced by idfxx::radio::lora_transceiver::do_rx_duty_cycle_min_sleep().
|
inlineconstexpr |
Preamble-detected event.
Definition at line 67 of file events.hpp.
Receive-complete event, carrying the packet's rx_info.
The payload describes the packet that raised the event, which suits metadata-only listeners (e.g. signal monitoring). To read the packet's bytes, call lora_transceiver::read_received and pair the bytes with the rx_info it returns — the receive cache holds only the most recent packet, which may already be newer than the one that raised this event.
Definition at line 58 of file events.hpp.
Transmit-complete event.
Definition at line 47 of file events.hpp.