use std::time::Duration;
use crate::precedence::ModePrecedence;
use crate::setpoint::Setpoint;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SwarmMode {
#[default]
Hold,
Flocking,
Formation,
}
impl SwarmMode {
pub const fn as_wire(self) -> &'static str {
match self {
Self::Hold => "hold",
Self::Flocking => "flocking",
Self::Formation => "formation",
}
}
pub fn from_wire(s: &str) -> Self {
match s.trim().to_ascii_lowercase().as_str() {
"flocking" => Self::Flocking,
"formation" => Self::Formation,
_ => Self::Hold,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum OperatorDirective {
Goto {
lat_deg: f64,
lon_deg: f64,
alt_m: f64,
},
Hold,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct OwnState {
pub slot: u8,
pub lat_deg: f64,
pub lon_deg: f64,
pub alt_rel_m: f64,
pub vn: f64,
pub ve: f64,
pub vd: f64,
pub armed: bool,
pub guided: bool,
pub fix_age: Option<Duration>,
}
impl Default for OwnState {
fn default() -> Self {
Self {
slot: 1,
lat_deg: 0.0,
lon_deg: 0.0,
alt_rel_m: 0.0,
vn: 0.0,
ve: 0.0,
vd: 0.0,
armed: false,
guided: false,
fix_age: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct NeighborFix {
pub slot: u8,
pub lat_deg: f64,
pub lon_deg: f64,
pub alt_m: f64,
pub vn: f64,
pub ve: f64,
pub vd: f64,
pub status: u8,
pub sender_order: std::cmp::Ordering,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Suppression {
Disabled,
NeighborsStale,
NotArmed,
NotGuided,
OwnStateStale,
NothingToDo,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ControlOutcome {
pub setpoint: Option<Setpoint>,
pub precedence: ModePrecedence,
pub emergency: bool,
pub suppressed: Option<Suppression>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct SwarmControlCounters {
pub setpoints_emitted: u64,
pub ticks_suppressed: u64,
pub hard_engagements: u64,
}