|
@@ -1,6 +1,143 @@
|
|
|
+// use async_trait::async_trait;
|
|
|
+// use std::{sync::Arc, time::Duration};
|
|
|
+// use tokio::{
|
|
|
+// sync::{broadcast, mpsc},
|
|
|
+// time,
|
|
|
+// };
|
|
|
+//
|
|
|
+// #[async_trait]
|
|
|
+// trait Service: Send + Sync {
|
|
|
+// async fn serve(
|
|
|
+// self: Arc<Self>,
|
|
|
+// output_tx: broadcast::Sender<String>,
|
|
|
+// input_rx: mpsc::Receiver<String>,
|
|
|
+// );
|
|
|
+// }
|
|
|
+//
|
|
|
+// struct Pcs;
|
|
|
+//
|
|
|
+// impl Pcs {
|
|
|
+// fn new() -> Self {
|
|
|
+// Pcs
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// #[async_trait]
|
|
|
+// impl Service for Pcs {
|
|
|
+// async fn serve(
|
|
|
+// self: Arc<Self>,
|
|
|
+// output_tx: broadcast::Sender<String>,
|
|
|
+// mut input_rx: mpsc::Receiver<String>,
|
|
|
+// ) {
|
|
|
+// // 消息发送任务
|
|
|
+// let send_task = tokio::spawn({
|
|
|
+// let output_tx = output_tx.clone();
|
|
|
+// async move {
|
|
|
+// loop {
|
|
|
+// time::sleep(Duration::from_secs(2)).await;
|
|
|
+// let _ = output_tx.send("我是PCS".to_string());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 消息处理任务
|
|
|
+// let handle_task = tokio::spawn(async move {
|
|
|
+// while let Some(msg) = input_rx.recv().await {
|
|
|
+// println!("回复: {}", msg);
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// let _ = tokio::join!(send_task, handle_task);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// struct Bms;
|
|
|
+//
|
|
|
+// impl Bms {
|
|
|
+// fn new() -> Self {
|
|
|
+// Bms
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// #[async_trait]
|
|
|
+// impl Service for Bms {
|
|
|
+// async fn serve(
|
|
|
+// self: Arc<Self>,
|
|
|
+// output_tx: broadcast::Sender<String>,
|
|
|
+// _input_rx: mpsc::Receiver<String>,
|
|
|
+// ) {
|
|
|
+// tokio::spawn(async move {
|
|
|
+// loop {
|
|
|
+// time::sleep(Duration::from_secs(2)).await;
|
|
|
+// let _ = output_tx.send("我是BMS".to_string());
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .await
|
|
|
+// .unwrap();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// struct Emu {
|
|
|
+// outputs: Vec<broadcast::Receiver<String>>,
|
|
|
+// inputs: Vec<mpsc::Sender<String>>,
|
|
|
+// }
|
|
|
+//
|
|
|
+// impl Emu {
|
|
|
+// fn new() -> Self {
|
|
|
+// // 初始化PCS
|
|
|
+// let (pcs_output_tx, pcs_output_rx) = broadcast::channel(32);
|
|
|
+// let (pcs_input_tx, pcs_input_rx) = mpsc::channel(32);
|
|
|
+// let pcs = Arc::new(Pcs::new());
|
|
|
+// tokio::spawn(pcs.clone().serve(pcs_output_tx, pcs_input_rx));
|
|
|
+//
|
|
|
+// // 初始化BMS
|
|
|
+// let (bms_output_tx, bms_output_rx) = broadcast::channel(32);
|
|
|
+// let (bms_input_tx, bms_input_rx) = mpsc::channel(32);
|
|
|
+// let bms = Arc::new(Bms::new());
|
|
|
+// tokio::spawn(bms.clone().serve(bms_output_tx, bms_input_rx));
|
|
|
+//
|
|
|
+// Emu {
|
|
|
+// outputs: vec![pcs_output_rx, bms_output_rx],
|
|
|
+// inputs: vec![pcs_input_tx, bms_input_tx],
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// async fn start_server(&mut self) {
|
|
|
+// // 处理输出消息
|
|
|
+// for rx in &mut self.outputs {
|
|
|
+// let mut rx = rx.resubscribe();
|
|
|
+// tokio::spawn(async move {
|
|
|
+// while let Ok(msg) = rx.recv().await {
|
|
|
+// println!("{}", msg);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 模拟发送消息到PCS
|
|
|
+// let pcs_input = self.inputs[0].clone();
|
|
|
+// tokio::spawn(async move {
|
|
|
+// loop {
|
|
|
+// time::sleep(Duration::from_secs(3)).await;
|
|
|
+// pcs_input.send("你好".to_string()).await.unwrap();
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 等待Ctrl-C
|
|
|
+// tokio::signal::ctrl_c().await.unwrap();
|
|
|
+// println!("EMU系统关闭");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// #[tokio::main]
|
|
|
+// async fn main() {
|
|
|
+// println!("EMU系统启动");
|
|
|
+// let mut emu = Emu::new();
|
|
|
+// emu.start_server().await;
|
|
|
+// }
|
|
|
+
|
|
|
use inpower_iot_mgc_rs::cmd::cmd::cmd;
|
|
|
|
|
|
#[tokio::main]
|
|
|
async fn main() {
|
|
|
cmd().await;
|
|
|
-}
|
|
|
+}
|