Skip to main content

t_offset_ms

Function t_offset_ms 

Source
pub fn t_offset_ms(scan_start_us: u64, preamble_end_us: u64) -> Option<u16>
Expand description

The milliseconds a relay reports from the start of its scan to the end of the WOR preamble, rounded up, TS011-1.0.1 appendix 1.

An end device takes TREF = TLAST + PreambleLength * TSYMB - TOffset, the end of its preamble less the offset, to be when the relay scanned, so the offset has to end where the preamble does. A relay finds that from when the frame finished arriving, less the time its sync word and payload take, which LinkSettings::airtime_us gives with no preamble symbols. Semtech LoRa Basics Modem’s relay does the same. Appendix 1 writes the offset as TEND - TSCAN - TOA(WOR) + 16.25 * TSYMB, a fixed allowance that lands on the end of the preamble for no WOR frame’s actual time on air, so a device would aim symbols early.

§Arguments

  • scan_start_us - when the scan that detected the frame started.
  • preamble_end_us - when the frame’s preamble ended.

§Returns

The offset in milliseconds, or None for a preamble that ended before the scan started or more than the eleven bits a WOR ACK carries after it.

§Examples

use pamoja_lora::LinkSettings;
use pamoja_lorawan::relay::{t_offset_ms, WOR_UPLINK_LEN};

// TS011-1.0.1 appendix 1: an SF10 scan at 87 654 ms, and a preamble ending 891.584 ms
// later.
assert_eq!(t_offset_ms(87_654_000, 88_545_584), Some(892));

// A WOR frame that finished arriving at 88 734 ms at SF10 ended its preamble 264.192 ms
// earlier: 4.25 symbols of sync word and 28 of payload.
let sync_and_payload = LinkSettings::new(10, 125_000).with_preamble(0).airtime_us(WOR_UPLINK_LEN);
assert_eq!(sync_and_payload, 264_192);
assert_eq!(t_offset_ms(87_654_000, 88_734_000 - sync_and_payload), Some(816));