spat: ensure that "our" intersection is kept in cache
Sometimes we may not receive V2X data for longer than the TLC cache time. This leads to no SPAT updates in the GLOSA algorithm since that uses a cached reference to the intersection instead of querying the tlc cache every time.
This commit is contained in:
parent
a62d25e651
commit
cc31d6226e
2 changed files with 72 additions and 53 deletions
|
|
@ -255,6 +255,15 @@ impl State {
|
|||
info.intersection_id, info.lane_id
|
||||
);
|
||||
|
||||
// ensure that "our" intersection is kept in TLC cache
|
||||
if self
|
||||
.tlc_cache
|
||||
.keep_intersection(info.intersection_id, self.time)
|
||||
.is_err()
|
||||
{
|
||||
info!("GLOSA: Intersection not known any more");
|
||||
(Some(GlosaState::Idle), None)
|
||||
} else {
|
||||
// determine if intersection is left
|
||||
let intersection = info.intersection.borrow();
|
||||
if Self::is_intersection_left(
|
||||
|
|
@ -295,8 +304,8 @@ impl State {
|
|||
.map(core::convert::Into::into)
|
||||
.unwrap_or_default();
|
||||
|
||||
let end_sec =
|
||||
sig.likely_time()
|
||||
let end_sec = sig
|
||||
.likely_time()
|
||||
.or_else(|| sig.min_end_time())
|
||||
.map(|time| {
|
||||
let dur =
|
||||
|
|
@ -322,6 +331,7 @@ impl State {
|
|||
(None, Some(sig_grps)) // keep state, return signal groups
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// can't update the state from within the match statement, so do it here
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use chrono::Datelike;
|
|||
use esp_println::println;
|
||||
|
||||
use super::v2x::map;
|
||||
use crate::cache::Cache;
|
||||
use crate::cache::{Cache, CacheError};
|
||||
|
||||
pub struct Data {
|
||||
intersections: Cache<u16, map::Intersection>,
|
||||
|
|
@ -86,6 +86,15 @@ impl Data {
|
|||
self.intersections.prune(time_now);
|
||||
}
|
||||
|
||||
/// Bumps the timestamp of a certain intersection to keep it cached
|
||||
pub fn keep_intersection(
|
||||
&mut self,
|
||||
intersection_id: u16,
|
||||
time_now: chrono::NaiveDateTime,
|
||||
) -> Result<(), CacheError<u16>> {
|
||||
self.intersections.update(time_now, intersection_id, |_| {})
|
||||
}
|
||||
|
||||
pub fn handle_spatem(&mut self, time_now: chrono::NaiveDateTime, etsi: &SPATEM) {
|
||||
for int in &etsi.spat.intersections.0 {
|
||||
let int_id = int.id.id.0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue