idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::radio::lora_transceiver Class Referenceabstract

Abstract base class for LoRa radio transceivers. More...

Inheritance diagram for idfxx::radio::lora_transceiver:
idfxx::radio::sx126x

Public Member Functions

virtual ~lora_transceiver ()=default
 
 lora_transceiver (const lora_transceiver &)=delete
 
lora_transceiveroperator= (const lora_transceiver &)=delete
 
chip_mode current_mode () const noexcept
 Returns the radio's current high-level mode.
 
lora_modulation modulation () const noexcept
 Returns the configured LoRa modulation parameters.
 
lora_packet_params packet_params () const noexcept
 Returns the configured LoRa packet framing parameters.
 
std::chrono::microseconds time_on_air (size_t payload_length) const noexcept
 Computes the time-on-air of a packet under the configured link parameters.
 
std::optional< rx_duty_cyclerx_duty_cycle_for (uint16_t min_symbols=8) const noexcept
 Computes duty-cycle receive windows for the configured link parameters.
 
void standby ()
 Puts the radio in standby mode.
 
void sleep ()
 Puts the radio in its lowest-power sleep mode.
 
void start_listening ()
 Starts continuous-receive mode.
 
void start_listening (std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period)
 Starts duty-cycled (periodic) receive for low-power listening.
 
void start_listening (rx_duty_cycle cycle)
 Starts duty-cycled (periodic) receive from precomputed windows.
 
void start_listening (const std::optional< rx_duty_cycle > &cycle)
 Starts duty-cycled receive, falling back to continuous receive.
 
idfxx::future< cad_infostart_channel_scan ()
 Starts a one-shot channel-activity scan and returns a future.
 
cad_info scan_channel ()
 Scans the channel for LoRa activity, blocking until the result is known.
 
bool channel_busy ()
 Returns whether LoRa activity is currently detected on the channel.
 
result< void > try_standby ()
 Puts the radio in standby mode.
 
result< void > try_sleep ()
 Puts the radio in its lowest-power sleep mode.
 
result< void > try_start_listening ()
 Starts continuous-receive mode.
 
result< void > try_start_listening (std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period)
 Starts duty-cycled (periodic) receive for low-power listening.
 
result< void > try_start_listening (rx_duty_cycle cycle)
 Starts duty-cycled (periodic) receive from precomputed windows.
 
result< void > try_start_listening (const std::optional< rx_duty_cycle > &cycle)
 Starts duty-cycled receive, falling back to continuous receive.
 
result< idfxx::future< cad_info > > try_start_channel_scan ()
 Starts a one-shot channel-activity scan and returns a future.
 
result< cad_infotry_scan_channel ()
 Scans the channel for LoRa activity, blocking until the result is known.
 
result< bool > try_channel_busy ()
 Returns whether LoRa activity is currently detected on the channel.
 
void configure (const lora_link &link)
 Applies a complete link configuration.
 
void set_frequency (freq::hertz hz)
 Sets the RF carrier frequency.
 
void set_output_power (electro::dbm power, ramp_time ramp=ramp_time::us_200)
 Sets the transmit output power.
 
void set_modulation (lora_modulation mod)
 Configures the LoRa modulation parameters.
 
void set_packet_params (lora_packet_params params)
 Configures the LoRa packet framing.
 
void set_sync_word (lora_network network)
 Selects the LoRa network by setting the sync word.
 
result< void > try_configure (const lora_link &link)
 Applies a complete link configuration.
 
result< void > try_set_frequency (freq::hertz hz)
 Sets the RF carrier frequency.
 
result< void > try_set_output_power (electro::dbm power, ramp_time ramp=ramp_time::us_200)
 Sets the transmit output power.
 
result< void > try_set_modulation (lora_modulation mod)
 Configures the LoRa modulation parameters.
 
result< void > try_set_packet_params (lora_packet_params params)
 Configures the LoRa packet framing.
 
result< void > try_set_sync_word (lora_network network)
 Selects the LoRa network by setting the sync word.
 
void transmit (std::span< const uint8_t > data)
 Transmits a packet and blocks until completion, sizing the timeout automatically.
 
template<typename Rep , typename Period >
void transmit (std::span< const uint8_t > data, const std::chrono::duration< Rep, Period > &timeout)
 Transmits a packet and blocks until completion.
 
template<typename Rep , typename Period >
rx_info receive (std::span< uint8_t > buffer, const std::chrono::duration< Rep, Period > &timeout)
 Receives a single packet, blocking until one arrives or the timeout expires.
 
result< void > try_transmit (std::span< const uint8_t > data)
 Transmits a packet and blocks until completion, sizing the timeout automatically.
 
template<typename Rep , typename Period >
result< void > try_transmit (std::span< const uint8_t > data, const std::chrono::duration< Rep, Period > &timeout)
 Transmits a packet and blocks until completion.
 
template<typename Rep , typename Period >
result< rx_infotry_receive (std::span< uint8_t > buffer, const std::chrono::duration< Rep, Period > &timeout)
 Receives a single packet, blocking until one arrives or the timeout expires.
 
idfxx::future< void > start_transmit (std::span< const uint8_t > data)
 Starts a transmit and returns a future tracking its completion.
 
idfxx::future< rx_infostart_receive (std::span< uint8_t > buffer)
 Starts a single-shot receive into the caller's buffer.
 
rx_info read_received (std::span< uint8_t > buffer)
 Reads the most recently received packet into the caller's buffer.
 
result< idfxx::future< void > > try_start_transmit (std::span< const uint8_t > data)
 Starts a transmit and returns a future tracking its completion.
 
result< idfxx::future< rx_info > > try_start_receive (std::span< uint8_t > buffer)
 Starts a single-shot receive into the caller's buffer.
 
result< rx_infotry_read_received (std::span< uint8_t > buffer)
 Reads the most recently received packet into the caller's buffer.
 
packet_status last_packet_status ()
 Returns detailed status for the most recent packet.
 
electro::centi_dbm current_rssi ()
 Returns the instantaneous RSSI on the configured channel.
 
result< packet_statustry_last_packet_status ()
 Returns detailed status for the most recent packet.
 
result< electro::centi_dbm > try_current_rssi ()
 Returns the instantaneous RSSI on the configured channel.
 

Static Public Attributes

static constexpr size_t max_payload_length = 255
 Maximum LoRa payload length in bytes.
 
static constexpr std::chrono::milliseconds transmit_timeout_margin {250}
 Margin added to the packet's time-on-air when the blocking transmit overload without a timeout sizes its own wait: covers command staging, PA ramp-up, and scheduling latency on top of the pure air-time.
 
static constexpr std::chrono::milliseconds scan_guard_window {1000}
 Guard window for the blocking scan_channel.
 

Protected Member Functions

 lora_transceiver ()=default
 
 lora_transceiver (lora_transceiver &&) noexcept=default
 
lora_transceiveroperator= (lora_transceiver &&) noexcept=default
 
virtual chip_mode do_current_mode () const noexcept=0
 Hook for current_mode.
 
virtual result< void > do_standby ()=0
 Hook for try_standby.
 
virtual result< void > do_sleep ()=0
 Hook for try_sleep.
 
virtual result< void > do_start_listening ()=0
 Hook for try_start_listening() (continuous receive).
 
virtual result< void > do_start_listening (std::chrono::microseconds rx_period, std::chrono::microseconds sleep_period)
 Hook for try_start_listening(std::chrono::microseconds, std::chrono::microseconds) (duty-cycled receive).
 
virtual result< idfxx::future< cad_info > > do_start_channel_scan ()=0
 Hook for try_start_channel_scan.
 
virtual result< void > do_set_frequency (freq::hertz hz)=0
 Hook for try_set_frequency.
 
virtual result< void > do_set_output_power (electro::dbm power, ramp_time ramp)=0
 Hook for try_set_output_power.
 
virtual result< void > do_set_modulation (lora_modulation mod)=0
 Hook for try_set_modulation.
 
virtual result< void > do_set_packet_params (lora_packet_params params)=0
 Hook for try_set_packet_params.
 
virtual result< void > do_set_sync_word (lora_network network)=0
 Hook for try_set_sync_word.
 
virtual result< idfxx::future< void > > do_start_transmit (std::span< const uint8_t > data)=0
 Hook for try_start_transmit.
 
virtual result< idfxx::future< rx_info > > do_start_receive (std::span< uint8_t > buffer)=0
 Hook for try_start_receive(std::span<uint8_t>) (single-shot receive).
 
virtual result< rx_infodo_read_received (std::span< uint8_t > buffer)=0
 Hook for try_read_received.
 
virtual result< packet_statusdo_last_packet_status ()=0
 Hook for try_last_packet_status.
 
virtual result< electro::centi_dbm > do_current_rssi ()=0
 Hook for try_current_rssi.
 
virtual std::chrono::microseconds do_rx_duty_cycle_min_sleep () const noexcept
 Hook for rx_duty_cycle_for: the shortest sleep window worth duty-cycling for on this chip.
 

Detailed Description

Abstract base class for LoRa radio transceivers.

The public interface is non-virtual; concrete drivers (e.g. idfxx::radio::sx126x) customize behaviour by overriding the protected do_* hooks, mirroring the standard library's non-virtual-interface pattern (cf. std::pmr::memory_resource).

Three coordinated styles are exposed: blocking calls (transmit/receive/ scan_channel), future-based one-shot operations (start_transmit, single-shot start_receive(buffer), and start_channel_scan, each returning an idfxx::future), and event-loop dispatch for packet streams (continuous and duty-cycled start_listening, surfacing packets via the typed events declared in <idfxx/radio/events>; pair them with read_received). Futures and events coexist: one-shot operations also post their completion event when an event loop is configured.

Definition at line 61 of file lora_transceiver.hpp.

Constructor & Destructor Documentation

◆ ~lora_transceiver()

virtual idfxx::radio::lora_transceiver::~lora_transceiver ( )
virtualdefault

◆ lora_transceiver() [1/3]

idfxx::radio::lora_transceiver::lora_transceiver ( const lora_transceiver )
delete

◆ lora_transceiver() [2/3]

idfxx::radio::lora_transceiver::lora_transceiver ( )
protecteddefault

◆ lora_transceiver() [3/3]

idfxx::radio::lora_transceiver::lora_transceiver ( lora_transceiver &&  )
protecteddefaultnoexcept

Member Function Documentation

◆ channel_busy()

bool idfxx::radio::lora_transceiver::channel_busy ( )
inline

Returns whether LoRa activity is currently detected on the channel.

Convenience over scan_channel for listen-before-talk: scan, then transmit only if the channel is clear.

Returns
true if LoRa activity was detected on the channel.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::timeout if the scan does not complete within scan_guard_window.
if (radio.channel_busy()) {
// defer the transmission
}

Definition at line 294 of file lora_transceiver.hpp.

References try_channel_busy(), and idfxx::unwrap().

◆ configure()

void idfxx::radio::lora_transceiver::configure ( const lora_link link)
inline

Applies a complete link configuration.

Sets the frequency, output power, modulation, packet framing, and network (sync word) in one call — equivalent to calling the individual setters in sequence. Both ends of a link must agree on every field except the output power.

Parameters
linkLink configuration; link.frequency is required.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::invalid_arg if link.frequency is unset (zero).
radio.configure({
.frequency = 915_MHz,
.output_power = 14_dBm,
.modulation = {.sf = idfxx::radio::spreading_factor::sf9},
});

Definition at line 452 of file lora_transceiver.hpp.

References try_configure(), and idfxx::unwrap().

◆ current_mode()

chip_mode idfxx::radio::lora_transceiver::current_mode ( ) const
inlinenoexcept

Returns the radio's current high-level mode.

Returns
The current chip_mode.

Definition at line 77 of file lora_transceiver.hpp.

References do_current_mode().

◆ current_rssi()

electro::centi_dbm idfxx::radio::lora_transceiver::current_rssi ( )
inline

Returns the instantaneous RSSI on the configured channel.

Returns
The RSSI.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 862 of file lora_transceiver.hpp.

References try_current_rssi(), and idfxx::unwrap().

◆ do_current_mode()

virtual chip_mode idfxx::radio::lora_transceiver::do_current_mode ( ) const
protectedpure virtualnoexcept

Hook for current_mode.

Referenced by current_mode().

◆ do_current_rssi()

virtual result< electro::centi_dbm > idfxx::radio::lora_transceiver::do_current_rssi ( )
protectedpure virtual

Hook for try_current_rssi.

Referenced by try_current_rssi().

◆ do_last_packet_status()

virtual result< packet_status > idfxx::radio::lora_transceiver::do_last_packet_status ( )
protectedpure virtual

◆ do_read_received()

virtual result< rx_info > idfxx::radio::lora_transceiver::do_read_received ( std::span< uint8_t >  buffer)
protectedpure virtual

Hook for try_read_received.

Referenced by try_read_received().

◆ do_rx_duty_cycle_min_sleep()

virtual std::chrono::microseconds idfxx::radio::lora_transceiver::do_rx_duty_cycle_min_sleep ( ) const
inlineprotectedvirtualnoexcept

Hook for rx_duty_cycle_for: the shortest sleep window worth duty-cycling for on this chip.

Drivers add any per-wake oscillator start-up cost to the generic default (e.g. the SX126x adds its configured TCXO start-up delay).

Definition at line 967 of file lora_transceiver.hpp.

References idfxx::radio::default_min_rx_sleep.

Referenced by rx_duty_cycle_for().

◆ do_set_frequency()

virtual result< void > idfxx::radio::lora_transceiver::do_set_frequency ( freq::hertz  hz)
protectedpure virtual

Hook for try_set_frequency.

Referenced by try_set_frequency().

◆ do_set_modulation()

virtual result< void > idfxx::radio::lora_transceiver::do_set_modulation ( lora_modulation  mod)
protectedpure virtual

Hook for try_set_modulation.

Referenced by try_set_modulation().

◆ do_set_output_power()

virtual result< void > idfxx::radio::lora_transceiver::do_set_output_power ( electro::dbm  power,
ramp_time  ramp 
)
protectedpure virtual

Hook for try_set_output_power.

Referenced by try_set_output_power().

◆ do_set_packet_params()

virtual result< void > idfxx::radio::lora_transceiver::do_set_packet_params ( lora_packet_params  params)
protectedpure virtual

◆ do_set_sync_word()

virtual result< void > idfxx::radio::lora_transceiver::do_set_sync_word ( lora_network  network)
protectedpure virtual

Hook for try_set_sync_word.

Referenced by try_set_sync_word().

◆ do_sleep()

virtual result< void > idfxx::radio::lora_transceiver::do_sleep ( )
protectedpure virtual

Hook for try_sleep.

Referenced by try_sleep().

◆ do_standby()

virtual result< void > idfxx::radio::lora_transceiver::do_standby ( )
protectedpure virtual

Hook for try_standby.

Referenced by try_standby().

◆ do_start_channel_scan()

virtual result< idfxx::future< cad_info > > idfxx::radio::lora_transceiver::do_start_channel_scan ( )
protectedpure virtual

Hook for try_start_channel_scan.

The returned future must complete with the scan result, or with errc::not_finished if the operation is cancelled (standby, sleep, or driver teardown).

Referenced by try_start_channel_scan().

◆ do_start_listening() [1/2]

virtual result< void > idfxx::radio::lora_transceiver::do_start_listening ( )
protectedpure virtual

Hook for try_start_listening() (continuous receive).

Referenced by try_start_listening(), and try_start_listening().

◆ do_start_listening() [2/2]

virtual result< void > idfxx::radio::lora_transceiver::do_start_listening ( std::chrono::microseconds  rx_period,
std::chrono::microseconds  sleep_period 
)
inlineprotectedvirtual

Hook for try_start_listening(std::chrono::microseconds, std::chrono::microseconds) (duty-cycled receive).

Both durations are positive. Hardware duty-cycled listening is optional: drivers whose chip cannot listen autonomously keep this default, which reports errc::not_supported.

Definition at line 920 of file lora_transceiver.hpp.

References idfxx::error(), and idfxx::not_supported.

◆ do_start_receive()

virtual result< idfxx::future< rx_info > > idfxx::radio::lora_transceiver::do_start_receive ( std::span< uint8_t >  buffer)
protectedpure virtual

Hook for try_start_receive(std::span<uint8_t>) (single-shot receive).

The returned future must complete with the received packet's info (errc::invalid_crc on CRC failure), or with errc::not_finished if the operation is cancelled (standby, sleep, or driver teardown); the buffer must never be written after the future completes.

Referenced by try_start_receive().

◆ do_start_transmit()

virtual result< idfxx::future< void > > idfxx::radio::lora_transceiver::do_start_transmit ( std::span< const uint8_t >  data)
protectedpure virtual

Hook for try_start_transmit.

The payload is non-empty and at most max_payload_length bytes, and is staged before the hook returns (the caller's buffer need not outlive the call). The returned future must complete when the packet has been sent, or with errc::not_finished if the operation is cancelled (standby, sleep, or driver teardown).

Referenced by try_start_transmit().

◆ last_packet_status()

packet_status idfxx::radio::lora_transceiver::last_packet_status ( )
inline

Returns detailed status for the most recent packet.

Returns
Packet status (RSSI, SNR, signal RSSI).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 854 of file lora_transceiver.hpp.

References try_last_packet_status(), and idfxx::unwrap().

◆ modulation()

lora_modulation idfxx::radio::lora_transceiver::modulation ( ) const
inlinenoexcept

Returns the configured LoRa modulation parameters.

Reflects the most recent successful try_set_modulation / set_modulation, or the defaults (lora_modulation{}) before any call. Used by time_on_air and rx_duty_cycle_for so callers need not keep their own copy of the link configuration.

Returns
The configured modulation parameters.

Definition at line 89 of file lora_transceiver.hpp.

◆ operator=() [1/2]

lora_transceiver & idfxx::radio::lora_transceiver::operator= ( const lora_transceiver )
delete

◆ operator=() [2/2]

lora_transceiver & idfxx::radio::lora_transceiver::operator= ( lora_transceiver &&  )
protecteddefaultnoexcept

◆ packet_params()

lora_packet_params idfxx::radio::lora_transceiver::packet_params ( ) const
inlinenoexcept

Returns the configured LoRa packet framing parameters.

Reflects the most recent successful try_set_packet_params / set_packet_params, or the defaults (lora_packet_params{}) before any call.

Returns
The configured packet framing parameters.

Definition at line 100 of file lora_transceiver.hpp.

◆ read_received()

rx_info idfxx::radio::lora_transceiver::read_received ( std::span< uint8_t >  buffer)
inline

Reads the most recently received packet into the caller's buffer.

Typically called from a rx_done event handler. The radio's internal cache holds only the most recent packet; calling this after a second rx_done returns that newer packet. Always pair the copied bytes with the rx_info this call returns — the rx_done event's payload may describe an older packet than the cache.

Parameters
bufferBuffer to copy the payload into.
Returns
Information about the packet (length, RSSI, SNR).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 774 of file lora_transceiver.hpp.

References try_read_received(), and idfxx::unwrap().

◆ receive()

template<typename Rep , typename Period >
rx_info idfxx::radio::lora_transceiver::receive ( std::span< uint8_t >  buffer,
const std::chrono::duration< Rep, Period > &  timeout 
)
inline

Receives a single packet, blocking until one arrives or the timeout expires.

Parameters
bufferBuffer to receive into.
timeoutMaximum time to wait for a packet.
Returns
Information about the received packet (length, RSSI, SNR).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::timeout and errc::invalid_crc.

Definition at line 632 of file lora_transceiver.hpp.

References idfxx::radio::timeout, try_receive(), and idfxx::unwrap().

◆ rx_duty_cycle_for()

std::optional< rx_duty_cycle > idfxx::radio::lora_transceiver::rx_duty_cycle_for ( uint16_t  min_symbols = 8) const
inlinenoexcept

Computes duty-cycle receive windows for the configured link parameters.

Equivalent to the free function idfxx::radio::rx_duty_cycle_for called with modulation, the configured preamble length (senders on the link are assumed to use the same packet_params), and the driver's minimum worthwhile sleep window — which includes any oscillator start-up cost the chip pays on each wake (e.g. the SX126x TCXO delay).

Returns std::nullopt when duty-cycling cannot reliably catch packets; passing the result straight to start_listening then falls back to continuous receive.

Parameters
min_symbolsMinimum preamble symbols the radio must observe to detect a packet; must be at least 1.
Returns
The listen/sleep windows, or std::nullopt if duty-cycling cannot reliably catch packets.
radio.start_listening(radio.rx_duty_cycle_for());

Definition at line 146 of file lora_transceiver.hpp.

References do_rx_duty_cycle_min_sleep(), idfxx::radio::lora_packet_params::preamble_length, and idfxx::radio::rx_duty_cycle_for().

◆ scan_channel()

cad_info idfxx::radio::lora_transceiver::scan_channel ( )
inline

Scans the channel for LoRa activity, blocking until the result is known.

Runs one channel-activity-detection operation with driver-default detection parameters and blocks until it completes, returning whether activity was detected. Intended for listen-before-talk: scan, then transmit only if the channel is clear.

Returns
The scan result (whether activity was detected).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::timeout if the scan does not complete within scan_guard_window.

Definition at line 275 of file lora_transceiver.hpp.

References try_scan_channel(), and idfxx::unwrap().

◆ set_frequency()

void idfxx::radio::lora_transceiver::set_frequency ( freq::hertz  hz)
inline

Sets the RF carrier frequency.

Parameters
hzCarrier frequency.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 460 of file lora_transceiver.hpp.

References try_set_frequency(), and idfxx::unwrap().

◆ set_modulation()

void idfxx::radio::lora_transceiver::set_modulation ( lora_modulation  mod)
inline

Configures the LoRa modulation parameters.

Parameters
modSpreading factor, bandwidth, coding rate.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 481 of file lora_transceiver.hpp.

References try_set_modulation(), and idfxx::unwrap().

◆ set_output_power()

void idfxx::radio::lora_transceiver::set_output_power ( electro::dbm  power,
ramp_time  ramp = ramp_time::us_200 
)
inline

Sets the transmit output power.

Parameters
powerOutput power. Valid range depends on the chip variant; drivers return errc::invalid_arg for values outside their supported range.
rampOutput-power ramp-up time (driver maps to nearest supported value).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 471 of file lora_transceiver.hpp.

References try_set_output_power(), and idfxx::unwrap().

◆ set_packet_params()

void idfxx::radio::lora_transceiver::set_packet_params ( lora_packet_params  params)
inline

Configures the LoRa packet framing.

Parameters
paramsPreamble, header type, CRC, IQ inversion, etc.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 489 of file lora_transceiver.hpp.

References try_set_packet_params(), and idfxx::unwrap().

◆ set_sync_word()

void idfxx::radio::lora_transceiver::set_sync_word ( lora_network  network)
inline

Selects the LoRa network by setting the sync word.

Senders and receivers must select the same network to hear each other. Each driver maps the selection to its chip's native sync-word encoding; chip-specific raw values remain available through driver-specific overloads (e.g. sx126x::set_sync_word(uint16_t)).

Parameters
networkNetwork whose sync word to use.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 503 of file lora_transceiver.hpp.

References try_set_sync_word(), and idfxx::unwrap().

◆ sleep()

void idfxx::radio::lora_transceiver::sleep ( )
inline

Puts the radio in its lowest-power sleep mode.

Configuration is retained where the chip supports it, so the next operation wakes the radio without a full reconfiguration.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 177 of file lora_transceiver.hpp.

References try_sleep(), and idfxx::unwrap().

◆ standby()

void idfxx::radio::lora_transceiver::standby ( )
inline

Puts the radio in standby mode.

Standby stops any in-progress receive or channel scan and parks the radio with its configuration retained, ready for the next operation.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 166 of file lora_transceiver.hpp.

References try_standby(), and idfxx::unwrap().

◆ start_channel_scan()

idfxx::future< cad_info > idfxx::radio::lora_transceiver::start_channel_scan ( )
inline

Starts a one-shot channel-activity scan and returns a future.

The returned future completes with the scan result (cad_info); when an event loop is configured the result is also posted as a cad_done event. Uses driver-default detection parameters; drivers may expose a chip-specific method to tune those (e.g. sx126x::set_cad_params). For a blocking scan, use scan_channel instead.

Dropping the future without waiting is safe: the scan continues and the result remains observable through the cad_done event.

Returns
A future completing with the scan result.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 260 of file lora_transceiver.hpp.

References try_start_channel_scan(), and idfxx::unwrap().

◆ start_listening() [1/4]

void idfxx::radio::lora_transceiver::start_listening ( )
inline

Starts continuous-receive mode.

The radio runs continuously, posting rx_done (and on errors, crc_error) events as packets arrive. Use read_received to extract the payload from inside the event handler. Call standby to stop receiving.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 190 of file lora_transceiver.hpp.

References try_start_listening(), and idfxx::unwrap().

◆ start_listening() [2/4]

void idfxx::radio::lora_transceiver::start_listening ( const std::optional< rx_duty_cycle > &  cycle)
inline

Starts duty-cycled receive, falling back to continuous receive.

Accepts the result of rx_duty_cycle_for directly: starts duty-cycled receive when cycle holds windows, and continuous receive when it is std::nullopt (duty-cycling could not reliably catch packets for the link's modulation and preamble length).

Parameters
cycleListen/sleep windows, or std::nullopt for continuous receive.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.
radio.start_listening(idfxx::radio::rx_duty_cycle_for(mod, pkt.preamble_length));
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.

Definition at line 241 of file lora_transceiver.hpp.

References try_start_listening(), and idfxx::unwrap().

◆ start_listening() [3/4]

void idfxx::radio::lora_transceiver::start_listening ( rx_duty_cycle  cycle)
inline

Starts duty-cycled (periodic) receive from precomputed windows.

Equivalent to start_listening(cycle.rx_period, cycle.sleep_period). Compute the windows with rx_duty_cycle_for (<idfxx/radio/duty_cycle>) or build them directly.

Parameters
cycleListen/sleep windows for each cycle.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::invalid_arg for a non-positive listen or sleep window.

Definition at line 223 of file lora_transceiver.hpp.

References try_start_listening(), and idfxx::unwrap().

◆ start_listening() [4/4]

void idfxx::radio::lora_transceiver::start_listening ( std::chrono::microseconds  rx_period,
std::chrono::microseconds  sleep_period 
)
inline

Starts duty-cycled (periodic) receive for low-power listening.

The radio alternates between listening for rx_period and sleeping for sleep_period, repeating until a packet arrives or the mode is changed. As with the continuous overload, packets surface through rx_done (and crc_error) events; use read_received to extract the payload.

Parameters
rx_periodTime to listen in each cycle.
sleep_periodTime to sleep in each cycle.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure, including errc::invalid_arg for a non-positive rx_period or sleep_period.

Definition at line 207 of file lora_transceiver.hpp.

References try_start_listening(), and idfxx::unwrap().

◆ start_receive()

idfxx::future< rx_info > idfxx::radio::lora_transceiver::start_receive ( std::span< uint8_t >  buffer)
inline

Starts a single-shot receive into the caller's buffer.

Receives exactly one packet: the radio listens until a packet arrives, copies the payload into buffer (clamped to its size), completes the returned future with the packet's rx_info, and returns to standby. For a packet stream, use the continuous or duty-cycled start_listening overloads instead.

buffer must remain valid until the future completes or the operation is cancelled by a mode change (standby or sleep).

Dropping the future without waiting is safe: the receive continues and the packet remains observable through the rx_done event and read_received.

Parameters
bufferBuffer to receive the payload into.
Returns
A future completing with information about the received packet.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 756 of file lora_transceiver.hpp.

References try_start_receive(), and idfxx::unwrap().

◆ start_transmit()

idfxx::future< void > idfxx::radio::lora_transceiver::start_transmit ( std::span< const uint8_t >  data)
inline

Starts a transmit and returns a future tracking its completion.

The companion to the blocking transmit: the call returns as soon as the packet is staged and transmission has started, so the caller's task is free to do other work and can await the returned future when it needs the result. When an event loop is configured, completion is also posted as a tx_done event.

Only one data-path operation may be in flight at a time; calling this (or any other transmit/receive/scan) again before completion returns errc::invalid_state. There is no built-in transmit timeout — wait on the future with a try_wait_for() sized via time_on_air and call standby to cancel the operation if it never completes.

Dropping the future without waiting is safe: the transmission continues and completion remains observable through the tx_done event.

Parameters
dataPayload to transmit (1–255 bytes). The payload is staged on-chip before this call returns, so the buffer need not outlive the call.
Returns
A future completing when the packet has been sent.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 731 of file lora_transceiver.hpp.

References try_start_transmit(), and idfxx::unwrap().

◆ time_on_air()

std::chrono::microseconds idfxx::radio::lora_transceiver::time_on_air ( size_t  payload_length) const
inlinenoexcept

Computes the time-on-air of a packet under the configured link parameters.

Equivalent to the free function idfxx::radio::time_on_air called with modulation and packet_params, so it always agrees with what the radio was actually configured with.

Parameters
payload_lengthNumber of payload bytes the packet carries.
Returns
The packet's time-on-air.
radio.transmit(payload, radio.time_on_air(payload.size()) + 200ms);

Definition at line 120 of file lora_transceiver.hpp.

References idfxx::radio::time_on_air().

Referenced by try_transmit().

◆ transmit() [1/2]

void idfxx::radio::lora_transceiver::transmit ( std::span< const uint8_t >  data)
inline

Transmits a packet and blocks until completion, sizing the timeout automatically.

Waits at most the packet's time_on_air — computed from the configured link parameters — plus transmit_timeout_margin.

Parameters
dataPayload to transmit (1–255 bytes).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure or timeout.

Definition at line 608 of file lora_transceiver.hpp.

References try_transmit(), and idfxx::unwrap().

◆ transmit() [2/2]

template<typename Rep , typename Period >
void idfxx::radio::lora_transceiver::transmit ( std::span< const uint8_t >  data,
const std::chrono::duration< Rep, Period > &  timeout 
)
inline

Transmits a packet and blocks until completion.

Parameters
dataPayload to transmit (1–255 bytes).
timeoutMaximum time to wait for transmit completion.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure or timeout.

Definition at line 618 of file lora_transceiver.hpp.

References idfxx::radio::timeout, try_transmit(), and idfxx::unwrap().

◆ try_channel_busy()

result< bool > idfxx::radio::lora_transceiver::try_channel_busy ( )
inline

Returns whether LoRa activity is currently detected on the channel.

Convenience over try_scan_channel for listen-before-talk: scan, then transmit only if the channel is clear.

Returns
true if LoRa activity was detected on the channel, or an error.
Return values
timeoutThe scan did not complete within scan_guard_window.
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 418 of file lora_transceiver.hpp.

References idfxx::error(), and try_scan_channel().

Referenced by channel_busy().

◆ try_configure()

result< void > idfxx::radio::lora_transceiver::try_configure ( const lora_link link)
inline

Applies a complete link configuration.

Sets the frequency, output power, modulation, packet framing, and network (sync word) in one call — equivalent to calling the individual setters in sequence, stopping at the first failure. Both ends of a link must agree on every field except the output power.

Parameters
linkLink configuration; link.frequency is required.
Returns
Success, or the first setter's error.
Return values
invalid_arglink.frequency is unset (zero), or a field is outside the driver's supported range.

Definition at line 519 of file lora_transceiver.hpp.

References idfxx::error(), idfxx::radio::lora_link::frequency, idfxx::invalid_arg, idfxx::radio::lora_link::modulation, idfxx::radio::lora_link::network, idfxx::radio::lora_link::output_power, idfxx::radio::lora_link::packet_params, idfxx::radio::lora_link::ramp, try_set_frequency(), try_set_modulation(), try_set_output_power(), try_set_packet_params(), and try_set_sync_word().

Referenced by configure().

◆ try_current_rssi()

result< electro::centi_dbm > idfxx::radio::lora_transceiver::try_current_rssi ( )
inline

Returns the instantaneous RSSI on the configured channel.

Returns
The RSSI, or an error.

Definition at line 875 of file lora_transceiver.hpp.

References do_current_rssi().

Referenced by current_rssi().

◆ try_last_packet_status()

result< packet_status > idfxx::radio::lora_transceiver::try_last_packet_status ( )
inline

Returns detailed status for the most recent packet.

Returns
Packet status, or an error.

Definition at line 869 of file lora_transceiver.hpp.

References do_last_packet_status().

Referenced by last_packet_status().

◆ try_read_received()

result< rx_info > idfxx::radio::lora_transceiver::try_read_received ( std::span< uint8_t >  buffer)
inline

Reads the most recently received packet into the caller's buffer.

Always pair the copied bytes with the rx_info this call returns — the rx_done event's payload may describe an older packet than the cache.

Parameters
bufferBuffer to copy the payload into.
Returns
Information about the packet, or an error.
Return values
not_foundNo packet has been received yet.

Definition at line 841 of file lora_transceiver.hpp.

References do_read_received().

Referenced by read_received().

◆ try_receive()

template<typename Rep , typename Period >
result< rx_info > idfxx::radio::lora_transceiver::try_receive ( std::span< uint8_t >  buffer,
const std::chrono::duration< Rep, Period > &  timeout 
)
inline

Receives a single packet, blocking until one arrives or the timeout expires.

Equivalent to try_start_receive(std::span<uint8_t>) followed by a wait on the returned future. If no packet arrives within timeout the radio is returned to standby and errc::timeout is reported.

Parameters
bufferBuffer to receive into.
timeoutMaximum time to wait for a packet.
Returns
Information about the received packet, or an error.
Return values
timeoutNo packet arrived within the timeout.
invalid_crcThe received packet failed its CRC check.
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 693 of file lora_transceiver.hpp.

References idfxx::error(), idfxx::radio::timeout, and try_start_receive().

Referenced by receive().

◆ try_scan_channel()

result< cad_info > idfxx::radio::lora_transceiver::try_scan_channel ( )
inline

Scans the channel for LoRa activity, blocking until the result is known.

Equivalent to try_start_channel_scan followed by a wait on the returned future. If the scan does not complete within scan_guard_window the radio is returned to standby and errc::timeout is reported.

Returns
The scan result, or an error.
Return values
timeoutThe scan did not complete within scan_guard_window.
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 400 of file lora_transceiver.hpp.

References idfxx::error(), scan_guard_window, and try_start_channel_scan().

Referenced by scan_channel(), and try_channel_busy().

◆ try_set_frequency()

result< void > idfxx::radio::lora_transceiver::try_set_frequency ( freq::hertz  hz)
inline

Sets the RF carrier frequency.

Parameters
hzCarrier frequency.
Returns
Success, or an error.

Definition at line 543 of file lora_transceiver.hpp.

References do_set_frequency().

Referenced by set_frequency(), and try_configure().

◆ try_set_modulation()

result< void > idfxx::radio::lora_transceiver::try_set_modulation ( lora_modulation  mod)
inline

Configures the LoRa modulation parameters.

Parameters
modSpreading factor, bandwidth, coding rate.
Returns
Success, or an error.

Definition at line 561 of file lora_transceiver.hpp.

References do_set_modulation().

Referenced by set_modulation(), and try_configure().

◆ try_set_output_power()

result< void > idfxx::radio::lora_transceiver::try_set_output_power ( electro::dbm  power,
ramp_time  ramp = ramp_time::us_200 
)
inline

Sets the transmit output power.

Parameters
powerOutput power.
rampOutput-power ramp-up time.
Returns
Success, or an error.
Return values
invalid_argThe requested power is outside the chip variant's supported range.

Definition at line 552 of file lora_transceiver.hpp.

References do_set_output_power().

Referenced by set_output_power(), and try_configure().

◆ try_set_packet_params()

result< void > idfxx::radio::lora_transceiver::try_set_packet_params ( lora_packet_params  params)
inline

Configures the LoRa packet framing.

Parameters
paramsPreamble, header type, CRC, IQ inversion, etc.
Returns
Success, or an error.

Definition at line 574 of file lora_transceiver.hpp.

References do_set_packet_params().

Referenced by set_packet_params(), and try_configure().

◆ try_set_sync_word()

result< void > idfxx::radio::lora_transceiver::try_set_sync_word ( lora_network  network)
inline

Selects the LoRa network by setting the sync word.

Senders and receivers must select the same network to hear each other. Each driver maps the selection to its chip's native sync-word encoding.

Parameters
networkNetwork whose sync word to use.
Returns
Success, or an error.

Definition at line 591 of file lora_transceiver.hpp.

References do_set_sync_word().

Referenced by set_sync_word(), and try_configure().

◆ try_sleep()

result< void > idfxx::radio::lora_transceiver::try_sleep ( )
inline

Puts the radio in its lowest-power sleep mode.

Configuration is retained where the chip supports it, so the next operation wakes the radio without a full reconfiguration.

Returns
Success, or an error.

Definition at line 315 of file lora_transceiver.hpp.

References do_sleep().

Referenced by sleep().

◆ try_standby()

result< void > idfxx::radio::lora_transceiver::try_standby ( )
inline

Puts the radio in standby mode.

Standby stops any in-progress receive or channel scan and parks the radio with its configuration retained, ready for the next operation.

Returns
Success, or an error.

Definition at line 305 of file lora_transceiver.hpp.

References do_standby().

Referenced by standby().

◆ try_start_channel_scan()

result< idfxx::future< cad_info > > idfxx::radio::lora_transceiver::try_start_channel_scan ( )
inline

Starts a one-shot channel-activity scan and returns a future.

The returned future completes with the scan result (cad_info); when an event loop is configured the result is also posted as a cad_done event. The future completes with errc::not_finished if the scan is cancelled by a mode change (try_standby or try_sleep).

Dropping the future without waiting is safe: the scan continues and the result remains observable through the cad_done event.

Returns
A future completing with the scan result, or an error.
Return values
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 386 of file lora_transceiver.hpp.

References do_start_channel_scan().

Referenced by start_channel_scan(), and try_scan_channel().

◆ try_start_listening() [1/4]

result< void > idfxx::radio::lora_transceiver::try_start_listening ( )
inline

Starts continuous-receive mode.

Packets surface through rx_done (and crc_error) events; use try_read_received to extract the payload. Call try_standby to stop receiving.

Returns
Success, or an error.

Definition at line 326 of file lora_transceiver.hpp.

References do_start_listening().

Referenced by start_listening(), start_listening(), start_listening(), start_listening(), try_start_listening(), and try_start_listening().

◆ try_start_listening() [2/4]

result< void > idfxx::radio::lora_transceiver::try_start_listening ( const std::optional< rx_duty_cycle > &  cycle)
inline

Starts duty-cycled receive, falling back to continuous receive.

Accepts the result of rx_duty_cycle_for directly: starts duty-cycled receive when cycle holds windows, and continuous receive when it is std::nullopt.

Parameters
cycleListen/sleep windows, or std::nullopt for continuous receive.
Returns
Success, or an error.

Definition at line 368 of file lora_transceiver.hpp.

References try_start_listening().

◆ try_start_listening() [3/4]

result< void > idfxx::radio::lora_transceiver::try_start_listening ( rx_duty_cycle  cycle)
inline

Starts duty-cycled (periodic) receive from precomputed windows.

Equivalent to try_start_listening(cycle.rx_period, cycle.sleep_period).

Parameters
cycleListen/sleep windows for each cycle.
Returns
Success, or an error.
Return values
invalid_argThe listen or sleep window is not positive.
not_supportedThe driver has no hardware duty-cycled listening.

Definition at line 354 of file lora_transceiver.hpp.

References idfxx::radio::rx_duty_cycle::rx_period, idfxx::radio::rx_duty_cycle::sleep_period, and try_start_listening().

◆ try_start_listening() [4/4]

result< void > idfxx::radio::lora_transceiver::try_start_listening ( std::chrono::microseconds  rx_period,
std::chrono::microseconds  sleep_period 
)
inline

Starts duty-cycled (periodic) receive for low-power listening.

Parameters
rx_periodTime to listen in each cycle.
sleep_periodTime to sleep in each cycle.
Returns
Success, or an error.
Return values
invalid_argrx_period or sleep_period is not positive.
not_supportedThe driver has no hardware duty-cycled listening.

Definition at line 337 of file lora_transceiver.hpp.

References do_start_listening(), idfxx::error(), and idfxx::invalid_arg.

◆ try_start_receive()

result< idfxx::future< rx_info > > idfxx::radio::lora_transceiver::try_start_receive ( std::span< uint8_t >  buffer)
inline

Starts a single-shot receive into the caller's buffer.

Receives exactly one packet: the radio listens until a packet arrives, copies the payload into buffer (clamped to its size), completes the returned future with the packet's rx_info, and returns to standby. The future completes with errc::invalid_crc if the packet failed its CRC check, and with errc::not_finished if the operation is cancelled by a mode change (try_standby or try_sleep).

buffer must remain valid until the future completes or the operation is cancelled.

Dropping the future without waiting is safe: the receive continues and the packet remains observable through the rx_done event and try_read_received.

Parameters
bufferBuffer to receive the payload into.
Returns
A future completing with information about the received packet, or an error.
Return values
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 826 of file lora_transceiver.hpp.

References do_start_receive().

Referenced by start_receive(), and try_receive().

◆ try_start_transmit()

result< idfxx::future< void > > idfxx::radio::lora_transceiver::try_start_transmit ( std::span< const uint8_t >  data)
inline

Starts a transmit and returns a future tracking its completion.

The call returns as soon as the packet is staged and transmission has started; the returned future completes when the packet has been sent (or with errc::not_finished if the operation is cancelled by a mode change). When an event loop is configured, completion is also posted as a tx_done event. Only one data-path operation may be in flight at a time.

Dropping the future without waiting is safe: the transmission continues and completion remains observable through the tx_done event.

Parameters
dataPayload to transmit (1–255 bytes). The payload is staged on-chip before this call returns, so the buffer need not outlive the call.
Returns
A future completing when the packet has been sent, or an error.
Return values
invalid_argThe payload is empty or longer than 255 bytes.
invalid_stateAnother transmit, receive, or scan is already in flight.

Definition at line 797 of file lora_transceiver.hpp.

References do_start_transmit(), idfxx::error(), idfxx::invalid_arg, and max_payload_length.

Referenced by start_transmit(), and try_transmit().

◆ try_transmit() [1/2]

result< void > idfxx::radio::lora_transceiver::try_transmit ( std::span< const uint8_t >  data)
inline

Transmits a packet and blocks until completion, sizing the timeout automatically.

Waits at most the packet's time_on_air — computed from the configured link parameters — plus transmit_timeout_margin.

Parameters
dataPayload to transmit (1–255 bytes).
Returns
Success, or an error.
Return values
invalid_argThe payload is empty or longer than 255 bytes.
invalid_stateAnother transmit, receive, or scan is already in flight.
timeoutThe transmit did not complete in time.

Definition at line 649 of file lora_transceiver.hpp.

References time_on_air(), transmit_timeout_margin, and try_transmit().

Referenced by transmit(), transmit(), and try_transmit().

◆ try_transmit() [2/2]

template<typename Rep , typename Period >
result< void > idfxx::radio::lora_transceiver::try_transmit ( std::span< const uint8_t >  data,
const std::chrono::duration< Rep, Period > &  timeout 
)
inline

Transmits a packet and blocks until completion.

Equivalent to try_start_transmit followed by a wait on the returned future. If the transmit does not complete within timeout the radio is returned to standby and errc::timeout is reported.

Parameters
dataPayload to transmit (1–255 bytes).
timeoutMaximum time to wait for transmit completion.
Returns
Success, or an error.
Return values
invalid_argThe payload is empty or longer than 255 bytes.
invalid_stateAnother transmit, receive, or scan is already in flight.
timeoutThe transmit did not complete within the specified duration.

Definition at line 669 of file lora_transceiver.hpp.

References idfxx::error(), idfxx::radio::timeout, and try_start_transmit().

Member Data Documentation

◆ max_payload_length

constexpr size_t idfxx::radio::lora_transceiver::max_payload_length = 255
staticconstexpr

Maximum LoRa payload length in bytes.

Definition at line 878 of file lora_transceiver.hpp.

Referenced by try_start_transmit().

◆ scan_guard_window

constexpr std::chrono::milliseconds idfxx::radio::lora_transceiver::scan_guard_window {1000}
staticconstexpr

Guard window for the blocking scan_channel.

Channel-activity detection completes within a few symbol times even at the slowest modulation, so it takes no caller-supplied timeout; the blocking form waits at most this long before cancelling the scan and reporting errc::timeout.

Definition at line 890 of file lora_transceiver.hpp.

Referenced by try_scan_channel().

◆ transmit_timeout_margin

constexpr std::chrono::milliseconds idfxx::radio::lora_transceiver::transmit_timeout_margin {250}
staticconstexpr

Margin added to the packet's time-on-air when the blocking transmit overload without a timeout sizes its own wait: covers command staging, PA ramp-up, and scheduling latency on top of the pure air-time.

Definition at line 883 of file lora_transceiver.hpp.

Referenced by try_transmit().


The documentation for this class was generated from the following file: