"""
Flask 静态文件服务器 - 托管前端页面
浏览器通过 roslibjs 直接连接 rosbridge_server，无需 Python 后端处理无人机逻辑
"""

import os
from flask import Flask, send_from_directory

# 项目根目录（server 的上级目录）
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

app = Flask(__name__, static_folder=BASE_DIR)


@app.route("/")
def index():
    return send_from_directory(BASE_DIR, "index.html")


@app.route("/css/<path:filename>")
def css_files(filename):
    return send_from_directory(os.path.join(BASE_DIR, "css"), filename)


@app.route("/js/<path:filename>")
def js_files(filename):
    return send_from_directory(os.path.join(BASE_DIR, "js"), filename)


if __name__ == "__main__":
    print("=" * 50)
    print("  P600 无人机定点巡航控制系统")
    print("  打开浏览器访问: http://localhost:5000")
    print()
    print("  架构: 浏览器 ──roslibjs──► rosbridge_server ──ROS──► PX4")
    print("  rosbridge 地址默认: ws://localhost:9090 (仿真)")
    print("                       ws://192.168.1.31:9090 (实机)")
    print("=" * 50)
    app.run(host="0.0.0.0", port=5000, debug=False)
