diff --git a/config/system_config.json b/config/system_config.json index efcebd9..d63542a 100644 --- a/config/system_config.json +++ b/config/system_config.json @@ -126,6 +126,10 @@ "warning_interval_ms": 1000, "log_interval_ms": 3000 }, + "frontend_http_server": { + "port": 8081, + "max_connections": 50 + }, "websocket": { "port": 8010, "max_connections": 100, diff --git a/src/config/SystemConfig.h b/src/config/SystemConfig.h index d673c48..9e1e646 100644 --- a/src/config/SystemConfig.h +++ b/src/config/SystemConfig.h @@ -90,6 +90,12 @@ public: int log_interval_ms; } warning; + // 前端交互 HTTP 服务器配置(ConfigHttpServer) + struct FrontendHttpServerConfig { + uint16_t port = 8090; + int max_connections = 50; + } frontend_http_server; + // 新增: 红绿灯 HTTP 服务器配置 struct TrafficLightServerConfig { uint16_t port = 8082; // Default port if not specified in config @@ -249,6 +255,18 @@ inline void from_json(const json& j, SystemConfig::Warning& p) { j.at("log_interval_ms").get_to(p.log_interval_ms); } +inline void to_json(json& j, const SystemConfig::FrontendHttpServerConfig& p) { + j = json{ + {"port", p.port}, + {"max_connections", p.max_connections} + }; +} + +inline void from_json(const json& j, SystemConfig::FrontendHttpServerConfig& p) { + p.port = j.value("port", static_cast(8090)); + p.max_connections = j.value("max_connections", 50); +} + // 新增: TrafficLightServerConfig 的 JSON 序列化/反序列化函数 inline void to_json(json& j, const SystemConfig::TrafficLightServerConfig& p) { j = json{ @@ -274,6 +292,7 @@ inline void to_json(json& j, const SystemConfig& config) { {"logging", config.logging}, {"debug", config.debug}, {"warning", config.warning}, + {"frontend_http_server", config.frontend_http_server}, {"traffic_light_server", config.traffic_light_server}, {"simulated_mobile_light_target_intersection_id", config.simulated_mobile_light_target_intersection_id} }; @@ -287,6 +306,7 @@ inline void from_json(const json& j, SystemConfig& config) { j.at("logging").get_to(config.logging); j.at("debug").get_to(config.debug); j.at("warning").get_to(config.warning); + config.frontend_http_server = j.value("frontend_http_server", SystemConfig::FrontendHttpServerConfig{}); config.traffic_light_server = j.value("traffic_light_server", SystemConfig::TrafficLightServerConfig{}); config.simulated_mobile_light_target_intersection_id = j.value("simulated_mobile_light_target_intersection_id", std::string("T2路口")); } diff --git a/src/core/System.cpp b/src/core/System.cpp index 0b102c9..5c378b4 100644 --- a/src/core/System.cpp +++ b/src/core/System.cpp @@ -54,11 +54,12 @@ bool System::initialize() { ws_thread_ = std::thread([this]() { ws_server_->start(); }); Logger::info("WebSocket server initialized on port ", system_config.websocket.port); - // 前端动态配置接口(HTTP) - // POST http://:8090/config/runway/warning_zone_radius/aircraft {"value": 300} + // 前端交互接口(HTTP) + // - POST http://:/config/runway/warning_zone_radius/aircraft {"value": 300} + // - POST http://:/api/VehicleRegistry [...] config_http_server_ = std::make_unique( - static_cast(8090), - 50, + system_config.frontend_http_server.port, + system_config.frontend_http_server.max_connections, *this); config_http_server_->start(1); diff --git a/~$信息_20251107.docx b/~$信息_20251107.docx new file mode 100644 index 0000000..dd563d7 Binary files /dev/null and b/~$信息_20251107.docx differ