CollisionAvoidance/tools/mock_server.py

69 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from flask import Flask, jsonify
import time
import math
app = Flask(__name__)
# 基准坐标(青岛胶东机场)
BASE_LAT = 36.361999
BASE_LON = 120.088003
# 模拟数据
aircraft_data = [
{
"flightNo": "CES2501", # 在跑道上
"latitude": BASE_LAT,
"longitude": BASE_LON + 0.001, # 在跑道中间位置
"time": int(time.time())
},
{
"flightNo": "CES2502", # 在滑行道上
"latitude": BASE_LAT - 0.001,
"longitude": BASE_LON,
"time": int(time.time())
}
]
# 两辆车从跑道两侧向中间移动(距离更近,速度更快)
vehicle_data = [
{
"vehicleNo": "VEH001", # 从南向北接近跑道
"latitude": BASE_LAT - 0.0005, # 起始位置更近约50米
"longitude": BASE_LON + 0.001, # 与飞机同一经度
"time": int(time.time())
},
{
"vehicleNo": "VEH002", # 从北向南接近跑道
"latitude": BASE_LAT + 0.0005, # 起始位置更近约50米
"longitude": BASE_LON + 0.001, # 与飞机同一经度
"time": int(time.time())
}
]
@app.route('/api/getCurrentFlightPositions')
def get_flight_positions():
current_time = int(time.time())
# 更新时间戳
for aircraft in aircraft_data:
aircraft["time"] = current_time
# CES2501 在跑道上缓慢滑行
if aircraft["flightNo"] == "CES2501":
aircraft["longitude"] += 0.00001 * math.sin(current_time) # 小幅度东西移动
return jsonify(aircraft_data)
@app.route('/api/getCurrentVehiclePositions')
def get_vehicle_positions():
current_time = int(time.time())
# 更新时间戳和位置
for vehicle in vehicle_data:
vehicle["time"] = current_time
if vehicle["vehicleNo"] == "VEH001":
# 从南向北移动(速度更快)
vehicle["latitude"] += 0.00005 # 增加移动速度
elif vehicle["vehicleNo"] == "VEH002":
# 从北向南移动(速度更快)
vehicle["latitude"] -= 0.00005 # 增加移动速度
return jsonify(vehicle_data)
if __name__ == '__main__':
app.run(host='localhost', port=8080)