[fix](trx-frontend-http): preserve decoder history timestamps
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -27,6 +27,14 @@ use trx_frontend::FrontendRuntimeContext;
|
|||||||
|
|
||||||
const HISTORY_RETENTION: Duration = Duration::from_secs(24 * 60 * 60);
|
const HISTORY_RETENTION: Duration = Duration::from_secs(24 * 60 * 60);
|
||||||
|
|
||||||
|
fn current_timestamp_ms() -> i64 {
|
||||||
|
let millis = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_millis();
|
||||||
|
i64::try_from(millis).unwrap_or(i64::MAX)
|
||||||
|
}
|
||||||
|
|
||||||
fn prune_aprs_history(history: &mut VecDeque<(Instant, AprsPacket)>) {
|
fn prune_aprs_history(history: &mut VecDeque<(Instant, AprsPacket)>) {
|
||||||
while let Some((ts, _)) = history.front() {
|
while let Some((ts, _)) = history.front() {
|
||||||
if ts.elapsed() <= HISTORY_RETENTION {
|
if ts.elapsed() <= HISTORY_RETENTION {
|
||||||
@@ -54,7 +62,10 @@ fn prune_vdes_history(history: &mut VecDeque<(Instant, VdesMessage)>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_ais(context: &FrontendRuntimeContext, msg: AisMessage) {
|
fn record_ais(context: &FrontendRuntimeContext, mut msg: AisMessage) {
|
||||||
|
if msg.ts_ms.is_none() {
|
||||||
|
msg.ts_ms = Some(current_timestamp_ms());
|
||||||
|
}
|
||||||
let mut history = context
|
let mut history = context
|
||||||
.ais_history
|
.ais_history
|
||||||
.lock()
|
.lock()
|
||||||
@@ -63,7 +74,10 @@ fn record_ais(context: &FrontendRuntimeContext, msg: AisMessage) {
|
|||||||
prune_ais_history(&mut history);
|
prune_ais_history(&mut history);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_vdes(context: &FrontendRuntimeContext, msg: VdesMessage) {
|
fn record_vdes(context: &FrontendRuntimeContext, mut msg: VdesMessage) {
|
||||||
|
if msg.ts_ms.is_none() {
|
||||||
|
msg.ts_ms = Some(current_timestamp_ms());
|
||||||
|
}
|
||||||
let mut history = context
|
let mut history = context
|
||||||
.vdes_history
|
.vdes_history
|
||||||
.lock()
|
.lock()
|
||||||
@@ -99,7 +113,10 @@ fn prune_wspr_history(history: &mut VecDeque<(Instant, WsprMessage)>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_aprs(context: &FrontendRuntimeContext, pkt: AprsPacket) {
|
fn record_aprs(context: &FrontendRuntimeContext, mut pkt: AprsPacket) {
|
||||||
|
if pkt.ts_ms.is_none() {
|
||||||
|
pkt.ts_ms = Some(current_timestamp_ms());
|
||||||
|
}
|
||||||
let mut history = context
|
let mut history = context
|
||||||
.aprs_history
|
.aprs_history
|
||||||
.lock()
|
.lock()
|
||||||
@@ -141,14 +158,7 @@ pub fn snapshot_aprs_history(context: &FrontendRuntimeContext) -> Vec<AprsPacket
|
|||||||
.lock()
|
.lock()
|
||||||
.expect("aprs history mutex poisoned");
|
.expect("aprs history mutex poisoned");
|
||||||
prune_aprs_history(&mut history);
|
prune_aprs_history(&mut history);
|
||||||
history
|
history.iter().map(|(_, pkt)| pkt.clone()).collect()
|
||||||
.iter()
|
|
||||||
.map(|(ts, pkt)| {
|
|
||||||
let mut pkt = pkt.clone();
|
|
||||||
pkt.ts_ms = Some(timestamp_ms_for_elapsed(ts.elapsed()));
|
|
||||||
pkt
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_ais_history(context: &FrontendRuntimeContext) -> Vec<AisMessage> {
|
pub fn snapshot_ais_history(context: &FrontendRuntimeContext) -> Vec<AisMessage> {
|
||||||
@@ -157,14 +167,7 @@ pub fn snapshot_ais_history(context: &FrontendRuntimeContext) -> Vec<AisMessage>
|
|||||||
.lock()
|
.lock()
|
||||||
.expect("ais history mutex poisoned");
|
.expect("ais history mutex poisoned");
|
||||||
prune_ais_history(&mut history);
|
prune_ais_history(&mut history);
|
||||||
history
|
history.iter().map(|(_, msg)| msg.clone()).collect()
|
||||||
.iter()
|
|
||||||
.map(|(ts, msg)| {
|
|
||||||
let mut msg = msg.clone();
|
|
||||||
msg.ts_ms = Some(timestamp_ms_for_elapsed(ts.elapsed()));
|
|
||||||
msg
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_vdes_history(context: &FrontendRuntimeContext) -> Vec<VdesMessage> {
|
pub fn snapshot_vdes_history(context: &FrontendRuntimeContext) -> Vec<VdesMessage> {
|
||||||
@@ -173,14 +176,7 @@ pub fn snapshot_vdes_history(context: &FrontendRuntimeContext) -> Vec<VdesMessag
|
|||||||
.lock()
|
.lock()
|
||||||
.expect("vdes history mutex poisoned");
|
.expect("vdes history mutex poisoned");
|
||||||
prune_vdes_history(&mut history);
|
prune_vdes_history(&mut history);
|
||||||
history
|
history.iter().map(|(_, msg)| msg.clone()).collect()
|
||||||
.iter()
|
|
||||||
.map(|(ts, msg)| {
|
|
||||||
let mut msg = msg.clone();
|
|
||||||
msg.ts_ms = Some(timestamp_ms_for_elapsed(ts.elapsed()));
|
|
||||||
msg
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_cw_history(context: &FrontendRuntimeContext) -> Vec<CwEvent> {
|
pub fn snapshot_cw_history(context: &FrontendRuntimeContext) -> Vec<CwEvent> {
|
||||||
@@ -234,15 +230,6 @@ pub fn clear_vdes_history(context: &FrontendRuntimeContext) {
|
|||||||
history.clear();
|
history.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_ms_for_elapsed(elapsed: Duration) -> i64 {
|
|
||||||
let wall_clock = SystemTime::now().checked_sub(elapsed).unwrap_or(UNIX_EPOCH);
|
|
||||||
let millis = wall_clock
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_millis();
|
|
||||||
i64::try_from(millis).unwrap_or(i64::MAX)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clear_cw_history(context: &FrontendRuntimeContext) {
|
pub fn clear_cw_history(context: &FrontendRuntimeContext) {
|
||||||
let mut history = context
|
let mut history = context
|
||||||
.cw_history
|
.cw_history
|
||||||
|
|||||||
Reference in New Issue
Block a user