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

Function request

chirpstack/src/maccommand/new_channel.rs:11–64  ·  view source on GitHub ↗
(
    max_channels: usize,
    current_channels: &HashMap<usize, Channel>,
    wanted_channels: &HashMap<usize, Channel>,
    region_conf: Arc<Box<dyn lrwn::region::Region + Send + Sync>>,
)

Source from the content-addressed store, hash-verified

9use lrwn::region::Channel;
10
11pub fn request(
12 max_channels: usize,
13 current_channels: &HashMap<usize, Channel>,
14 wanted_channels: &HashMap<usize, Channel>,
15 region_conf: Arc<Box<dyn lrwn::region::Region + Send + Sync>>,
16) -> Result<Option<lrwn::MACCommandSet>> {
17 let mut out: Vec<lrwn::MACCommand> = Vec::new();
18
19 let mut wanted_channel_numbers: Vec<usize> = wanted_channels.keys().cloned().collect();
20 wanted_channel_numbers.sort_unstable();
21
22 for i in &wanted_channel_numbers {
23 let wanted = wanted_channels.get(i).unwrap(); // we already know the key is in the map
24 let (min_dr, max_dr) = region_conf.get_new_channel_req_dr_range(&wanted.data_rates)?;
25
26 match current_channels.get(i) {
27 Some(current) => {
28 // Channel needs to be updated.
29 if current.frequency != wanted.frequency || current.data_rates != wanted.data_rates
30 {
31 out.push(lrwn::MACCommand::NewChannelReq(
32 lrwn::NewChannelReqPayload {
33 ch_index: *i as u8,
34 freq: wanted.frequency,
35 min_dr,
36 max_dr,
37 },
38 ));
39 }
40 }
41 None => {
42 // Channel needs to be added.
43 out.push(lrwn::MACCommand::NewChannelReq(
44 lrwn::NewChannelReqPayload {
45 ch_index: *i as u8,
46 freq: wanted.frequency,
47 min_dr,
48 max_dr,
49 },
50 ));
51 }
52 }
53 }
54
55 if out.len() > max_channels {
56 out.drain(max_channels..);
57 }
58
59 if out.is_empty() {
60 return Ok(None);
61 }
62
63 Ok(Some(lrwn::MACCommandSet::new(out)))
64}
65
66pub fn handle(
67 dev: &mut device::Device,

Callers 6

test_requestFunction · 0.70
_set_rx_parametersMethod · 0.50
_set_tx_parametersMethod · 0.50

Calls 4

unwrapMethod · 0.80
pushMethod · 0.80
getMethod · 0.45

Tested by 1

test_requestFunction · 0.56