Skip to content

Commit

Permalink
hoxfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kistenklaus committed Nov 18, 2023
1 parent 728861c commit fcba743
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
51 changes: 50 additions & 1 deletion src-tauri/src/can/can/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,56 @@ pub enum CanModule {
CAN1,
}

pub enum Can {
SocketCan(CAN),
MockCan(MockCan),
}

impl Can {
pub async fn send(&self, frame: CanFrame) {
match &self {
Can::SocketCan(can) => can.send(frame),
Can::MockCan(mock_can) => todo!(),
}
}

pub async fn receive(&self) -> Result<CanFrame, CanError> {
match &self {
Can::SocketCan(can) => can.receive(),
Can::MockCan(mock_can) => todo!(),
}
}

pub async fn receive_err(&mut self) -> CanError {
match &self {
Can::SocketCan(can) => can.receive_err(),
Can::MockCan(mock_can) => todo!(),
}

}

pub struct MockCan {
network_ref : config::NetworkRef,

}

impl MockCan {
pub fn create(network_ref : &config::NetworkRef) -> Self{
Self {
network_ref : network_ref.clone(),
}
}
pub async fn send(&self, frame : CanFrame) {
println!("mock-can : sending : {frame:?}");
}
pub async fn receive(&self) -> Result<CanFrame, CanError> {

}
pub async fn receive_err(&mut self) -> CanError {

}
}

pub struct CAN {
socket: OwnedCanSocket,
rx: Mutex<Receiver<CanFrame>>,
Expand Down Expand Up @@ -59,7 +109,6 @@ impl CAN {

Ok(CAN { tx : txtx, socket, rx : Mutex::new(rx), err_rx : Mutex::new(err_rx) })
}

pub async fn send(&self, frame: CanFrame) {
self.tx.send(frame).await.expect("failed to forward canframe to can module for transmission");
}
Expand Down
46 changes: 13 additions & 33 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ use rand::{rngs::StdRng, Rng, SeedableRng};
use std::time::Duration;
use tauri::Manager;

use crate::{serialize::serialized_frame::SerializedFrame, can::CNL};

mod can;
mod serialize;

#[tauri::command]
fn emergency() {
println!("Emergency")
Expand All @@ -34,7 +29,20 @@ fn connect_pod() {
//TODO: connect_pod behaviour
}


fn main() {
tauri::Builder::default()
.setup(|app| {
random_integer(app.handle());
Ok(())
})
.invoke_handler(tauri::generate_handler![emergency, launch_pod, land_pod, connect_pod])
.run(tauri::generate_context!())
.expect("Error while running tauri application");
}

fn random_integer(app_handle: tauri::AppHandle) {

tauri::async_runtime::spawn(async move {
let mut rng = {
let rng = rand::thread_rng();
Expand All @@ -48,31 +56,3 @@ fn random_integer(app_handle: tauri::AppHandle) {
}
});
}

fn main() {
println!("Hello, World!");
// setup tauri
tauri::Builder::default()
.setup(|app| {
println!("Hello, Tauri!");
let app_handle = app.handle();
tauri::async_runtime::spawn(async move {
// read config
let network =
can_yaml_config_rs::parse_yaml_config_from_file("./test.yaml").unwrap();
// start CaNetwork Layer
let mut cnl = CNL::create(&network);
cnl.start();

loop {
let frame = cnl.get_rx_message_receiver().recv().await.unwrap();
app_handle
.emit_all("rx-frame", SerializedFrame::from(frame))
.unwrap();
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

0 comments on commit fcba743

Please sign in to comment.