From 3463926e9830dea768a0d18524747f43598da830 Mon Sep 17 00:00:00 2001 From: sladro Date: Sun, 8 Feb 2026 12:20:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E8=BD=A6=E8=BE=86=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=A4=84=E7=90=86=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8?= =?UTF-8?q?=20ALERT=20=E5=90=8E=E8=A1=A5=E5=8F=91=20PARKING=20=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=20HTTPClient=20?= =?UTF-8?q?=E4=BB=A5=E4=BF=9D=E6=8C=81=E5=AD=97=E6=AE=B5=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/System.cpp | 30 +++++++++++++++++++++++++++++- src/network/HTTPClient.cpp | 11 ++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/core/System.cpp b/src/core/System.cpp index 580bb46..a50a927 100644 --- a/src/core/System.cpp +++ b/src/core/System.cpp @@ -520,6 +520,20 @@ void System::processCollisions( broadcastVehicleCommand(cmd); controllableVehicles_.sendCommand(vehicleId, cmd); + // ALERT 后立即补发 PARKING 作为停止指令 + if (cmd.type == CommandType::ALERT) { + VehicleCommand parkingCmd = cmd; + parkingCmd.type = CommandType::PARKING; + parkingCmd.reason = CommandReason::PARKING_SIDE; + parkingCmd.timestamp = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + + broadcastVehicleCommand(parkingCmd); + controllableVehicles_.sendCommand(vehicleId, parkingCmd); + Logger::info("ALERT 后补发停车指令到车辆: ", vehicleId); + } + // 更新风险记录 currentVehiclesWithRisk.insert(vehicleId); vehicleMaxRiskLevels[vehicleId] = risk.level; @@ -866,6 +880,20 @@ bool System::handleSafetyZoneRisk(const Vehicle& vehicle, broadcastVehicleCommand(cmd); controllableVehicles_.sendCommand(vehicle.id, cmd); + // 安全区触发 ALERT 时也补发 PARKING 作为停止指令 + if (cmd.type == CommandType::ALERT) { + VehicleCommand parkingCmd = cmd; + parkingCmd.type = CommandType::PARKING; + parkingCmd.reason = CommandReason::PARKING_SIDE; + parkingCmd.timestamp = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + + broadcastVehicleCommand(parkingCmd); + controllableVehicles_.sendCommand(vehicle.id, parkingCmd); + Logger::info("安全区 ALERT 后补发停车指令到车辆: ", vehicle.id); + } + CollisionRisk risk; risk.id1 = vehicle.id; risk.id2 = target ? target->id : ""; @@ -947,4 +975,4 @@ void System::processPushedTrafficLightData(const nlohmann::json& di_data) { } catch (const std::exception& e) { Logger::error("处理推送的交通信号灯数据时出错: ", e.what()); } -} \ No newline at end of file +} diff --git a/src/network/HTTPClient.cpp b/src/network/HTTPClient.cpp index 2db3273..362d6c8 100644 --- a/src/network/HTTPClient.cpp +++ b/src/network/HTTPClient.cpp @@ -97,10 +97,11 @@ bool HTTPClient::sendCommand(const std::string& host, int port, const std::strin {"longitude", command.longitude} }; - if (command.type == CommandType::SIGNAL) { - request["signalState"] = getSignalStateString(command.signalState); - request["intersectionId"] = command.intersectionId; - } + // 字段完整性:即使非 SIGNAL 也保留字段,使用占位值避免后端校验失败 + request["signalState"] = + command.type == CommandType::SIGNAL ? getSignalStateString(command.signalState) : ""; + request["intersectionId"] = + command.type == CommandType::SIGNAL ? command.intersectionId : ""; // 后端当前校验要求该字段始终存在;对非 ALERT/WARNING 场景默认填 0 request["relativeSpeed"] = command.relativeSpeed; @@ -174,4 +175,4 @@ bool HTTPClient::sendCommand(const std::string& host, int port, const std::strin Logger::error("Command failed with HTTP code: ", http_code, " response: ", response_buffer_); return false; } -} \ No newline at end of file +}