config.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use serde::{Deserialize, Serialize};
  2. use std::sync::OnceLock;
  3. //全局配置
  4. pub static APP_CONFIG: OnceLock<AppConfig> = OnceLock::new();
  5. #[inline]
  6. pub fn app_config() -> &'static AppConfig {
  7. APP_CONFIG.get().expect("配置尚未加载")
  8. }
  9. #[derive(Debug, Serialize, Deserialize)]
  10. pub struct AppConfig {
  11. pub emu: EmuConfig,
  12. pub rabbitmq: RabbitMQConfig,
  13. pub mqtt: MqttConfig,
  14. pub log: LogConfig,
  15. }
  16. #[derive(Serialize, Deserialize, Debug)]
  17. pub struct EmuConfig {
  18. pub ver: String,
  19. pub pcs: PcsConfig,
  20. pub ems: EmsConfig,
  21. pub bms: BmsConfig,
  22. }
  23. #[derive(Serialize, Deserialize, Debug)]
  24. pub struct PcsConfig {
  25. pub host: String,
  26. pub port: u16,
  27. }
  28. #[derive(Serialize, Deserialize, Debug)]
  29. pub struct EmsConfig {
  30. //读取间隔, 单位ms
  31. pub read_interval: u64,
  32. }
  33. #[derive(Serialize, Deserialize, Debug)]
  34. pub struct BmsConfig {
  35. pub name: String,
  36. }
  37. #[derive(Serialize, Deserialize, Debug)]
  38. pub struct RabbitMQConfig {
  39. pub host: String,
  40. pub port: u16,
  41. pub username: String,
  42. pub password: String,
  43. }
  44. #[derive(Serialize, Deserialize, Debug)]
  45. pub struct LogConfig {
  46. pub path: String,
  47. }
  48. #[derive(Serialize, Deserialize, Debug)]
  49. pub struct MqttConfig {
  50. pub host: String,
  51. pub port: u16,
  52. pub username: String,
  53. pub password: String,
  54. }