pub struct ForwardedUplink<'a> {
pub metadata: UplinkMetadata,
pub frequency_hz: u32,
pub phy_payload: &'a [u8],
}Expand description
An end device’s uplink as a relay forwards it: the payload of a relay uplink on
LA_FPORT_RELAY.
Fields§
§metadata: UplinkMetadataWhat the relay heard of it.
frequency_hz: u32The frequency it arrived on, in hertz.
phy_payload: &'a [u8]The end device’s frame, as the relay received it.
Implementations§
Source§impl<'a> ForwardedUplink<'a>
impl<'a> ForwardedUplink<'a>
Sourcepub fn encode(&self, out: &mut [u8]) -> Result<usize, LorawanError>
pub fn encode(&self, out: &mut [u8]) -> Result<usize, LorawanError>
Writes the forwarded uplink out.
A strength or ratio past what its field carries goes out as the closest value, as section 9.1 asks.
§Arguments
out- where to write it.
§Returns
How many bytes were written: FORWARD_OVERHEAD and the frame.
§Errors
Returns LorawanError::PayloadTooLong when out is too short, and
LorawanError::MalformedFrame for a data rate past 15 or a frequency the three-byte
field cannot carry.
§Examples
use pamoja_lorawan::relay::{ForwardedUplink, UplinkMetadata, WorChannel};
use pamoja_lorawan::{Session, Uplink};
// A sensor's reading, which the relay heard and carries on without reading it.
let sensor = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
let frame = sensor.encode_uplink(&Uplink::new(7, 2, b"21.5"))?;
// What the relay adds: where and how well it heard the frame.
let forwarded = ForwardedUplink {
metadata: UplinkMetadata {
wor_channel: WorChannel::Second,
rssi_dbm: -100,
snr_db: 5,
data_rate: 5,
},
frequency_hz: 868_100_000,
phy_payload: frame.as_bytes(),
};
let mut out = [0u8; 64];
let len = forwarded.encode(&mut out)?;
// The network reads back exactly what the relay heard, and the sensor's frame intact.
assert_eq!(ForwardedUplink::parse(&out[..len])?, forwarded);Sourcepub fn parse(bytes: &'a [u8]) -> Result<ForwardedUplink<'a>, LorawanError>
pub fn parse(bytes: &'a [u8]) -> Result<ForwardedUplink<'a>, LorawanError>
Reads a forwarded uplink.
§Arguments
bytes- the payload of a relay uplink on port 226.
§Returns
The forwarded uplink, borrowing the end device’s frame from bytes.
§Errors
Returns LorawanError::FrameTooShort for fewer than FORWARD_OVERHEAD bytes, and
LorawanError::MalformedFrame for a reserved WOR channel.
Trait Implementations§
Source§impl<'a> Clone for ForwardedUplink<'a>
impl<'a> Clone for ForwardedUplink<'a>
Source§fn clone(&self) -> ForwardedUplink<'a>
fn clone(&self) -> ForwardedUplink<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more