#ifndef MLAT_H #define MLAT_H #include #include "../global_include.h" #include "Psc_Cpp_Core/Base/JSON.h" #include "Psc_Cpp_Core/system/export.h" #include "adminive/managed.hpp" class Global; #pragma pack(push, 8) extern "C" { struct MLAT_Data { char icao[6]; double lon; double lat; }; } #pragma pack(pop) struct MLAT_Store { MLAT_Data d{}; [[nodiscard]] Psc::JSON to_json() const { Psc::JSON ret = Psc::JSON::object(); ret.append({"icao", std::string(d.icao, 6)}); ret.append({"lon", d.lon}); ret.append({"lat", d.lat}); return ret; } [[nodiscard]] std::string icao() const { return {d.icao, 6}; } }; struct Base_MLAT_Data { MLAT_Data mlat_data; std::string msg; std::string hex; std::string icao; }; extern std::multimap hex_mlat_map; class MLAT_Config_Data { public: bool enable{}; bool merge{}; std::string library_path; std::string function_name; PSC_USE_JSON }; namespace adminive { template <> struct Type_Descriptor { static auto get() { using T = MLAT_Config_Data; return object("mlat_config", "MLAT 配置", ADMINIVE_FIELD_LABEL(T, enable, "启用 MLAT").editable().boolean_input(), ADMINIVE_FIELD_LABEL(T, merge, "合并 MLAT").editable().boolean_input(), ADMINIVE_FIELD_LABEL(T, library_path, "库路径").editable().text_input(), ADMINIVE_FIELD_LABEL(T, function_name, "函数名").editable().text_input()); } }; } class MLAT_Config { public: adminive::Managed_Value settings; ~MLAT_Config() = default; MLAT_Config(); [[nodiscard]] Psc::JSON to_base_json() const { return settings.read([](const auto& value) { return value.to_base_json(); }); } void* lib{}; using Func_Type = void (*)(MLAT_Data* buf, std::uint16_t* len); Func_Type read_func_ptr{}; void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value); MLAT_Data buf[std::numeric_limits::max()]{}; void refresh(); Psc::JSON get_reset() { std::lock_guard guard(mtx); Psc::JSON ret = Psc::JSON::array(); for (auto& t : update_map) { ret.append(t.second.to_json()); } update_map.clear(); return ret; } void server(Global* g); protected: std::mutex mtx; std::map update_map; }; #endif