初步修改
This commit is contained in:
@@ -145,7 +145,7 @@ size_t Data_Source_Handler::process_mode_acs_data(std::string_view origin_data)
|
||||
}
|
||||
};
|
||||
auto f = [this, source, handle_packet](std::string& packet) {
|
||||
auto& wait = Global::instance()->mode_acs.wait_process_msg;
|
||||
const auto wait = Global::instance()->mode_acs.settings.member<&Mode_ACS_Config_Data::wait_process_msg>().snapshot();
|
||||
if (wait) {
|
||||
handle_packet(packet);
|
||||
}
|
||||
@@ -168,29 +168,29 @@ void Data_Source_Handler::handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg>& mode_s
|
||||
mem2hex(t, true, " "), mem2hex(mode_s_msg->packet, true, " "), t, mode_s_msg->packet);
|
||||
Psc::fail_fast(data);
|
||||
}
|
||||
auto& cfg = Global::instance()->mode_acs;
|
||||
bool time_space_filter = cfg.time_space_filter.load();
|
||||
bool speed_filter = cfg.speed_filter.load();
|
||||
bool use_system_time = source->ignore_msg_time.load();
|
||||
const auto cfg = Global::instance()->mode_acs.settings.snapshot();
|
||||
const auto source_cfg = source->settings.snapshot();
|
||||
bool time_space_filter = cfg.time_space_filter;
|
||||
bool speed_filter = cfg.speed_filter;
|
||||
bool use_system_time = source_cfg.ignore_msg_time;
|
||||
auto base_station_pos = source->base_station.get_pos();
|
||||
if (!base_station_pos && source->base_station_has_valid_position.load()) {
|
||||
base_station_pos = SSR::Position_3D{source->lat, source->lon, source->alt};
|
||||
}
|
||||
auto range_filter = cfg.aircraft_change_list_adsb_range_filter.load();
|
||||
auto range_factor = cfg.aircraft_change_list_adsb_range_factor.load();
|
||||
SSR::ADS_B_T::Constraint air_constraint{cfg.max_speed_m_s, cfg.air_pos_timeout, SSR::cpr_cb, time_space_filter,
|
||||
speed_filter, use_system_time, base_station_pos, source->alt,
|
||||
range_filter, range_factor};
|
||||
SSR::ADS_B_T::Constraint surface_constraint{
|
||||
cfg.max_speed_m_s, cfg.surface_pos_timeout, SSR::cpr_cb, time_space_filter, speed_filter,
|
||||
use_system_time, base_station_pos, source->alt, range_filter, range_factor};
|
||||
if (!base_station_pos && source_cfg.base_station_has_valid_position)
|
||||
base_station_pos = SSR::Position_3D{source_cfg.lat, source_cfg.lon, source_cfg.alt};
|
||||
auto range_filter = cfg.aircraft_change_list_adsb_range_filter;
|
||||
auto range_factor = cfg.aircraft_change_list_adsb_range_factor;
|
||||
SSR::ADS_B_T::Constraint air_constraint{cfg.max_speed_m_s, cfg.air_pos_timeout, SSR::cpr_cb, time_space_filter,
|
||||
speed_filter, use_system_time, base_station_pos, source_cfg.alt,
|
||||
range_filter, range_factor};
|
||||
SSR::ADS_B_T::Constraint surface_constraint{cfg.max_speed_m_s, cfg.surface_pos_timeout, SSR::cpr_cb, time_space_filter,
|
||||
speed_filter, use_system_time, base_station_pos, source_cfg.alt,
|
||||
range_filter, range_factor};
|
||||
SSR::parse_mode_s_bin(source.get(), mode_s_msg, base_station_pos, air_constraint, surface_constraint);
|
||||
auto base = source->get_aircraft(mode_s_msg->icao);
|
||||
if (base) {
|
||||
auto derived = std::dynamic_pointer_cast<Aircraft>(base);
|
||||
derived->refresh_external_database_info();
|
||||
}
|
||||
if (Global::instance()->mlat.merge) {
|
||||
if (Global::instance()->mlat.settings.member<&MLAT_Config_Data::merge>().snapshot()) {
|
||||
auto& mh = Global::instance()->mlat_handler;
|
||||
mh.push(mode_s_msg);
|
||||
auto tt = mh.get_all();
|
||||
@@ -216,10 +216,13 @@ void Data_Source_Handler::handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg>& mode_s
|
||||
if (o_pos.has_value() && o_alt.has_value()) {
|
||||
have_pos = true;
|
||||
auto pos = o_pos.value();
|
||||
source->alt = o_alt.value();
|
||||
const auto altitude = o_alt.value();
|
||||
source->settings.member<&Data_Source_Data::alt>().write([altitude](double& value) {
|
||||
value = altitude;
|
||||
});
|
||||
double x, y, z;
|
||||
SSR::CPR::WGS84_LBH_to_XYZ(pos.lon, pos.lat, source->alt, x, y, z);
|
||||
oss << "\tpos:[" << pos.lon << "," << pos.lat << "," << source->alt << "]" << std::endl;
|
||||
SSR::CPR::WGS84_LBH_to_XYZ(pos.lon, pos.lat, altitude, x, y, z);
|
||||
oss << "\tpos:[" << pos.lon << "," << pos.lat << "," << altitude << "]" << std::endl;
|
||||
oss << "\tXYZ:[" << x << "," << y << "," << z << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -279,90 +282,85 @@ void Data_Source_Handler::handle_HULC(std::string_view packet) {
|
||||
}
|
||||
}
|
||||
void Data_Source_Handler::refresh_data_feed_key_list() {
|
||||
// std::cout << key << " refresh_data_feed_key_list" << std::endl;
|
||||
std::vector<std::string> tmp;
|
||||
for (auto& relation : Global::instance()->mode_acs.source_feed_relation_config.map.list()) {
|
||||
if (!relation->enable)
|
||||
auto* global = Global::instance();
|
||||
std::map<std::string, std::string> assignment;
|
||||
const auto sources = global->mode_acs.data_source_config.map.list();
|
||||
const auto feeds = global->mode_acs.data_feed_config.map.list();
|
||||
const auto relations = global->mode_acs.source_feed_relation_config.map.list();
|
||||
for (const auto& relation : relations) {
|
||||
const auto config = relation->settings.snapshot();
|
||||
if (!config.enable || relation->type != "One_to_One_Relation")
|
||||
continue;
|
||||
if (relation->type == "One_to_One_Relation") {
|
||||
auto t = dynamic_cast<One_to_One_Relation*>(relation.get());
|
||||
// std::cout << VAR_STR_2(t->source_key, this->key) << "
|
||||
// refresh_data_feed_key_list" << std::endl;
|
||||
if (t->source_key == this->key) {
|
||||
tmp.push_back(t->feed_key);
|
||||
}
|
||||
const auto source = global->mode_acs.data_source_config.map.get(config.source_key);
|
||||
const auto feed = global->mode_acs.data_feed_config.map.get(config.feed_key);
|
||||
if (source.has_value() && feed.has_value() && source.value()->enabled() && feed.value()->enabled() && !assignment.contains(config.feed_key))
|
||||
assignment.emplace(config.feed_key, config.source_key);
|
||||
}
|
||||
for (const auto& relation : relations) {
|
||||
const auto config = relation->settings.snapshot();
|
||||
if (!config.enable || relation->type != "Name_One_To_Many_Relation")
|
||||
continue;
|
||||
const auto source = global->mode_acs.data_source_config.map.get(config.source_key);
|
||||
if (!source.has_value() || !source.value()->enabled())
|
||||
continue;
|
||||
const std::string& prefix = config.feed_name.empty() ? config.source_key : config.feed_name;
|
||||
for (const auto& feed : feeds) {
|
||||
if (!feed->enabled() || assignment.contains(feed->key) || !feed->key.starts_with(prefix))
|
||||
continue;
|
||||
assignment.emplace(feed->key, config.source_key);
|
||||
}
|
||||
else if (relation->type == "First_Source_To_All_Feed_Relation") {
|
||||
auto t = dynamic_cast<First_Source_To_All_Feed_Relation*>(relation.get());
|
||||
std::shared_ptr<Data_Source> first = nullptr;
|
||||
for (const auto& ds : Global::instance()->mode_acs.data_source_config.map.list()) {
|
||||
if (ds->enable) {
|
||||
first = ds;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (first->key == key) {
|
||||
for (const auto& df : Global::instance()->mode_acs.data_feed_config.map.list()) {
|
||||
if (df->enable) {
|
||||
tmp.push_back(df->key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool use_default = false;
|
||||
for (const auto& relation : relations) {
|
||||
if (relation->type == "First_Source_To_All_Feed_Relation" && relation->settings.member<&Source_Feed_Relation_Data::enable>().snapshot()) {
|
||||
use_default = true;
|
||||
break;
|
||||
}
|
||||
std::sort(tmp.begin(), tmp.end());
|
||||
// 去重
|
||||
auto last = std::unique(tmp.begin(), tmp.end());
|
||||
tmp.erase(last, tmp.end());
|
||||
{
|
||||
std::vector<Cached_Source_Info> tmp_info;
|
||||
// 创建 tmp_info 向量,将 tmp 的内容转化为 Cached_Source_Info 对象
|
||||
for (const auto& key : tmp) {
|
||||
tmp_info.push_back({key});
|
||||
}
|
||||
{
|
||||
// 进入临界区,锁住 mutex,确保线程安全
|
||||
std::lock_guard<std::mutex> lock(cdf_mtx);
|
||||
// 1. 删除 tmp 中没有的 cached_data_feed_key_list 元素
|
||||
auto it = cached_data_feed_key_list.begin();
|
||||
while (it != cached_data_feed_key_list.end()) {
|
||||
if (std::find_if(tmp_info.begin(), tmp_info.end(), [&](const Cached_Source_Info& info) {
|
||||
return info.key == it->key;
|
||||
}) == tmp_info.end()) {
|
||||
// 如果当前元素在 tmp 中找不到,删除它
|
||||
it = cached_data_feed_key_list.erase(it);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
// 2. 创建 tmp 中有但 cached_data_feed_key_list 没有的元素
|
||||
for (const auto& tmp_item : tmp_info) {
|
||||
auto found = std::find_if(
|
||||
cached_data_feed_key_list.begin(), cached_data_feed_key_list.end(),
|
||||
[&](const Cached_Source_Info& cached_item) { return cached_item.key == tmp_item.key; });
|
||||
if (found == cached_data_feed_key_list.end()) {
|
||||
// 如果 tmp_item 不在 cached_data_feed_key_list 中,添加它
|
||||
cached_data_feed_key_list.push_back(tmp_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (use_default) {
|
||||
auto first = std::find_if(sources.begin(), sources.end(), [](const auto& source) {
|
||||
return source->enabled();
|
||||
});
|
||||
if (first != sources.end()) {
|
||||
for (const auto& feed : feeds) {
|
||||
if (feed->enabled() && !assignment.contains(feed->key))
|
||||
assignment.emplace(feed->key, (*first)->key);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::vector<Cached_Source_Info> next;
|
||||
for (const auto& [feed_key, source_key] : assignment) {
|
||||
if (source_key == key)
|
||||
next.push_back({feed_key});
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(cdf_mtx);
|
||||
for (auto& item : next) {
|
||||
auto old = std::find_if(cached_data_feed_key_list.begin(), cached_data_feed_key_list.end(), [&](const Cached_Source_Info& value) {
|
||||
return value.key == item.key;
|
||||
});
|
||||
if (old != cached_data_feed_key_list.end()) {
|
||||
item.mode_s_cache_num = old->mode_s_cache_num;
|
||||
item.mode_other_cache_num = old->mode_other_cache_num;
|
||||
}
|
||||
}
|
||||
cached_data_feed_key_list = std::move(next);
|
||||
}
|
||||
|
||||
std::optional<std::string> convert_to_send_format(Data_Source_Handler* ds, const std::shared_ptr<Data_Feed>& feed,
|
||||
const std::shared_ptr<SSR::Msg>& msg) {
|
||||
auto& type = msg->type;
|
||||
auto fs = dynamic_cast<File_Data_Source*>(msg->source.get());
|
||||
if (fs) {
|
||||
if (fs->play_mode == Play_Mode::analysis) {
|
||||
if (fs->specific.member<&File_Data_Source_Data::play_mode>().snapshot() == Play_Mode::analysis) {
|
||||
// std::cout << fs->key << " analysis i ==" << i << std::endl;
|
||||
}
|
||||
}
|
||||
// 出口输出的条件
|
||||
auto& output_format = feed->output_format.type;
|
||||
auto& use_mode_ac = feed->output_format.use_mode_ac;
|
||||
auto& use_status = feed->output_format.use_status;
|
||||
auto& mode_s_output_type = feed->output_format.mode_s_output_type;
|
||||
const auto feed_format = feed->output_format.snapshot();
|
||||
const auto output_format = feed_format.type;
|
||||
const auto use_mode_ac = feed_format.use_mode_ac;
|
||||
const auto use_status = feed_format.use_status;
|
||||
const auto mode_s_output_type = feed_format.mode_s_output_type;
|
||||
// 计算出是否输出消息
|
||||
std::optional<std::string> send_msg = std::nullopt;
|
||||
if (type == SSR::Msg::HULC_Status) {
|
||||
@@ -416,7 +414,7 @@ std::optional<std::string> convert_to_send_format(Data_Source_Handler* ds, const
|
||||
auto aircraft = ds->get_aircraft(s_msg->icao);
|
||||
if (output_format == Output_Data_Format::SBS) {
|
||||
bool sbs_out_put = false;
|
||||
if (feed->output_format.sbs_only_pos) {
|
||||
if (feed_format.sbs_only_pos) {
|
||||
auto s = ds->get_aircraft(s_msg->icao);
|
||||
if (s) {
|
||||
auto pos = s->pos();
|
||||
@@ -490,8 +488,9 @@ void Data_Source_Handler::push_to_feed(const std::shared_ptr<SSR::Msg>& msg) {
|
||||
refresh_data_feed_key_list();
|
||||
need_refresh_data_feed_key_list = false;
|
||||
}
|
||||
auto& other_size = Global::instance()->mode_acs.mode_other_max_num;
|
||||
auto& s_size = Global::instance()->mode_acs.mode_other_max_num;
|
||||
const auto mode_config = Global::instance()->mode_acs.settings.snapshot();
|
||||
const auto other_size = mode_config.mode_other_max_num;
|
||||
const auto s_size = mode_config.mode_s_max_num;
|
||||
std::vector<std::string> list;
|
||||
for (const auto& item : cached_data_feed_key_list) {
|
||||
auto& key = item.key;
|
||||
@@ -501,7 +500,7 @@ void Data_Source_Handler::push_to_feed(const std::shared_ptr<SSR::Msg>& msg) {
|
||||
break;
|
||||
}
|
||||
std::shared_ptr<Data_Feed>& feed = opt_feed.value();
|
||||
if (!feed->enable)
|
||||
if (!feed->enabled())
|
||||
continue;
|
||||
if (msg->type == SSR::Mode_Msg::T::S7 || msg->type == SSR::Mode_Msg::T::S14) {
|
||||
// static Frequency_Limit fl;
|
||||
|
||||
Reference in New Issue
Block a user