use alloc::{boxed::Box, string::String, vec::Vec};
use serde::{Deserialize, Serialize};
#[cfg(feature = "schemars")]
use schemars::JsonSchema;
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct Point {
pub quality: u8,
pub angle_rad: f32,
pub distance_mm: f32,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct WheelJointState {
pub effort_percent: f32,
pub velocity_rad_per_s: f32,
pub position_rad: f32,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct DriveBaseState {
pub left: WheelJointState,
pub right: WheelJointState,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct ImuAxisTriple {
pub x: f32,
pub y: f32,
pub z: f32,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct ImuMeasurement {
pub accel: ImuAxisTriple,
pub gyro: ImuAxisTriple,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub struct NetworkConnection {
pub ssid: String,
pub strength: u8,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BitResult {
Waiting,
Pass,
Fail,
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub struct Bit {
pub name: String,
pub result: BitResult,
}
pub type BitList = Vec<Bit>;
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub struct BitCollection {
pub power: BitList,
pub wifi: BitList,
pub lidar: BitList,
pub imu: BitList,
pub encoders: BitList,
}
impl BitCollection {
pub const fn new() -> Self {
Self {
power: Vec::new(),
wifi: Vec::new(),
lidar: Vec::new(),
imu: Vec::new(),
encoders: Vec::new(),
}
}
}
pub type Uid = String;
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConnectionError {
Timeout,
AuthOrRefused,
Other(String),
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub struct State {
pub uid: Uid,
pub ip: Option<String>,
pub mac: Option<String>,
pub current_network_connection: Option<Result<String, ConnectionError>>,
pub available_network_connections: Vec<NetworkConnection>,
pub built_in_test: BitCollection,
}
impl State {
pub const fn new() -> Self {
Self {
uid: Uid::new(),
ip: None,
mac: None,
current_network_connection: None,
available_network_connections: Vec::new(),
built_in_test: BitCollection::new(),
}
}
}
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Message {
Ping,
Pong,
Scan(Vec<Point>),
DriveBaseState(DriveBaseState),
ImuMeasurement(ImuMeasurement),
State(Box<State>),
}