12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- use serde::{Deserialize, Serialize};
- use std::sync::OnceLock;
- //全局配置
- pub static APP_CONFIG: OnceLock<AppConfig> = OnceLock::new();
- #[inline]
- pub fn app_config() -> &'static AppConfig {
- APP_CONFIG.get().expect("配置尚未加载")
- }
- #[derive(Debug, Serialize, Deserialize)]
- pub struct AppConfig {
- pub emu: EmuConfig,
- pub rabbitmq: RabbitMQConfig,
- pub mqtt: MqttConfig,
- pub log: LogConfig,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct EmuConfig {
- pub ver: String,
- pub pcs: PcsConfig,
- pub ems: EmsConfig,
- pub bms: BmsConfig,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct PcsConfig {
- pub host: String,
- pub port: u16,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct EmsConfig {
- //读取间隔, 单位ms
- pub read_interval: u64,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct BmsConfig {
- pub name: String,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct RabbitMQConfig {
- pub host: String,
- pub port: u16,
- pub username: String,
- pub password: String,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct LogConfig {
- pub path: String,
- }
- #[derive(Serialize, Deserialize, Debug)]
- pub struct MqttConfig {
- pub host: String,
- pub port: u16,
- pub username: String,
- pub password: String,
- }
|