缩减代码
This commit is contained in:
@@ -1,89 +1,37 @@
|
||||
#ifndef MLAT_H
|
||||
#define MLAT_H
|
||||
#include <string>
|
||||
#include "../global_include.h"
|
||||
#pragma once
|
||||
|
||||
#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<std::string, Base_MLAT_Data> hex_mlat_map;
|
||||
class MLAT_Config_Data {
|
||||
public:
|
||||
bool enable{};
|
||||
|
||||
struct MLAT_Config_Data {
|
||||
bool merge{};
|
||||
std::string library_path;
|
||||
std::string function_name;
|
||||
PSC_USE_JSON
|
||||
};
|
||||
|
||||
namespace adminive {
|
||||
template <>
|
||||
struct Type_Descriptor<MLAT_Config_Data> {
|
||||
static auto get() {
|
||||
using T = MLAT_Config_Data;
|
||||
return object<T>("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());
|
||||
ADMINIVE_FIELD_LABEL(T, merge, "合并 MLAT").editable().boolean_input());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class MLAT_Config {
|
||||
public:
|
||||
adminive::Managed_Value<MLAT_Config_Data> 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<std::uint16_t>::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 from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
|
||||
settings.write([&](auto& value) {
|
||||
value.from_base_json(that_json, not_exist_use_default_value);
|
||||
});
|
||||
}
|
||||
void server(Global* g);
|
||||
protected:
|
||||
std::mutex mtx;
|
||||
std::map<std::string, MLAT_Store> update_map;
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user