pub use kinavis_kernel::event::{
Event, EventList, NavigationEvent, NavigationIntegrity, PositionSource, RejectionReason,
SensorHealth, SensorId, TargetId, MAX_EVENTS, SENSOR_NAME_BYTES,
};
use kinavis_kernel::position::Position;
use kinavis_kernel::time::{Instant, Utc};
use kinavis_kernel::units::Distance;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum GuidanceEvent {
WaypointReached {
index: u16,
at: Instant<Utc>,
},
WheelOverReached {
index: u16,
wheel_over_at: Position,
at: Instant<Utc>,
},
CrossTrackExceeded {
error: Distance,
limit: Distance,
at: Instant<Utc>,
},
}
impl Event for GuidanceEvent {
const PLACEHOLDER: Self = Self::WaypointReached {
index: 0,
at: Instant::UNIX_EPOCH,
};
fn at(&self) -> Instant<Utc> {
match self {
Self::WaypointReached { at, .. }
| Self::WheelOverReached { at, .. }
| Self::CrossTrackExceeded { at, .. } => *at,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ClearanceEvent {
UnderKeelClearanceLow {
clearance: Distance,
required: Distance,
at: Instant<Utc>,
},
}
impl Event for ClearanceEvent {
const PLACEHOLDER: Self = Self::UnderKeelClearanceLow {
clearance: Distance::ZERO,
required: Distance::ZERO,
at: Instant::UNIX_EPOCH,
};
fn at(&self) -> Instant<Utc> {
match self {
Self::UnderKeelClearanceLow { at, .. } => *at,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AnchorEvent {
AnchorDragging {
distance: Distance,
radius: Distance,
at: Instant<Utc>,
},
}
impl Event for AnchorEvent {
const PLACEHOLDER: Self = Self::AnchorDragging {
distance: Distance::ZERO,
radius: Distance::ZERO,
at: Instant::UNIX_EPOCH,
};
fn at(&self) -> Instant<Utc> {
match self {
Self::AnchorDragging { at, .. } => *at,
}
}
}
#[cfg(test)]
#[allow(clippy::indexing_slicing)]
mod tests {
use super::*;
#[test]
fn each_context_lists_its_own_events() {
let at = Instant::from_unix_seconds(1_789_000_000);
let mut passage = EventList::<GuidanceEvent>::new();
passage.push(GuidanceEvent::WaypointReached { index: 3, at });
assert_eq!(passage.len(), 1);
assert_eq!(passage[0].at(), at);
let mut anchor = EventList::<AnchorEvent, 2>::with_capacity();
anchor.push(AnchorEvent::AnchorDragging {
distance: Distance::ZERO,
radius: Distance::ZERO,
at,
});
assert_eq!(anchor.as_slice()[0].at(), at);
assert!(!anchor.overflowed());
}
}