pub struct Uplink<'a> { /* private fields */ }Expand description
An uplink data frame to encode, built up from the fields a sender sets.
Construct one with new and turn on whatever applies; the rest default
off. A higher port carries application data; port 0 carries MAC commands. A frame with
nothing to carry but its header and frame options, such as an answer to a MAC command
with no reading to go with it, is built with empty and has no port.
§Examples
use pamoja_lorawan::Uplink;
let uplink = Uplink::new(7, 2, b"reading").confirmed().with_adr();Implementations§
Source§impl<'a> Uplink<'a>
impl<'a> Uplink<'a>
Sourcepub fn empty(fcnt: u32) -> Self
pub fn empty(fcnt: u32) -> Self
Creates an uplink with no port and no payload.
TS001-1.0.4 section 4.3.2 makes the port optional when there is no payload. What such a frame carries is its header: the counter, the flags, and whatever frame options it is given.
§Arguments
fcnt- the frame counter for this uplink.
§Returns
The uplink.
§Examples
use pamoja_lorawan::mac::MacCommand;
use pamoja_lorawan::{Session, Uplink};
// A device answering a status request and nothing else: on mains power it cannot
// measure a battery, and it heard the request 10 dB above the noise.
let session = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
let mut answer = [0u8; 3];
MacCommand::DevStatusAns { battery: 255, margin: 10 }.encode(&mut answer)?;
let frame = session.encode_uplink(&Uplink::empty(3).with_fopts(&answer))?;
// It goes up with no port and no payload, the answer in the frame options.
let heard = session.decode(frame.as_bytes(), 3)?;
assert_eq!(heard.fport(), None);
assert_eq!(heard.fopts(), &answer);Sourcepub fn confirmed(self) -> Self
pub fn confirmed(self) -> Self
Marks the uplink as confirmed, asking the network to acknowledge it.
§Returns
The uplink, for chaining.
Sourcepub fn with_adr(self) -> Self
pub fn with_adr(self) -> Self
Sets the adaptive-data-rate bit, letting the network manage the data rate.
§Returns
The uplink, for chaining.
Sourcepub fn with_adr_ack_req(self) -> Self
pub fn with_adr_ack_req(self) -> Self
Sets the ADR acknowledgment request bit, asking the network to send something back.
A device sets it once it has gone ADR_ACK_LIMIT
uplinks without hearing anything, and Backoff says when.
§Returns
The uplink, for chaining.
Sourcepub fn with_ack(self) -> Self
pub fn with_ack(self) -> Self
Sets the acknowledgment bit, confirming a previously received downlink.
§Returns
The uplink, for chaining.