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

Function get_rx_timestamp

chirpstack/src/uplink/helpers.rs:56–91  ·  view source on GitHub ↗
(rx_info: &[gw::UplinkRxInfo])

Source from the content-addressed store, hash-verified

54}
55
56pub fn get_rx_timestamp(rx_info: &[gw::UplinkRxInfo]) -> SystemTime {
57 let conf = config::get();
58 let rx_timestamp_max_drift = conf.gateway.rx_timestamp_max_drift;
59
60 // First search for time_since_gps_epoch.
61 for rxi in rx_info {
62 if let Some(gps_time) = &rxi.time_since_gps_epoch
63 && let Ok(ts) = chrono::Duration::from_std(Duration::new(
64 gps_time.seconds as u64,
65 gps_time.nanos as u32,
66 ))
67 {
68 return ts.to_date_time().into();
69 }
70 }
71
72 // Then search for time.
73 for rxi in rx_info {
74 if let Some(ts) = &rxi.gw_time {
75 let ts: Result<DateTime<Utc>> = (*ts).try_into().map_err(anyhow::Error::msg);
76 if let Ok(ts) = ts {
77 let mut delta = Utc::now() - ts;
78 if delta < TimeDelta::default() {
79 delta = -delta;
80 }
81 let delta = delta.to_std().unwrap_or_default();
82 if delta < rx_timestamp_max_drift {
83 return ts.into();
84 }
85 }
86 }
87 }
88
89 // last resort use systemtime of NS
90 SystemTime::now()
91}
92
93pub fn get_rx_timestamp_chrono(rx_info: &[gw::UplinkRxInfo]) -> DateTime<Utc> {
94 let conf = config::get();

Callers 9

handleFunction · 0.85
handleFunction · 0.85
send_join_eventMethod · 0.85
send_uplink_eventMethod · 0.85
handle_uplink_ackMethod · 0.85
send_join_eventMethod · 0.85

Calls 3

to_date_timeMethod · 0.80
getFunction · 0.50
intoMethod · 0.45

Tested by 2