Skip to main content

ForwardedUplink

Struct ForwardedUplink 

Source
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: UplinkMetadata

What the relay heard of it.

§frequency_hz: u32

The 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>

Source

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);
Source

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>

Source§

fn clone(&self) -> ForwardedUplink<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ForwardedUplink<'a>

Source§

impl<'a> Debug for ForwardedUplink<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for ForwardedUplink<'a>

Source§

impl<'a> PartialEq for ForwardedUplink<'a>

Source§

fn eq(&self, other: &ForwardedUplink<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for ForwardedUplink<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ForwardedUplink<'a>

§

impl<'a> RefUnwindSafe for ForwardedUplink<'a>

§

impl<'a> Send for ForwardedUplink<'a>

§

impl<'a> Sync for ForwardedUplink<'a>

§

impl<'a> Unpin for ForwardedUplink<'a>

§

impl<'a> UnsafeUnpin for ForwardedUplink<'a>

§

impl<'a> UnwindSafe for ForwardedUplink<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.