#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "std")]
pub mod aircraft_json;
#[cfg(feature = "verify")]
pub mod auth;
pub mod ble;
pub mod drip;
mod error;
pub mod france;
pub mod geo;
mod message;
mod pack;
pub mod ridf;
#[cfg(feature = "std")]
mod tracker;
pub mod trust;
mod uas;
pub mod wifi;
pub use error::Error;
pub use message::*;
pub use pack::{MessagePack, MessagePackBuilder, PACK_MAX_MESSAGES};
#[cfg(feature = "std")]
pub use tracker::{CounterStats, TrackedUas, Tracker, TrackerConfig};
pub use trust::{Assessment, Observation, Reason, TrustConfig, TrustState, Verdict};
pub use uas::UasData;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Transmitter {
Ble([u8; 6]),
Wifi([u8; 6]),
Other(u64),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
pub enum Transport {
#[default]
Unknown = 0,
Bluetooth4 = 1,
Bluetooth5 = 2,
WifiBeacon = 3,
WifiNan = 4,
Other = 5,
}
impl Transport {
pub const ALL: [Transport; 6] = [
Transport::Unknown,
Transport::Bluetooth4,
Transport::Bluetooth5,
Transport::WifiBeacon,
Transport::WifiNan,
Transport::Other,
];
pub fn code(self) -> u8 {
self as u8
}
pub fn from_code(c: u8) -> Transport {
Transport::ALL
.get(c as usize)
.copied()
.unwrap_or(Transport::Unknown)
}
pub fn name(self) -> &'static str {
match self {
Transport::Unknown => "unknown",
Transport::Bluetooth4 => "bt4",
Transport::Bluetooth5 => "bt5",
Transport::WifiBeacon => "wifi_beacon",
Transport::WifiNan => "wifi_nan",
Transport::Other => "other",
}
}
pub fn from_name(s: &str) -> Option<Transport> {
Transport::ALL.iter().copied().find(|t| t.name() == s)
}
}
impl core::fmt::Display for Transport {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.name())
}
}
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;
pub const MESSAGE_SIZE: usize = 25;
pub const PROTOCOL_VERSION: u8 = 2;
#[derive(Debug, Clone, PartialEq)]
pub enum Frame<'a> {
Message(Message),
Pack(MessagePack<'a>),
}
impl<'a> Frame<'a> {
pub fn decode(payload: &'a [u8]) -> Result<Self, Error> {
let first = *payload.first().ok_or(Error::TooShort { need: 1, got: 0 })?;
if first >> 4 == 0xF {
MessagePack::parse(payload).map(Frame::Pack)
} else {
Message::decode(payload).map(Frame::Message)
}
}
pub fn for_each_message(&self, mut f: impl FnMut(Message)) {
match self {
Frame::Message(m) => f(m.clone()),
Frame::Pack(p) => p.messages().filter_map(Result::ok).for_each(f),
}
}
}