Skip to content

Commit

Permalink
src: device: Integrations required for restAPI and websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin authored and patrickelectric committed Jul 29, 2024
1 parent 09c0fc8 commit a455550
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/device/manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use paperclip::actix::Apiv2Schema;
use serde::{Deserialize, Serialize};
use std::{
collections::{hash_map::DefaultHasher, HashMap},
Expand Down Expand Up @@ -59,13 +60,13 @@ enum SourceType {
Serial(SerialStream),
}

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

#[derive(Clone, Debug, Deserialize, Serialize, Hash)]
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Apiv2Schema)]
pub struct SourceSerialStruct {
pub path: String,
pub baudrate: u32,
Expand All @@ -92,9 +93,9 @@ pub struct ManagerActorHandler {
pub sender: mpsc::Sender<ManagerActorRequest>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Apiv2Schema)]
pub enum Answer {
Ping(PingAnswer),
DeviceMessage(DeviceAnswer),
#[serde(skip)]
InnerDeviceHandler(DeviceActorHandler),
DeviceInfo(Vec<DeviceInfo>),
Expand All @@ -113,12 +114,13 @@ pub enum ManagerError {
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PingAnswer {
pub answer: Result<crate::device::devices::PingAnswer, crate::device::devices::DeviceError>,
pub struct DeviceAnswer {
#[serde(flatten)]
pub answer: crate::device::devices::PingAnswer,
pub device_id: Uuid,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Apiv2Schema)]
pub enum Request {
Create(CreateStruct),
Delete(Uuid),
Expand Down Expand Up @@ -410,8 +412,8 @@ impl ManagerActorHandler {
match result {
Ok(result) => {
info!("Handling Ping request: {request:?}: Success");
Ok(Answer::Ping(PingAnswer {
answer: Ok(result),
Ok(Answer::DeviceMessage(DeviceAnswer {
answer: result,
device_id: request.target,
}))
}
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ async fn main() {
//Todo: Load previous devices
info!(
"DeviceManager initialized with following devices: {:?}",
handler
.send(crate::device::manager::Request::List {})
.await
.unwrap()
handler.send(crate::device::manager::Request::List).await
);

server::manager::run(&cli::manager::server_address())
server::manager::run(&cli::manager::server_address(), handler)
.await
.unwrap();
}

0 comments on commit a455550

Please sign in to comment.