可恢复版本,开发验证了和前端交互的接口还有配置文件
This commit is contained in:
parent
aade3009e1
commit
1063d3eb5c
@ -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,
|
||||
|
||||
@ -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<uint16_t>(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路口"));
|
||||
}
|
||||
|
||||
@ -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://<host>:8090/config/runway/warning_zone_radius/aircraft {"value": 300}
|
||||
// 前端交互接口(HTTP)
|
||||
// - POST http://<host>:<port>/config/runway/warning_zone_radius/aircraft {"value": 300}
|
||||
// - POST http://<host>:<port>/api/VehicleRegistry [...]
|
||||
config_http_server_ = std::make_unique<network::ConfigHttpServer>(
|
||||
static_cast<uint16_t>(8090),
|
||||
50,
|
||||
system_config.frontend_http_server.port,
|
||||
system_config.frontend_http_server.max_connections,
|
||||
*this);
|
||||
config_http_server_->start(1);
|
||||
|
||||
|
||||
BIN
~$信息_20251107.docx
Normal file
BIN
~$信息_20251107.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user