0
0
Fork 0

screen, spat: Add more information and update indicator

This commit is contained in:
Jannik Beyerstedt 2026-06-22 22:59:47 +02:00
commit fc0c9b61da
3 changed files with 403 additions and 175 deletions

View file

@ -65,7 +65,46 @@ pub struct State {
}
#[cfg(feature = "spat")]
#[derive(Debug, Default)]
#[derive(Debug)]
pub enum GlosaOutput {
Error(alloc::string::String),
Searching(GlosaSearching),
Found(GlosaFound),
Locked(GlosaSignalInfo),
}
#[cfg(feature = "spat")]
#[derive(Debug, PartialEq, Eq)]
pub struct GlosaSearching {
pub known_intersection_ids: Vec<u16>,
}
#[cfg(feature = "spat")]
#[derive(Debug, PartialEq, Eq)]
pub struct GlosaFound {
pub intersection_id: u16,
pub approach_id: Option<u8>,
}
#[cfg(feature = "spat")]
impl From<&TlData> for GlosaFound {
fn from(value: &TlData) -> Self {
Self {
intersection_id: value.intersection_id,
approach_id: value.approach_id,
}
}
}
#[cfg(feature = "spat")]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GlosaSignalInfo {
pub intersection_id: u16,
pub signal_groups: Vec<SignalGroupData>,
}
#[cfg(feature = "spat")]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct SignalGroupData {
pub phase: SignalPhase,
pub maneuver: map::Maneuvers,
@ -73,7 +112,7 @@ pub struct SignalGroupData {
}
#[cfg(feature = "spat")]
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub enum SignalPhase {
#[default]
Unknown,
@ -212,17 +251,20 @@ impl State {
}
#[cfg(feature = "spat")]
pub fn run_glosa(&mut self) -> Vec<SignalGroupData> {
pub fn run_glosa(&mut self) -> GlosaOutput {
let Some(own_heading) = self.heading_deg else {
return alloc::vec![];
use alloc::string::ToString;
return GlosaOutput::Error("Heading unknown".to_string());
};
let (state_update, sig_grps) = match &self.glosa_state {
let known_intersection_ids = self.tlc_cache.known_intersections();
let (state_update, output_data) = match &self.glosa_state {
// search for upcoming intersection
GlosaState::Idle => {
debug!(
"GLOSA: Searching with {} known intersections",
self.tlc_cache.known_intersections().len()
known_intersection_ids.len()
);
if let Some(search_result) =
@ -233,9 +275,18 @@ impl State {
search_result.signal_groups
);
(Some(GlosaState::Locked(search_result)), None)
let glosa_found_data = (&search_result).into();
(
Some(GlosaState::Locked(search_result)),
GlosaOutput::Found(glosa_found_data),
)
} else {
(None, None)
(
None,
GlosaOutput::Searching(GlosaSearching {
known_intersection_ids,
}),
)
}
}
GlosaState::Locked(info) => {
@ -251,7 +302,12 @@ impl State {
.is_err()
{
info!("GLOSA: Intersection not known any more");
(Some(GlosaState::Idle), None)
(
Some(GlosaState::Idle),
GlosaOutput::Searching(GlosaSearching {
known_intersection_ids,
}),
)
} else {
// determine if intersection is left
let intersection = info.intersection.borrow();
@ -262,7 +318,12 @@ impl State {
&self.position,
) {
info!("GLOSA: Intersection was left -> back to idle");
(Some(GlosaState::Idle), None)
(
Some(GlosaState::Idle),
GlosaOutput::Searching(GlosaSearching {
known_intersection_ids,
}),
)
} else {
// get signal groups which are in our approach
let mut approach_sig_grps = intersection
@ -317,7 +378,13 @@ impl State {
})
.collect::<Vec<_>>();
(None, Some(sig_grps)) // keep state, return signal groups
(
None,
GlosaOutput::Locked(GlosaSignalInfo {
intersection_id: intersection.id(),
signal_groups: sig_grps,
}),
) // keep state, return signal groups
}
}
}
@ -328,7 +395,7 @@ impl State {
self.glosa_state = new;
}
sig_grps.unwrap_or_default()
output_data
}
#[cfg(feature = "spat")]