diff --git a/Cargo.toml b/Cargo.toml index 8c98cbb5..58fce26a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ udp-stream = "0.0.12" uuid = { version = "1.8", features = ["serde"] } validator = "0.18.1" thiserror = "1.0.61" +ts-rs = { version = "9.0.1" , features = ["serde-compat", "uuid-impl"] } [build-dependencies] vergen-gix = { version = "1.0.0-beta.2", default-features = false, features = ["build", "cargo"] } diff --git a/src/device/devices.rs b/src/device/devices.rs index 2434902e..a7f470ed 100644 --- a/src/device/devices.rs +++ b/src/device/devices.rs @@ -2,6 +2,7 @@ use bluerobotics_ping::device::PingDevice; use serde::{Deserialize, Serialize}; use tokio::sync::{mpsc, oneshot}; use tracing::{error, trace, warn}; +use ts_rs::TS; pub struct DeviceActor { pub receiver: mpsc::Receiver, @@ -271,7 +272,7 @@ pub enum UpgradeResult { Ping360, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub enum PingRequest { Ping1D(Ping1DRequest), Ping360(Ping360Request), @@ -281,7 +282,7 @@ pub enum PingRequest { Stop, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub enum Ping1DRequest { DeviceID, ModeAuto, @@ -300,33 +301,45 @@ pub enum Ping1DRequest { GainSetting, PingEnable, DistanceSimple, + #[ts(skip)] SetDeviceId(bluerobotics_ping::ping1d::SetDeviceIdStruct), + #[ts(skip)] SetModeAuto(bluerobotics_ping::ping1d::SetModeAutoStruct), + #[ts(skip)] SetPingInterval(bluerobotics_ping::ping1d::SetPingIntervalStruct), + #[ts(skip)] SetPingEnable(bluerobotics_ping::ping1d::SetPingEnableStruct), + #[ts(skip)] SetSpeedOfSound(bluerobotics_ping::ping1d::SetSpeedOfSoundStruct), + #[ts(skip)] SetRange(bluerobotics_ping::ping1d::SetRangeStruct), + #[ts(skip)] SetGainSetting(bluerobotics_ping::ping1d::SetGainSettingStruct), + #[ts(skip)] ContinuousStart(bluerobotics_ping::ping1d::ContinuousStartStruct), + #[ts(skip)] ContinuousStop(bluerobotics_ping::ping1d::ContinuousStopStruct), + #[ts(skip)] GotoBootloader(bluerobotics_ping::ping1d::GotoBootloaderStruct), } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub enum Ping360Request { MotorOff, DeviceData, AutoDeviceData, + #[ts(skip)] SetDeviceId(bluerobotics_ping::ping1d::SetDeviceIdStruct), Transducer, Reset, AutoTransmit, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub enum PingCommonRequest { DeviceInformation, ProtocolVersion, + #[ts(skip)] SetDeviceId(bluerobotics_ping::common::SetDeviceIdStruct), } diff --git a/src/device/manager.rs b/src/device/manager.rs index 2b0982b5..79f3e64d 100644 --- a/src/device/manager.rs +++ b/src/device/manager.rs @@ -8,6 +8,7 @@ use std::{ use tokio::sync::{mpsc, oneshot}; use tokio_serial::{SerialPort, SerialPortBuilderExt, SerialStream}; use tracing::{error, info, trace}; +use ts_rs::TS; use udp_stream::UdpStream; use uuid::Uuid; @@ -41,7 +42,7 @@ impl Device { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)] pub enum DeviceSelection { Common, Ping1D, @@ -49,7 +50,7 @@ pub enum DeviceSelection { Auto, } -#[derive(Debug, Clone, Deserialize, Serialize, Hash)] +#[derive(Debug, Clone, Deserialize, Serialize, Hash, TS)] pub enum SourceSelection { UdpStream(SourceUdpStruct), SerialStream(SourceSerialStruct), @@ -60,13 +61,13 @@ enum SourceType { Serial(SerialStream), } -#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)] +#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema, TS)] pub struct SourceUdpStruct { pub ip: Ipv4Addr, pub port: u16, } -#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)] +#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema, TS)] pub struct SourceSerialStruct { pub path: String, pub baudrate: u32, @@ -119,7 +120,8 @@ pub struct DeviceAnswer { pub device_id: Uuid, } -#[derive(Debug, Clone, Serialize, Deserialize, Apiv2Schema)] +#[derive(Debug, Clone, Serialize, Deserialize, Apiv2Schema, TS)] +#[ts(export, export_to = "RequestModels.ts")] pub enum Request { Create(CreateStruct), Delete(Uuid), @@ -130,13 +132,13 @@ pub enum Request { GetDeviceHandler(Uuid), } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub struct CreateStruct { pub source: SourceSelection, pub device_selection: DeviceSelection, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, TS)] pub struct DeviceRequestStruct { pub target: Uuid, pub request: crate::device::devices::PingRequest,