Skip to content

Commit

Permalink
Add fine-timestamp to concentratord-sx1302. (#66)
Browse files Browse the repository at this point in the history
Closes #65.

---------

Co-authored-by: Orne Brocaar <[email protected]>
  • Loading branch information
LouneCode and brocaar authored Jun 13, 2023
1 parent 40791ea commit d3a3c7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
4 changes: 3 additions & 1 deletion chirpstack-concentratord-sx1302/src/handler/uplink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ pub fn handle_loop(
let rx_info = proto.rx_info.as_ref().unwrap();

info!(
"Frame received, uplink_id: {}, count_us: {}, freq: {}, bw: {}, mod: {:?}, dr: {:?}",
"Frame received, uplink_id: {}, count_us: {}, freq: {}, bw: {}, mod: {:?}, dr: {:?}, ftime_received: {}, ftime_ns: {}",
rx_info.uplink_id,
frame.count_us,
frame.freq_hz,
frame.bandwidth,
frame.modulation,
frame.datarate,
frame.ftime_received,
frame.ftime,
);

if frame.status == hal::CRC::CRCOk {
Expand Down
34 changes: 23 additions & 11 deletions chirpstack-concentratord-sx1302/src/wrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ pub fn uplink_to_proto(
let mut rng = rand::thread_rng();
let uplink_id: u32 = rng.gen();

let time_since_gps_epoch = match gps::cnt2epoch(packet.count_us) {
Ok(v) => Some(prost_types::Duration {
seconds: v.as_secs() as i64,
nanos: v.subsec_nanos() as i32,
}),
Err(err) => {
debug!(
"Could not get GPS epoch, uplink_id: {}, error: {}",
uplink_id, err
);
None
}
};

Ok(gw::UplinkFrame {
phy_payload: packet.payload[..packet.size as usize].to_vec(),
tx_info: Some(gw::UplinkTxInfo {
Expand Down Expand Up @@ -133,19 +147,17 @@ pub fn uplink_to_proto(
}
}
},
time_since_gps_epoch: match gps::cnt2epoch(packet.count_us) {
Ok(v) => Some(prost_types::Duration {
seconds: v.as_secs() as i64,
nanos: v.subsec_nanos() as i32,
fine_time_since_gps_epoch: match packet.ftime_received {
true => Some(prost_types::Duration {
nanos: packet.ftime as i32,
seconds: time_since_gps_epoch
.as_ref()
.map(|v| v.seconds)
.unwrap_or_default(),
}),
Err(err) => {
debug!(
"Could not get GPS epoch, uplink_id: {}, error: {}",
uplink_id, err
);
None
}
false => None,
},
time_since_gps_epoch,
crc_status: match packet.status {
hal::CRC::CRCOk => gw::CrcStatus::CrcOk,
hal::CRC::BadCRC => gw::CrcStatus::BadCrc,
Expand Down

0 comments on commit d3a3c7b

Please sign in to comment.