MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / set_phy_payloads

Method set_phy_payloads

chirpstack/src/downlink/data.rs:717–870  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

715 }
716
717 fn set_phy_payloads(&mut self) -> Result<()> {
718 trace!("Setting downlink PHYPayloads");
719 let mut f_pending = self.more_device_queue_items;
720 let dev_addr = self.device.get_dev_addr()?;
721 let device_f_cnt_up = self.device.f_cnt_up as u32;
722 let ds = self.device.get_device_session_mut()?;
723
724 for item in self.downlink_frame_items.iter_mut() {
725 let mut mac_size: usize = 0;
726 let mut mac_commands: Vec<lrwn::MACCommand> = Vec::new();
727
728 // collect all mac-commands up to RemainingPayloadSize bytes.
729 for mac_set in &self.mac_commands {
730 // get size of mac-command block
731 let s = mac_set.size().context("Get mac-command size")?;
732
733 // break if it does not fit within the RemainingPayloadSize
734 if (item.remaining_payload_size as isize) - (s as isize) < 0 {
735 break;
736 }
737
738 item.remaining_payload_size -= s;
739 mac_size += s;
740
741 for mac in &**mac_set {
742 mac_commands.push(mac.clone());
743 }
744
745 mac_command::set_pending(ds, mac_set)?;
746 }
747
748 // LoRaWAN MHDR
749 let mut mhdr = lrwn::MHDR {
750 f_type: lrwn::FType::UnconfirmedDataDown,
751 major: lrwn::Major::LoRaWANR1,
752 };
753
754 // LoRaWAN MAC payload
755 let mut mac_pl = lrwn::MACPayload {
756 fhdr: lrwn::FHDR {
757 devaddr: dev_addr,
758 f_cnt: ds.n_f_cnt_down,
759 f_ctrl: lrwn::FCtrl {
760 adr: !self.network_conf.adr_disabled,
761 ack: self.must_ack,
762 f_pending,
763 ..Default::default()
764 },
765 f_opts: lrwn::MACCommandSet::new(vec![]),
766 },
767 f_port: None,
768 frm_payload: None,
769 };
770
771 // In this case mac-commands are sent as FRMPayload. We will not be able to
772 // send a device-queue item in this case.
773 if mac_size > 15 {
774 // Set the FPending to true if we were planning to send a downlink

Callers 3

_handle_responseMethod · 0.80

Calls 14

set_pendingFunction · 0.85
MACCommandSetClass · 0.85
MACPayloadClass · 0.85
get_dev_addrMethod · 0.80
pushMethod · 0.80
get_a_f_cnt_downMethod · 0.80
encrypt_frm_payloadMethod · 0.80
to_stringMethod · 0.80
encrypt_f_optsMethod · 0.80
set_downlink_data_micMethod · 0.80
from_protoMethod · 0.80

Tested by

no test coverage detected