Skip to content

Commit

Permalink
ts models for vue
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Jul 19, 2024
1 parent 31f95ca commit 2ad2297
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
21 changes: 17 additions & 4 deletions src/device/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceActorRequest>,
Expand Down Expand Up @@ -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),
Expand All @@ -281,7 +282,7 @@ pub enum PingRequest {
Stop,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
pub enum Ping1DRequest {
DeviceID,
ModeAuto,
Expand All @@ -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),
}

Expand Down
16 changes: 9 additions & 7 deletions src/device/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -41,15 +42,15 @@ impl Device {
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub enum DeviceSelection {
Common,
Ping1D,
Ping360,
Auto,
}

#[derive(Debug, Clone, Deserialize, Serialize, Hash)]
#[derive(Debug, Clone, Deserialize, Serialize, Hash, TS)]
pub enum SourceSelection {
UdpStream(SourceUdpStruct),
SerialStream(SourceSerialStruct),
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down

0 comments on commit 2ad2297

Please sign in to comment.