config_loader.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <string>
  3. #include <fstream>
  4. #include "json.hpp"
  5. #include "rfid_client.h"
  6. #include "modbus_client.h"
  7. #include "bucket_manager.h"
  8. using json = nlohmann::json;
  9. struct AppConfig {
  10. // 应用信息
  11. std::string app_name = "钢包工位视频监测系统";
  12. // 通讯模块
  13. std::string module_type = "RFID"; // "RFID" 或 "Modbus"
  14. RfidConfig rfid;
  15. ModbusConfig modbus;
  16. // 视频
  17. float rtsp_timeout = 10.0f;
  18. // 空闲超时
  19. int idle_timeout = 5;
  20. // 自动重启
  21. bool auto_reboot_enabled = false;
  22. int auto_reboot_cycle = 1;
  23. std::string auto_reboot_time = "03:30";
  24. // Web
  25. int web_port = 8080;
  26. std::string web_username = "admin";
  27. std::string web_password = "admin";
  28. };
  29. class ConfigLoader {
  30. public:
  31. static json loadJson(const std::string& path);
  32. static void saveJson(const std::string& path, const json& j);
  33. static AppConfig loadConfig(const std::string& path);
  34. static void saveConfig(const std::string& path, const AppConfig& cfg, const json& buckets);
  35. };