diff --git a/config/system_config.json b/config/system_config.json index 30262d8..ace68d7 100644 --- a/config/system_config.json +++ b/config/system_config.json @@ -60,7 +60,7 @@ } }, "logging": { - "level": "debug", + "level": "info", "file": "logs/system.log", "max_size_mb": 10, "max_files": 5, diff --git a/docs/official_api.md b/docs/official_api.md index c7ec88b..4057463 100644 --- a/docs/official_api.md +++ b/docs/official_api.md @@ -32,7 +32,7 @@ | 1 | flightNo | 航班号 | String | 是 | | 2 | longitude | 经度 | double | 是 | | 3 | latitude | 纬度 | double | 是 | -| 4 | time | 时间戳 | double | 是 | +| 4 | time | 时间戳(UTC 时间) | long | 是 | | 5 | altitude | 海拔高度 | double | 否 | | 6 | trackNumber | 航迹号 | String | 否 | @@ -53,7 +53,7 @@ | 1 | vehicleNo | 车牌号 | String | 是 | | 2 | longitude | 经度 | double | 是 | | 3 | latitude | 纬度 | double | 是 | -| 4 | time | 时间戳 | double | 是 | +| 4 | time | 时间戳 | long | 是 | | 5 | direction | 方向 | double | 否 | | 6 | speed | 速度 | double | 否 | diff --git a/src/config/SystemConfig.cpp b/src/config/SystemConfig.cpp index 3a2e951..d53af7b 100644 --- a/src/config/SystemConfig.cpp +++ b/src/config/SystemConfig.cpp @@ -13,6 +13,19 @@ void SystemConfig::load(const std::string& filename) { file >> j; nlohmann::from_json(j, *this); + if (j.contains("logging") && j["logging"].contains("level")) { + std::string level = j["logging"]["level"]; + if (level == "debug") { + Logger::setLogLevel(LogLevel::DEBUG); + } else if (level == "info") { + Logger::setLogLevel(LogLevel::INFO); + } else if (level == "warning") { + Logger::setLogLevel(LogLevel::WARNING); + } else if (level == "error") { + Logger::setLogLevel(LogLevel::ERROR); + } + } + Logger::info("Loaded system configuration from ", filename); } catch (const std::exception& e) { diff --git a/src/core/System.cpp b/src/core/System.cpp index cdad92f..ba4b76c 100644 --- a/src/core/System.cpp +++ b/src/core/System.cpp @@ -294,12 +294,6 @@ void System::processLoop() { } else { // 正常的更新检查 for (const auto& veh : vehicles) { - // Logger::debug("处理车辆: ", veh.vehicleNo); - // Logger::debug(" - 位置: (", veh.geo.longitude, ", ", veh.geo.latitude, ")"); - // Logger::debug(" - 速度: ", veh.speed, "m/s"); - // Logger::debug(" - 时间戳: ", veh.timestamp); - // Logger::debug(" - 时间差: ", veh.timestamp - last_vehicle_timestamp); - if (veh.timestamp > last_vehicle_timestamp) { has_new_vehicles = true; if (veh.timestamp > max_timestamp) { @@ -328,60 +322,6 @@ void System::processLoop() { Logger::debug("车辆位置更新检查结束 <<<<<<<<<<<<<<<"); } - // // 检查冲突更新 - // auto collision_elapsed = std::chrono::duration_cast( - // now - last_collision_update).count(); - // if (collision_elapsed >= system_config.collision_detection.update_interval_ms) { - // // 只有有新的数据时才更新冲突检测 - // if (last_aircraft_timestamp > last_collision_timestamp || - // last_vehicle_timestamp > last_collision_timestamp) { - - // // 更新冲突检测器 - // collisionDetector_->updateTraffic(aircraft, vehicles); - // auto collisions = collisionDetector_->detectCollisions(); - - // if (!collisions.empty()) { - // Logger::debug("检测到 ", collisions.size(), "个碰撞风险"); - // for (const auto& risk : collisions) { - // Logger::debug("碰撞风险详情: id1=", risk.id1, - // ", id2=", risk.id2, - // ", 距离=", risk.distance, "m, 预测最小距离=", risk.minDistance, "m, 风险等级=", static_cast(risk.level), - // ", 区域类型=", static_cast(risk.zoneType)); - // } - // processCollisions(collisions); - - // } else if (!lastVehiclesWithRisk_.empty()) { - // // 当前没有任何风险上次有风险车辆,需要处理恢复指令 - // Logger::debug("当前无碰撞风险,检查是否需要发送恢复指令"); - // for (const auto& vehicleId : lastVehiclesWithRisk_) { - // Logger::debug("车辆 ", vehicleId, " 当前没有风险,准备发送恢复指令"); - // VehicleCommand cmd; - // cmd.vehicleId = vehicleId; - // cmd.type = CommandType::RESUME; - // cmd.reason = CommandReason::RESUME_TRAFFIC; - // cmd.timestamp = std::chrono::system_clock::now().time_since_epoch().count(); - - // broadcastVehicleCommand(cmd); - // controllableVehicles_->sendCommand(vehicleId, cmd); - // Logger::info("发送恢复指令到车辆: ", vehicleId); - // } - // // 清空风险车辆列表 - // Logger::debug("清空风险车辆列表: 原数量=", lastVehiclesWithRisk_.size(), - // ", 原列表={", [&]() { - // std::string s; - // for (const auto& id : lastVehiclesWithRisk_) { - // s += id + ","; - // } - // return s; - // }(), "}"); - // lastVehiclesWithRisk_.clear(); - // } - - // last_collision_timestamp = std::max(last_aircraft_timestamp, last_vehicle_timestamp); - // } - // last_collision_update = now; - // } - // 处理红绿灯信号 auto traffic_light_elapsed = std::chrono::duration_cast( now - last_traffic_light_update).count(); diff --git a/src/network/HTTPDataSource.cpp b/src/network/HTTPDataSource.cpp index 881560b..2aebd21 100644 --- a/src/network/HTTPDataSource.cpp +++ b/src/network/HTTPDataSource.cpp @@ -322,13 +322,18 @@ bool HTTPDataSource::parseVehicleResponse(const std::string& response, std::vect } veh.timestamp = static_cast(time); + // 解析可选字段 + if (item.contains("direction")) { + veh.heading = item["direction"].get(); + } + if (item.contains("speed")) { + veh.speed = item["speed"].get(); + } + // 更新位置信息 veh.position = coordinateConverter_.toLocalXY(veh.geo.latitude, veh.geo.longitude); veh.updateMotion(veh.geo, veh.timestamp); // 更新速度和航向 - // Logger::debug("Parsed vehicle: id=", veh.id, " vehicleNo=", veh.vehicleNo, - // " timestamp=", veh.timestamp, " pos=(", veh.geo.longitude, ",", veh.geo.latitude, ")"); - vehicles.push_back(veh); } @@ -379,13 +384,23 @@ bool HTTPDataSource::parseAircraftResponse(const std::string& response, std::vec } ac.timestamp = static_cast(time); + // 解析可选字段 + if (item.contains("altitude")) { + ac.altitude = item["altitude"].get(); + } else { + ac.altitude = 0.0; // 默认值 + } + + if (item.contains("trackNumber")) { + ac.trackNumber = item["trackNumber"].get(); + } else { + ac.trackNumber = "TN" + ac.flightNo.substr(2); // 默认使用航班号生成跟踪号 + } + // 更新位置信息 ac.position = coordinateConverter_.toLocalXY(ac.geo.latitude, ac.geo.longitude); ac.updateMotion(ac.geo, ac.timestamp); // 更新速度和航向 - Logger::debug("Parsed aircraft: id=", ac.id, " flightNo=", ac.flightNo, - " timestamp=", ac.timestamp, " pos=(", ac.geo.longitude, ",", ac.geo.latitude, ")"); - aircraft.push_back(ac); } diff --git a/src/types/BasicTypes.cpp b/src/types/BasicTypes.cpp index 3f2a456..e0310ca 100644 --- a/src/types/BasicTypes.cpp +++ b/src/types/BasicTypes.cpp @@ -104,12 +104,6 @@ void MovingObject::updateMotion(const GeoPosition& newPos, uint64_t newTime) { double distance = calculateDistance(prev.geo, curr.geo); // 单位:米 double timeDiff = static_cast(curr.timestamp - prev.timestamp) / 1000.0; // 转换为秒 - // 只有当位置变化足够大且时间差足够长时才更新速度和航向 - // Logger::debug("[Motion] Position update: ", - // "\n Current: lat=", curr.geo.latitude, ", lon=", curr.geo.longitude, - // "\n Previous: lat=", prev.geo.latitude, ", lon=", prev.geo.longitude, - // "\n Distance=", distance, "m, TimeDiff=", timeDiff, "s"); - // 只有当位置变化足够大且时间差足够长时才更新速度和航向 static const double MIN_DISTANCE = 0.1; // 最小位置变化阈值(米) static const double MIN_TIME = 0.05; // 最小时间差阈值(秒) diff --git a/src/vehicle/ControllableVehicles.cpp b/src/vehicle/ControllableVehicles.cpp index bece014..06017f0 100644 --- a/src/vehicle/ControllableVehicles.cpp +++ b/src/vehicle/ControllableVehicles.cpp @@ -70,7 +70,15 @@ bool ControllableVehicles::sendCommand(const std::string& vehicleNo, const Vehic try { bool success = http_client_->sendCommand(vehicle->ip, vehicle->port, command); if (success) { - Logger::info("Successfully sent command to vehicle ", vehicleNo, ": type=", static_cast(command.type), ", reason=", static_cast(command.reason)); + Logger::info("Successfully sent command to vehicle ", vehicleNo, ": ", + command.type == CommandType::SIGNAL ? "SIGNAL" : + command.type == CommandType::ALERT ? "ALERT" : + command.type == CommandType::WARNING ? "WARNING" : "RESUME", + "/", + command.reason == CommandReason::TRAFFIC_LIGHT ? "TRAFFIC_LIGHT" : + command.reason == CommandReason::AIRCRAFT_CROSSING ? "AIRCRAFT_CROSSING" : + command.reason == CommandReason::SPECIAL_VEHICLE ? "SPECIAL_VEHICLE" : + command.reason == CommandReason::AIRCRAFT_PUSH ? "AIRCRAFT_PUSH" : "RESUME_TRAFFIC"); } else { Logger::error("Failed to send command to vehicle ", vehicleNo); } diff --git a/tools/mock_server.py b/tools/mock_server.py index 5c44aa6..557e594 100644 --- a/tools/mock_server.py +++ b/tools/mock_server.py @@ -88,14 +88,16 @@ if initial_dist > 0: aircraft_data = [ { "flightNo": "AC001", # 航空器 - "latitude": POINT_T7["latitude"], "longitude": POINT_T7["longitude"], + "latitude": POINT_T7["latitude"], "time": int(time.time() * 1000), - "direction": { # 改用方向向量替代单一方向值 + "altitude": 0.0, + "trackNumber": "TN001", + "speed": 36.0, # 内部使用的速度字段,不会在 API 返回中显示 + "direction": { # 内部使用的方向字段,不会在 API 返回中显示 "lat": initial_target_lat, "lon": initial_target_lon - }, - "speed": 36.0 # 滑行速度 ,默认 50km/h + } } ] @@ -118,33 +120,27 @@ if qn002_dist > 0: vehicle_data = [ { "vehicleNo": "QN001", # 无人车1 - "latitude": POINT_T1["latitude"], "longitude": POINT_T1["longitude"], + "latitude": POINT_T1["latitude"], "time": int(time.time() * 1000), - "direction": -1, # -1表示向南 - "speed": DEFAULT_VEHICLE_SPEED, - "phase": 0 + "direction": 180.0, # 向南方向为180度 + "speed": DEFAULT_VEHICLE_SPEED }, { "vehicleNo": "QN002", # 无人车2 - "latitude": POINT_T12["latitude"], # 使用新的起点 "longitude": POINT_T12["longitude"], + "latitude": POINT_T12["latitude"], "time": int(time.time() * 1000), - "direction": { # 改用方向向量 - "lat": qn002_target_lat, - "lon": qn002_target_lon - }, - "speed": DEFAULT_VEHICLE_SPEED, - "phase": 0 + "direction": 135.0, # 东南方向约为135度 + "speed": DEFAULT_VEHICLE_SPEED }, { "vehicleNo": "TQ001", # 特勤车 - "latitude": POINT_T4["latitude"], "longitude": POINT_T4["longitude"], + "latitude": POINT_T4["latitude"], "time": int(time.time() * 1000), - "direction": -1, # -1表示向西 - "speed": DEFAULT_VEHICLE_SPEED, # 使用默认速度 - "phase": 0 # 初始化 phase + "direction": 270.0, # 向西方向为270度 + "speed": DEFAULT_VEHICLE_SPEED } ] @@ -746,8 +742,10 @@ def check_auth(): @app.route('/openApi/getCurrentFlightPositions', methods=['GET', 'OPTIONS']) def get_flight_positions(): + """获取当前航空器位置信息""" if request.method == 'OPTIONS': return '', 204 + if not check_auth(): return jsonify({ "status": 401, @@ -765,7 +763,20 @@ def get_flight_positions(): aircraft["time"] = int(current_time * 1000) last_aircraft_update_time = current_time - return jsonify(aircraft_data) + # 创建符合 API 格式的响应数据 + response_data = [] + for aircraft in aircraft_data: + api_aircraft = { + "flightNo": aircraft["flightNo"], + "longitude": aircraft["longitude"], + "latitude": aircraft["latitude"], + "time": aircraft["time"], + "altitude": aircraft["altitude"], + "trackNumber": aircraft["trackNumber"] + } + response_data.append(api_aircraft) + + return jsonify(response_data) def switch_traffic_light_state(): """统一处理红绿灯状态切换""" @@ -792,6 +803,7 @@ def switch_traffic_light_state(): @app.route('/openApi/getCurrentVehiclePositions', methods=['GET', 'OPTIONS']) def get_vehicle_positions(): + """获取当前车辆位置信息""" if request.method == 'OPTIONS': return '', 204 if not check_auth():