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 18, 2024
1 parent 31f95ca commit bb12e35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 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"] }
17 changes: 17 additions & 0 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 @@ -272,6 +273,7 @@ pub enum UpgradeResult {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(TS)]
pub enum PingRequest {
Ping1D(Ping1DRequest),
Ping360(Ping360Request),
Expand All @@ -282,6 +284,7 @@ pub enum PingRequest {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(TS)]
pub enum Ping1DRequest {
DeviceID,
ModeAuto,
Expand All @@ -300,33 +303,47 @@ 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(TS)]
pub enum Ping360Request {
MotorOff,
DeviceData,
AutoDeviceData,
#[ts(skip)]
SetDeviceId(bluerobotics_ping::ping1d::SetDeviceIdStruct),
Transducer,
Reset,
AutoTransmit,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(TS)]
pub enum PingCommonRequest {
DeviceInformation,
ProtocolVersion,
#[ts(skip)]
SetDeviceId(bluerobotics_ping::common::SetDeviceIdStruct),
}

Expand Down
10 changes: 10 additions & 0 deletions src/device/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use paperclip::actix::Apiv2Schema;
use serde::{Deserialize, Serialize};
use ts_rs::TS;
use std::{
collections::{hash_map::DefaultHasher, HashMap},
hash::{Hash, Hasher},
Expand Down Expand Up @@ -42,6 +43,7 @@ impl Device {
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(TS)]
pub enum DeviceSelection {
Common,
Ping1D,
Expand All @@ -50,6 +52,7 @@ pub enum DeviceSelection {
}

#[derive(Debug, Clone, Deserialize, Serialize, Hash)]
#[derive(TS)]
pub enum SourceSelection {
UdpStream(SourceUdpStruct),
SerialStream(SourceSerialStruct),
Expand All @@ -61,12 +64,14 @@ enum SourceType {
}

#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)]
#[derive(TS)]
pub struct SourceUdpStruct {
pub ip: Ipv4Addr,
pub port: u16,
}

#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)]
#[derive(TS)]
pub struct SourceSerialStruct {
pub path: String,
pub baudrate: u32,
Expand Down Expand Up @@ -120,6 +125,9 @@ pub struct DeviceAnswer {
}

#[derive(Debug, Clone, Serialize, Deserialize, Apiv2Schema)]
#[derive(TS)]
// #[ts(rename_all = "lowercase")]
#[ts(export, export_to = "RequestModels.ts")]
pub enum Request {
Create(CreateStruct),
Delete(Uuid),
Expand All @@ -131,12 +139,14 @@ pub enum Request {
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(TS)]
pub struct CreateStruct {
pub source: SourceSelection,
pub device_selection: DeviceSelection,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(TS)]
pub struct DeviceRequestStruct {
pub target: Uuid,
pub request: crate::device::devices::PingRequest,
Expand Down

0 comments on commit bb12e35

Please sign in to comment.