Procházet zdrojové kódy

【框架搭建】增加类图

yuanan před 2 měsíci
rodič
revize
d909592fe8
4 změnil soubory, kde provedl 41 přidání a 4 odebrání
  1. 3 0
      emu-config.yaml
  2. 24 0
      readme.md
  3. 7 1
      src/cmd/config.rs
  4. 7 3
      src/ems/pcs/pcs.rs

+ 3 - 0
emu-config.yaml

@@ -1,4 +1,7 @@
 emu:
   ver: '0.0.1'
   pcs:
+  bms:
   ems:
+    # 读取间隔
+    read_interval: 1000

+ 24 - 0
readme.md

@@ -0,0 +1,24 @@
+#### 系统类图
+
+```mermaid
+classDiagram
+    class Service {
+        +run() Result~JoinHandle~
+    }
+    <<interface>> Service
+    class Pcs {
+        +new() Pcs
+        +run() Result~JoinHandle~
+    }
+    class Bms {
+        +new() Bms
+        +run() Result~JoinHandle~
+    }
+    Pcs ..|> Service
+    Bms ..|> Service
+    class Ems {
+        +devices: Vec~Service~
+        +start_services() Result
+    }
+    Ems *-- Service
+```

+ 7 - 1
src/cmd/config.rs

@@ -14,9 +14,15 @@ pub struct EmuConfig {
     pub ver: String,
     pub pcs: PcsConfig,
     pub ems: EmsConfig,
+    pub bms: BmsConfig,
 }
 
 #[derive(Serialize, Deserialize, Debug)]
 pub struct PcsConfig {}
 #[derive(Serialize, Deserialize, Debug)]
-pub struct EmsConfig {}
+pub struct EmsConfig {
+    //读取间隔, 单位ms
+    pub read_interval: u64,
+}
+#[derive(Serialize, Deserialize, Debug)]
+pub struct BmsConfig {}

+ 7 - 3
src/ems/pcs/pcs.rs

@@ -1,8 +1,8 @@
+use crate::cmd::config::EMU_CONFIG;
 use crate::ems::service::Service;
 use anyhow::Error;
 use std::time::Duration;
 use tokio::task::JoinHandle;
-use tokio::time::sleep;
 
 pub struct Pcs {}
 
@@ -12,14 +12,18 @@ impl Pcs {
         println!("PCS初始化成功");
         Pcs {}
     }
+
+    // pub fn read(&self){
+    //
+    // }
 }
 
 impl Service for Pcs {
     fn run(&self) -> Result<JoinHandle<()>, Error> {
         let handle = tokio::spawn(async {
+            let emu_config = EMU_CONFIG.get();
             loop {
-                println!("pcs");
-                tokio::time::sleep(Duration::from_secs(1)).await;
+                tokio::time::sleep(Duration::from_millis(1)).await;
             }
         });
         Ok(handle)