Skip to content

Commit 63062ed

Browse files
committed
Tune dependency features + replace rand by getrandom.
1 parent 49c441f commit 63062ed

File tree

11 files changed

+272
-677
lines changed

11 files changed

+272
-677
lines changed

Cargo.lock

Lines changed: 11 additions & 422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,31 @@
1515
[workspace.dependencies]
1616
chirpstack_api = { version = "4.14", default-features = false }
1717
serde = { version = "1.0", features = ["derive"] }
18-
toml = "0.9"
19-
clap = { version = "4.5", features = ["derive"] }
18+
serde_json = "1.0"
19+
toml = { version = "0.9", default-features = false, features = [
20+
"std",
21+
"parse",
22+
"serde",
23+
] }
24+
clap = { version = "4.5", default-features = false, features = [
25+
"std",
26+
"help",
27+
"usage",
28+
"derive",
29+
] }
2030
log = "0.4"
21-
simple_logger = "5.0"
31+
simple_logger = { version = "5.0", default-features = false, features = [
32+
"timestamps",
33+
] }
2234
zmq = "0.10"
2335
hex = "0.4"
24-
chrono = "0.4"
36+
chrono = { version = "0.4", default-features = false, features = ["now"] }
2537
humantime-serde = "1.1"
2638
syslog = "7.0"
2739
signal-hook = "0.3"
2840
handlebars = "6.3"
29-
rand = "0.9"
41+
getrandom = "0.3"
3042
anyhow = "1.0"
43+
thiserror = "2.0"
3144
bindgen = "0.72"
45+
gpiocdev = { version = "0.7", features = ["uapi_v1"] }

chirpstack-concentratord-2g4/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
syslog = { workspace = true }
2525
signal-hook = { workspace = true }
2626
handlebars = { workspace = true }
27-
rand = { workspace = true }
27+
getrandom = { workspace = true }
2828
anyhow = { workspace = true }

chirpstack-concentratord-2g4/src/wrapper.rs

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use anyhow::Result;
44
use chirpstack_api::{gw, prost_types};
55
use libconcentratord::jitqueue;
66
use libloragw_2g4::hal;
7-
use rand::Rng;
87

98
#[derive(Copy, Clone)]
109
pub struct TxPacket(hal::TxPacket, u32);
@@ -68,8 +67,6 @@ pub fn uplink_to_proto(
6867
packet: &hal::RxPacket,
6968
time_fallback: bool,
7069
) -> Result<gw::UplinkFrame> {
71-
let mut rng = rand::rng();
72-
7370
Ok(gw::UplinkFrame {
7471
phy_payload: packet.payload[..packet.size as usize].to_vec(),
7572
tx_info: Some(gw::UplinkTxInfo {
@@ -106,7 +103,7 @@ pub fn uplink_to_proto(
106103
}),
107104
}),
108105
rx_info: Some(gw::UplinkRxInfo {
109-
uplink_id: rng.random(),
106+
uplink_id: getrandom::u32()?,
110107
context: packet.count_us.to_be_bytes().to_vec(),
111108
gateway_id: hex::encode(gateway_id),
112109
rssi: packet.rssi as i32,
@@ -157,89 +154,91 @@ pub fn downlink_from_proto(
157154
};
158155

159156
if let Some(timing) = &tx_info.timing
160-
&& let Some(params) = &timing.parameters {
161-
match params {
162-
gw::timing::Parameters::Immediately(_) => {
163-
packet.tx_mode = hal::TxMode::Immediate;
157+
&& let Some(params) = &timing.parameters
158+
{
159+
match params {
160+
gw::timing::Parameters::Immediately(_) => {
161+
packet.tx_mode = hal::TxMode::Immediate;
162+
}
163+
gw::timing::Parameters::Delay(v) => {
164+
packet.tx_mode = hal::TxMode::Timestamped;
165+
166+
let ctx = &tx_info.context;
167+
if ctx.len() != 4 {
168+
return Err(anyhow!("context must be exactly 4 bytes"));
164169
}
165-
gw::timing::Parameters::Delay(v) => {
166-
packet.tx_mode = hal::TxMode::Timestamped;
167170

168-
let ctx = &tx_info.context;
169-
if ctx.len() != 4 {
170-
return Err(anyhow!("context must be exactly 4 bytes"));
171+
match &v.delay {
172+
Some(v) => {
173+
let mut array = [0; 4];
174+
array.copy_from_slice(ctx);
175+
packet.count_us = u32::from_be_bytes(array).wrapping_add(
176+
(Duration::from_secs(v.seconds as u64)
177+
+ Duration::from_nanos(v.nanos as u64))
178+
.as_micros() as u32,
179+
);
171180
}
172-
173-
match &v.delay {
174-
Some(v) => {
175-
let mut array = [0; 4];
176-
array.copy_from_slice(ctx);
177-
packet.count_us = u32::from_be_bytes(array).wrapping_add(
178-
(Duration::from_secs(v.seconds as u64)
179-
+ Duration::from_nanos(v.nanos as u64))
180-
.as_micros() as u32,
181-
);
182-
}
183-
None => {
184-
return Err(anyhow!("delay must not be null"));
185-
}
181+
None => {
182+
return Err(anyhow!("delay must not be null"));
186183
}
187184
}
188-
gw::timing::Parameters::GpsEpoch(_) => {
189-
return Err(anyhow!("gps epoch timing is not implemented"));
190-
}
185+
}
186+
gw::timing::Parameters::GpsEpoch(_) => {
187+
return Err(anyhow!("gps epoch timing is not implemented"));
191188
}
192189
}
190+
}
193191

194192
if let Some(modulation) = &tx_info.modulation
195-
&& let Some(params) = &modulation.parameters {
196-
match params {
197-
gw::modulation::Parameters::Lora(v) => {
198-
packet.bandwidth = v.bandwidth;
199-
packet.datarate = match v.spreading_factor {
200-
5 => hal::DataRate::SF5,
201-
6 => hal::DataRate::SF6,
202-
7 => hal::DataRate::SF7,
203-
8 => hal::DataRate::SF8,
204-
9 => hal::DataRate::SF9,
205-
10 => hal::DataRate::SF10,
206-
11 => hal::DataRate::SF11,
207-
12 => hal::DataRate::SF12,
193+
&& let Some(params) = &modulation.parameters
194+
{
195+
match params {
196+
gw::modulation::Parameters::Lora(v) => {
197+
packet.bandwidth = v.bandwidth;
198+
packet.datarate = match v.spreading_factor {
199+
5 => hal::DataRate::SF5,
200+
6 => hal::DataRate::SF6,
201+
7 => hal::DataRate::SF7,
202+
8 => hal::DataRate::SF8,
203+
9 => hal::DataRate::SF9,
204+
10 => hal::DataRate::SF10,
205+
11 => hal::DataRate::SF11,
206+
12 => hal::DataRate::SF12,
207+
_ => return Err(anyhow!("unexpected spreading-factor")),
208+
};
209+
packet.coderate = match v.code_rate() {
210+
gw::CodeRate::Cr45 => hal::CodeRate::LoRa4_5,
211+
gw::CodeRate::Cr46 => hal::CodeRate::LoRa4_6,
212+
gw::CodeRate::Cr47 => hal::CodeRate::LoRa4_7,
213+
gw::CodeRate::Cr48 => hal::CodeRate::LoRa4_8,
214+
gw::CodeRate::CrLi45 => hal::CodeRate::LoRaLi4_5,
215+
gw::CodeRate::CrLi46 => hal::CodeRate::LoRaLi4_6,
216+
gw::CodeRate::CrLi48 => hal::CodeRate::LoRaLi4_8,
217+
_ => return Err(anyhow!("unexpected coderate")),
218+
};
219+
packet.preamble = if v.preamble > 0 {
220+
v.preamble as u16
221+
} else {
222+
match v.spreading_factor {
223+
5 => 12,
224+
6 => 12,
225+
7 => 8,
226+
8 => 8,
227+
9 => 8,
228+
10 => 8,
229+
11 => 8,
230+
12 => 8,
208231
_ => return Err(anyhow!("unexpected spreading-factor")),
209-
};
210-
packet.coderate = match v.code_rate() {
211-
gw::CodeRate::Cr45 => hal::CodeRate::LoRa4_5,
212-
gw::CodeRate::Cr46 => hal::CodeRate::LoRa4_6,
213-
gw::CodeRate::Cr47 => hal::CodeRate::LoRa4_7,
214-
gw::CodeRate::Cr48 => hal::CodeRate::LoRa4_8,
215-
gw::CodeRate::CrLi45 => hal::CodeRate::LoRaLi4_5,
216-
gw::CodeRate::CrLi46 => hal::CodeRate::LoRaLi4_6,
217-
gw::CodeRate::CrLi48 => hal::CodeRate::LoRaLi4_8,
218-
_ => return Err(anyhow!("unexpected coderate")),
219-
};
220-
packet.preamble = if v.preamble > 0 {
221-
v.preamble as u16
222-
} else {
223-
match v.spreading_factor {
224-
5 => 12,
225-
6 => 12,
226-
7 => 8,
227-
8 => 8,
228-
9 => 8,
229-
10 => 8,
230-
11 => 8,
231-
12 => 8,
232-
_ => return Err(anyhow!("unexpected spreading-factor")),
233-
}
234-
};
235-
packet.no_crc = v.no_crc;
236-
packet.invert_pol = v.polarization_inversion;
237-
}
238-
_ => {
239-
return Err(anyhow!("only LORA modulation is implemented"));
240-
}
232+
}
233+
};
234+
packet.no_crc = v.no_crc;
235+
packet.invert_pol = v.polarization_inversion;
236+
}
237+
_ => {
238+
return Err(anyhow!("only LORA modulation is implemented"));
241239
}
242240
}
241+
}
243242

244243
Ok(packet)
245244
}

chirpstack-concentratord-sx1301/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
syslog = { workspace = true }
2525
signal-hook = { workspace = true }
2626
handlebars = { workspace = true }
27-
rand = { workspace = true }
27+
getrandom = { workspace = true }
2828
anyhow = { workspace = true }

chirpstack-concentratord-sx1301/src/handler/beacon.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use anyhow::Result;
77
use libconcentratord::jitqueue;
88
use libconcentratord::signals::Signal;
99
use libloragw_sx1301::hal;
10-
use rand::Rng;
1110

1211
use super::super::{config, wrapper};
1312
use super::{gps, timersync};
@@ -71,8 +70,6 @@ fn send_beacon(
7170
beacon_time: Duration,
7271
queue: &Arc<Mutex<jitqueue::Queue<wrapper::TxPacket>>>,
7372
) -> Result<()> {
74-
let mut rng = rand::rng();
75-
7673
let mut beacon_pl = get_beacon(conf.compulsory_rfu_size, beacon_time);
7774
let data_size = beacon_pl.len();
7875

@@ -109,7 +106,7 @@ fn send_beacon(
109106
size: data_size as u16,
110107
payload: data,
111108
};
112-
let tx_packet = wrapper::TxPacket::new(rng.random(), tx_packet);
109+
let tx_packet = wrapper::TxPacket::new(getrandom::u32()?, tx_packet);
113110

114111
queue
115112
.lock()

0 commit comments

Comments
 (0)