Skip to content

Commit

Permalink
Implement preamble and no_crc fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Oct 26, 2023
1 parent 0ada5cb commit 2591b7a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clap = { version = "4.4", default-features = false, features = [
"usage",
"derive",
] }
chirpstack_api = { version = "4.5", default-features = false, features = [
chirpstack_api = { version = "4.6.0-test.1", default-features = false, features = [
"json",
] }
lrwn_filters = { version = "4.5", features = ["serde"] }
Expand Down
45 changes: 32 additions & 13 deletions src/backend/semtech_udp/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ impl RxPk {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: hex::encode(gateway_id),
uplink_id,
time: match self.time.map(pbjson_types::Timestamp::from) {
ns_time: None,
gw_time: match self.time.map(pbjson_types::Timestamp::from) {
Some(v) => Some(v),
None => {
if time_fallback_enabled {
Expand Down Expand Up @@ -724,12 +725,30 @@ impl PullResp {
gw::modulation::Parameters::Fsk(v) => Some(v.frequency_deviation as u16),
_ => None,
},
ncrc: None,
ncrc: match modulation_params {
gw::modulation::Parameters::Lora(v) => {
if v.no_crc {
Some(v.no_crc)
} else {
None
}
}
_ => None,
},
ipol: match modulation_params {
gw::modulation::Parameters::Lora(v) => Some(v.polarization_inversion),
_ => None,
},
prea: None,
prea: match modulation_params {
gw::modulation::Parameters::Lora(v) => {
if v.preamble > 0 {
Some(v.preamble as u16)
} else {
None
}
}
_ => None,
},
size: item.phy_payload.len() as u16,
data: item.phy_payload.clone(),
},
Expand Down Expand Up @@ -1140,7 +1159,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 120,
snr: 3.5,
channel: 5,
Expand Down Expand Up @@ -1210,7 +1229,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
time_since_gps_epoch: Some(pbjson_types::Duration::from(Duration::from_secs(
5
))),
Expand Down Expand Up @@ -1283,7 +1302,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
time_since_gps_epoch: Some(pbjson_types::Duration::from(
Duration::from_millis(5_100)
)),
Expand Down Expand Up @@ -1373,7 +1392,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 120,
snr: 5.4,
channel: 5,
Expand Down Expand Up @@ -1404,7 +1423,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 130,
snr: 3.5,
channel: 6,
Expand Down Expand Up @@ -1471,7 +1490,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 120,
channel: 5,
rf_chain: 1,
Expand Down Expand Up @@ -1540,7 +1559,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 120,
channel: 5,
rf_chain: 1,
Expand Down Expand Up @@ -1614,7 +1633,7 @@ mod test {
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
uplink_id: 123,
time: Some(pbjson_types::Timestamp::from(now)),
gw_time: Some(pbjson_types::Timestamp::from(now)),
rssi: 120,
snr: 3.5,
channel: 5,
Expand Down Expand Up @@ -1667,7 +1686,7 @@ mod test {
};
let pl = pl.to_proto_uplink_frames(false).unwrap();
assert_eq!(1, pl.len());
assert!(pl[0].rx_info.as_ref().unwrap().time.is_none());
assert!(pl[0].rx_info.as_ref().unwrap().gw_time.is_none());
}

#[test]
Expand Down Expand Up @@ -1702,7 +1721,7 @@ mod test {
};
let pl = pl.to_proto_uplink_frames(true).unwrap();
assert_eq!(1, pl.len());
assert!(pl[0].rx_info.as_ref().unwrap().time.is_some());
assert!(pl[0].rx_info.as_ref().unwrap().gw_time.is_some());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/semtech_udp_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async fn end_to_end() {
}),
rx_info: Some(gw::UplinkRxInfo {
gateway_id: "0102030405060708".into(),
time: Some(pbjson_types::Timestamp::from(ts.clone())),
gw_time: Some(pbjson_types::Timestamp::from(ts.clone())),
rssi: -35,
snr: 5.1,
channel: 2,
Expand Down

0 comments on commit 2591b7a

Please sign in to comment.