#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(test)]
extern crate alloc;
mod manager;
mod policy;
mod reportable;
use core::fmt;
use kinavis_kernel::event::{NavigationIntegrity, PositionSource, SensorId, TargetId};
use kinavis_kernel::time::{Instant, Utc};
pub use manager::{AlertChange, AlertChanges, AlertManager, MAX_ALERTS, MAX_CHANGES};
pub use policy::{AlertPolicy, StandardPolicy};
pub use reportable::Reportable;
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadmeExamples;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AlertPriority {
Caution,
Warning,
Alarm,
EmergencyAlarm,
}
impl fmt::Display for AlertPriority {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Caution => "caution",
Self::Warning => "warning",
Self::Alarm => "alarm",
Self::EmergencyAlarm => "emergency alarm",
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AlertState {
Active,
Acknowledged,
Rectified,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AlertKind {
CrossTrackExceeded,
UnderKeelClearanceLow,
AnchorDragging,
Cpa {
target: TargetId,
},
TargetLost {
target: TargetId,
},
FixLost {
source: PositionSource,
},
IntegrityDegraded {
to: NavigationIntegrity,
},
SensorSuspect {
sensor: SensorId,
},
ObservationRejected,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Ended {
Nothing,
One(AlertKind),
EveryIntegrityDegradation,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AlertId(u32);
impl AlertId {
#[must_use]
pub const fn number(self) -> u32 {
self.0
}
}
impl fmt::Display for AlertId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "A{}", self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Alert {
id: AlertId,
kind: AlertKind,
priority: AlertPriority,
state: AlertState,
raised_at: Instant<Utc>,
last_reported_at: Instant<Utc>,
occurrences: u32,
}
impl Alert {
#[must_use]
pub const fn id(&self) -> AlertId {
self.id
}
#[must_use]
pub const fn kind(&self) -> AlertKind {
self.kind
}
#[must_use]
pub const fn priority(&self) -> AlertPriority {
self.priority
}
#[must_use]
pub const fn state(&self) -> AlertState {
self.state
}
#[must_use]
pub const fn raised_at(&self) -> Instant<Utc> {
self.raised_at
}
#[must_use]
pub const fn last_reported_at(&self) -> Instant<Utc> {
self.last_reported_at
}
#[must_use]
pub const fn occurrences(&self) -> u32 {
self.occurrences
}
}