106 lines
3.5 KiB
C++
106 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
class System; // 前向声明
|
|
|
|
struct CoordinatePoint {
|
|
std::string point;
|
|
double latitude;
|
|
double longitude;
|
|
};
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CoordinatePoint, point, latitude, longitude)
|
|
|
|
class SystemConfig {
|
|
public:
|
|
static SystemConfig& instance() {
|
|
static SystemConfig instance;
|
|
return instance;
|
|
}
|
|
|
|
void load(const std::string& filename);
|
|
|
|
SystemConfig(const SystemConfig&) = delete;
|
|
SystemConfig& operator=(const SystemConfig&) = delete;
|
|
|
|
friend class System;
|
|
|
|
struct Airport {
|
|
std::string name;
|
|
std::string iata;
|
|
std::string icao;
|
|
struct ReferencePoint {
|
|
double latitude;
|
|
double longitude;
|
|
} reference_point;
|
|
std::vector<CoordinatePoint> coordinate_points;
|
|
} airport;
|
|
|
|
struct DataSource {
|
|
std::string host;
|
|
uint16_t port;
|
|
std::string aircraft_path;
|
|
std::string vehicle_path;
|
|
std::string traffic_light_path;
|
|
int refresh_interval_ms;
|
|
int timeout_ms;
|
|
int read_timeout_ms;
|
|
} data_source;
|
|
|
|
struct WebSocket {
|
|
uint16_t port;
|
|
int max_connections;
|
|
int ping_interval_ms;
|
|
struct PositionUpdate {
|
|
int aircraft_interval_ms;
|
|
int vehicle_interval_ms;
|
|
int traffic_light_interval_ms;
|
|
} position_update;
|
|
} websocket;
|
|
|
|
struct CollisionDetection {
|
|
int update_interval_ms;
|
|
struct Prediction {
|
|
double time_window;
|
|
double vehicle_size;
|
|
double aircraft_size;
|
|
double min_unmanned_speed;
|
|
} prediction;
|
|
} collision_detection;
|
|
|
|
struct Logging {
|
|
std::string level;
|
|
std::string file;
|
|
int max_size_mb;
|
|
int max_files;
|
|
bool console_output;
|
|
} logging;
|
|
|
|
struct Debug {
|
|
bool enable_mock_data;
|
|
bool save_raw_data;
|
|
bool profile_performance;
|
|
} debug;
|
|
|
|
struct Warning {
|
|
int warning_interval_ms;
|
|
int log_interval_ms;
|
|
} warning;
|
|
|
|
private:
|
|
SystemConfig() = default;
|
|
};
|
|
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport::ReferencePoint, latitude, longitude)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Airport, name, iata, icao, reference_point, coordinate_points)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket::PositionUpdate, aircraft_interval_ms, vehicle_interval_ms, traffic_light_interval_ms)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::WebSocket, port, max_connections, ping_interval_ms, position_update)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection::Prediction, time_window, vehicle_size, aircraft_size, min_unmanned_speed)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::CollisionDetection, update_interval_ms, prediction)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::DataSource, host, port, aircraft_path, vehicle_path, traffic_light_path, refresh_interval_ms, timeout_ms, read_timeout_ms)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Logging, level, file, max_size_mb, max_files, console_output)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Debug, enable_mock_data, save_raw_data, profile_performance)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig::Warning, warning_interval_ms, log_interval_ms)
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SystemConfig, airport, data_source, websocket, collision_detection, logging, debug, warning) |