重新设置代码格式
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
#include "BaseStation.h"
|
||||
|
||||
|
||||
|
||||
namespace SSR {
|
||||
struct HULC_Status_Message;
|
||||
}
|
||||
|
||||
|
||||
std::optional<SSR::CPR::Position> BaseStation::get_pos() {
|
||||
std::lock_guard g(mtx);
|
||||
return SSR::CPR::Position{hulc.get_latitude(), hulc.get_longitude()};
|
||||
}
|
||||
void BaseStation::set_msg(const SSR::HULC_Status_Message& msg) {
|
||||
void BaseStation::set_msg(const SSR::HULC_Status_Message &msg) {
|
||||
std::lock_guard g(mtx);
|
||||
hulc = msg;
|
||||
if (handle_when_updated) handle_when_updated(msg);
|
||||
if (handle_when_updated)
|
||||
handle_when_updated(msg);
|
||||
}
|
||||
std::string BaseStation::to_string() {
|
||||
std::lock_guard g(mtx);
|
||||
return "BaseStation:[" + std::to_string(hulc.get_latitude()) + ", " + std::to_string(hulc.get_longitude()) + "]";
|
||||
return "BaseStation:[" + std::to_string(hulc.get_latitude()) + ", " +
|
||||
std::to_string(hulc.get_longitude()) + "]";
|
||||
}
|
||||
Psc::JSON BaseStation::to_Json() {
|
||||
std::lock_guard g(mtx);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include "Data_Source_Handler.h"
|
||||
|
||||
|
||||
namespace Psc {
|
||||
class SM_RingBuffer;
|
||||
}
|
||||
@@ -14,467 +11,460 @@ std::shared_ptr<Data_Source> create_from_json(const Psc::JSON *that_json);
|
||||
|
||||
class Input_Format {
|
||||
public:
|
||||
Input_Format() {
|
||||
test_v.resize(static_cast<size_t>(SSR::Downlink_Format::Unknown));
|
||||
}
|
||||
Input_Format() {
|
||||
test_v.resize(static_cast<size_t>(SSR::Downlink_Format::Unknown));
|
||||
}
|
||||
|
||||
Psc::JSON to_json() {
|
||||
std::lock_guard g(mtx);
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
for (auto e : magic_enum::enum_values<SSR::Downlink_Format>()) {
|
||||
std::string_view value_view = magic_enum::enum_name(e);
|
||||
std::string value(value_view.begin(), value_view.end());
|
||||
if (value == Psc::to_string(SSR::Downlink_Format::Unknown)) continue;
|
||||
auto ev = static_cast<std::uint8_t>(e);
|
||||
bool it = test_v[ev];
|
||||
ret.append({value, it});
|
||||
}
|
||||
return ret;
|
||||
Psc::JSON to_json() {
|
||||
std::lock_guard g(mtx);
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
for (auto e : magic_enum::enum_values<SSR::Downlink_Format>()) {
|
||||
std::string_view value_view = magic_enum::enum_name(e);
|
||||
std::string value(value_view.begin(), value_view.end());
|
||||
if (value == Psc::to_string(SSR::Downlink_Format::Unknown))
|
||||
continue;
|
||||
auto ev = static_cast<std::uint8_t>(e);
|
||||
bool it = test_v[ev];
|
||||
ret.append({value, it});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void from_json(const Psc::JSON* json) {
|
||||
std::lock_guard g(mtx);
|
||||
for (auto e : magic_enum::enum_values<SSR::Downlink_Format>()) {
|
||||
std::string_view value_view = magic_enum::enum_name(e);
|
||||
std::string value(value_view.begin(), value_view.end());
|
||||
if (value == Psc::to_string(SSR::Downlink_Format::Unknown)) continue;
|
||||
auto use = json->get_bool(value);
|
||||
auto ev = static_cast<std::uint8_t>(e);
|
||||
test_v[ev] = use;
|
||||
}
|
||||
void from_json(const Psc::JSON *json) {
|
||||
std::lock_guard g(mtx);
|
||||
for (auto e : magic_enum::enum_values<SSR::Downlink_Format>()) {
|
||||
std::string_view value_view = magic_enum::enum_name(e);
|
||||
std::string value(value_view.begin(), value_view.end());
|
||||
if (value == Psc::to_string(SSR::Downlink_Format::Unknown))
|
||||
continue;
|
||||
auto use = json->get_bool(value);
|
||||
auto ev = static_cast<std::uint8_t>(e);
|
||||
test_v[ev] = use;
|
||||
}
|
||||
}
|
||||
|
||||
bool test(SSR::Downlink_Format df) {
|
||||
std::lock_guard g(mtx);
|
||||
auto dfv = static_cast<std::uint8_t>(df);
|
||||
if (dfv >= static_cast<std::uint8_t>(SSR::Downlink_Format::Unknown))
|
||||
return false;
|
||||
return test_v[dfv];
|
||||
}
|
||||
|
||||
bool test(SSR::Downlink_Format df) {
|
||||
std::lock_guard g(mtx);
|
||||
auto dfv = static_cast<std::uint8_t>(df);
|
||||
if (dfv >= static_cast<std::uint8_t>(SSR::Downlink_Format::Unknown)) return false;
|
||||
return test_v[dfv];
|
||||
}
|
||||
bool test(std::uint8_t dfv) {
|
||||
std::lock_guard g(mtx);
|
||||
if (dfv >= static_cast<std::uint8_t>(SSR::Downlink_Format::Unknown))
|
||||
return false;
|
||||
return test_v[dfv];
|
||||
}
|
||||
|
||||
bool test(std::uint8_t dfv) {
|
||||
std::lock_guard g(mtx);
|
||||
if (dfv >= static_cast<std::uint8_t>(SSR::Downlink_Format::Unknown)) return false;
|
||||
return test_v[dfv];
|
||||
}
|
||||
protected:
|
||||
std::mutex mtx;
|
||||
std::vector<bool> test_v;
|
||||
std::mutex mtx;
|
||||
std::vector<bool> test_v;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Data_Source : public std::enable_shared_from_this<Data_Source>, public Data_Source_Handler {
|
||||
class Data_Source : public std::enable_shared_from_this<Data_Source>,
|
||||
public Data_Source_Handler {
|
||||
public:
|
||||
std::shared_ptr<Data_Source> that();
|
||||
virtual concurrencpp::result<std::string> read_coro() {co_return "";};
|
||||
bool registered() const;
|
||||
virtual Psc::JSON get_custom_state_json() = 0;
|
||||
Psc::JSON get_state();
|
||||
std::string last_char; // 用于处理奇数字节
|
||||
Data_Source();
|
||||
concurrencpp::result<void> loop_coro(std::shared_ptr<concurrencpp::worker_thread_executor> executor) override;
|
||||
std::shared_ptr<SSR::Mode_Msg> last_prase_msg = nullptr;
|
||||
virtual concurrencpp::result<void> handle_in_loop_coro(){co_return;}
|
||||
std::string type;
|
||||
std::atomic<bool> base_station_show{};
|
||||
std::atomic<bool> aircraft_show{};
|
||||
std::atomic<bool> show_icao = true;
|
||||
std::atomic<bool> show_call_sign = false;
|
||||
std::atomic<bool> show_fly_status = false;
|
||||
std::atomic<bool> keep_mode = true;
|
||||
double lat{};
|
||||
double lon{};
|
||||
double alt{};
|
||||
std::atomic<bool> update_form_gps{};
|
||||
std::string color = "#1677ff";
|
||||
int aircraft_pixel_size{};
|
||||
Frequency_Limit statistic_fl;
|
||||
std::string thread_key() const;
|
||||
Psc::JSON statistic_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
Ret_J(enable);
|
||||
Ret_J(type);
|
||||
ret.append({"aircraft_total", get_aircraft_num()});
|
||||
ret.append({"aircraft_with_position", have_pos_aircraft_num});
|
||||
ret.append({"mode_ac_statistic", mode_ac_statistic.to_json()});
|
||||
ret.append({"mode_s_statistic", mode_s_statistic.to_json()});
|
||||
ret.append({"all_connect_feed", get_all_connect_feed_status()});
|
||||
return ret;
|
||||
}
|
||||
virtual Psc::JSON to_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
Ret_J(key);
|
||||
Ret_J(enable);
|
||||
Ret_J(base_station_show);
|
||||
Ret_J(aircraft_show);
|
||||
Ret_J(color);
|
||||
Ret_J(aircraft_pixel_size);
|
||||
Ret_J(type);
|
||||
Ret_J(lat);
|
||||
Ret_J(lon);
|
||||
Ret_J(alt);
|
||||
Ret_J(update_form_gps);
|
||||
Ret_J(show_icao);
|
||||
Ret_J(show_call_sign);
|
||||
Ret_J(show_fly_status);
|
||||
Ret_J(keep_mode);
|
||||
// ret.append({"parse_format", parse_format->to_json()});
|
||||
return ret;
|
||||
}
|
||||
virtual void from_json(const Psc::JSON *that_json) {
|
||||
Get_J(key);
|
||||
Get_J(enable);
|
||||
Get_J(base_station_show);
|
||||
Get_J(aircraft_show);
|
||||
Get_J(color);
|
||||
Get_J(aircraft_pixel_size);
|
||||
Get_J(type);
|
||||
Get_J(lat);
|
||||
Get_J(lon);
|
||||
Get_J(alt);
|
||||
Get_J(update_form_gps);
|
||||
Get_J(show_icao);
|
||||
Get_J(show_call_sign);
|
||||
Get_J(show_fly_status);
|
||||
Get_J(keep_mode);
|
||||
// parse_format->from_json(that_json->get("parse_format"));
|
||||
}
|
||||
std::string buffer;
|
||||
std::shared_ptr<Data_Source> that();
|
||||
virtual concurrencpp::result<std::string> read_coro() { co_return ""; };
|
||||
bool registered() const;
|
||||
virtual Psc::JSON get_custom_state_json() = 0;
|
||||
Psc::JSON get_state();
|
||||
std::string last_char; // 用于处理奇数字节
|
||||
Data_Source();
|
||||
concurrencpp::result<void> loop_coro(
|
||||
std::shared_ptr<concurrencpp::worker_thread_executor> executor) override;
|
||||
std::shared_ptr<SSR::Mode_Msg> last_prase_msg = nullptr;
|
||||
virtual concurrencpp::result<void> handle_in_loop_coro() { co_return; }
|
||||
std::string type;
|
||||
std::atomic<bool> base_station_show{};
|
||||
std::atomic<bool> aircraft_show{};
|
||||
std::atomic<bool> show_icao = true;
|
||||
std::atomic<bool> show_call_sign = false;
|
||||
std::atomic<bool> show_fly_status = false;
|
||||
std::atomic<bool> keep_mode = true;
|
||||
double lat{};
|
||||
double lon{};
|
||||
double alt{};
|
||||
std::atomic<bool> update_form_gps{};
|
||||
std::string color = "#1677ff";
|
||||
int aircraft_pixel_size{};
|
||||
Frequency_Limit statistic_fl;
|
||||
std::string thread_key() const;
|
||||
Psc::JSON statistic_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
Ret_J(enable);
|
||||
Ret_J(type);
|
||||
ret.append({"aircraft_total", get_aircraft_num()});
|
||||
ret.append({"aircraft_with_position", have_pos_aircraft_num});
|
||||
ret.append({"mode_ac_statistic", mode_ac_statistic.to_json()});
|
||||
ret.append({"mode_s_statistic", mode_s_statistic.to_json()});
|
||||
ret.append({"all_connect_feed", get_all_connect_feed_status()});
|
||||
return ret;
|
||||
}
|
||||
virtual Psc::JSON to_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
Ret_J(key);
|
||||
Ret_J(enable);
|
||||
Ret_J(base_station_show);
|
||||
Ret_J(aircraft_show);
|
||||
Ret_J(color);
|
||||
Ret_J(aircraft_pixel_size);
|
||||
Ret_J(type);
|
||||
Ret_J(lat);
|
||||
Ret_J(lon);
|
||||
Ret_J(alt);
|
||||
Ret_J(update_form_gps);
|
||||
Ret_J(show_icao);
|
||||
Ret_J(show_call_sign);
|
||||
Ret_J(show_fly_status);
|
||||
Ret_J(keep_mode);
|
||||
// ret.append({"parse_format", parse_format->to_json()});
|
||||
return ret;
|
||||
}
|
||||
virtual void from_json(const Psc::JSON *that_json) {
|
||||
Get_J(key);
|
||||
Get_J(enable);
|
||||
Get_J(base_station_show);
|
||||
Get_J(aircraft_show);
|
||||
Get_J(color);
|
||||
Get_J(aircraft_pixel_size);
|
||||
Get_J(type);
|
||||
Get_J(lat);
|
||||
Get_J(lon);
|
||||
Get_J(alt);
|
||||
Get_J(update_form_gps);
|
||||
Get_J(show_icao);
|
||||
Get_J(show_call_sign);
|
||||
Get_J(show_fly_status);
|
||||
Get_J(keep_mode);
|
||||
// parse_format->from_json(that_json->get("parse_format"));
|
||||
}
|
||||
std::string buffer;
|
||||
};
|
||||
|
||||
|
||||
class TCP_Client_Data_Source : public Data_Source {
|
||||
public:
|
||||
concurrencpp::result<void> handle_in_loop_coro() override {
|
||||
co_await cli.tick_coro();
|
||||
co_return;
|
||||
}
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto& state = cli.state;
|
||||
return VAR_JSON_1(state);
|
||||
}
|
||||
Psc::asio_socket::TCP_Client_Coro cli;
|
||||
std::string ip;
|
||||
std::uint16_t port{};
|
||||
concurrencpp::result<void> handle_in_loop_coro() override {
|
||||
co_await cli.tick_coro();
|
||||
co_return;
|
||||
}
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto &state = cli.state;
|
||||
return VAR_JSON_1(state);
|
||||
}
|
||||
Psc::asio_socket::TCP_Client_Coro cli;
|
||||
std::string ip;
|
||||
std::uint16_t port{};
|
||||
|
||||
~TCP_Client_Data_Source() override = default;
|
||||
TCP_Client_Data_Source() {
|
||||
type = "TCP_Client_Data_Source";
|
||||
}
|
||||
concurrencpp::result<void> _open() override {
|
||||
Psc::asio_socket::Sockaddr_In addr;
|
||||
addr.ip = ip;
|
||||
addr.port = port;
|
||||
cli.set_dest_address(addr);
|
||||
cli.create();
|
||||
co_await cli.connect_coro();
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<void> _close() override {
|
||||
co_await cli.close_coro();
|
||||
co_return;
|
||||
}
|
||||
~TCP_Client_Data_Source() override = default;
|
||||
TCP_Client_Data_Source() { type = "TCP_Client_Data_Source"; }
|
||||
concurrencpp::result<void> _open() override {
|
||||
Psc::asio_socket::Sockaddr_In addr;
|
||||
addr.ip = ip;
|
||||
addr.port = port;
|
||||
cli.set_dest_address(addr);
|
||||
cli.create();
|
||||
co_await cli.connect_coro();
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<void> _close() override {
|
||||
co_await cli.close_coro();
|
||||
co_return;
|
||||
}
|
||||
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(ip);
|
||||
Ret_J(port);
|
||||
return ret;
|
||||
}
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(ip);
|
||||
Get_J(port);
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(ip);
|
||||
Ret_J(port);
|
||||
return ret;
|
||||
}
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(ip);
|
||||
Get_J(port);
|
||||
}
|
||||
|
||||
|
||||
concurrencpp::result<std::string> read_coro() override {
|
||||
co_return co_await cli.read_coro();
|
||||
}
|
||||
concurrencpp::result<std::string> read_coro() override {
|
||||
co_return co_await cli.read_coro();
|
||||
}
|
||||
};
|
||||
class Serial_Data_Source : public Data_Source {
|
||||
public:
|
||||
std::string port_name;
|
||||
Baud_Rate_Type baud_rate{};
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
return Psc::JSON::object();
|
||||
}
|
||||
Serial_Data_Source() { this->type = "Serial_Data_Source"; }
|
||||
concurrencpp::result<void> _open() override {
|
||||
serial = std::make_unique<Psc::serial::Serial_Coro>();
|
||||
serial->set_serial_name(port_name);
|
||||
serial->set_baud_rate(baud_rate);
|
||||
serial->set_parity(Psc::serial::Parity::NoParity);
|
||||
serial->set_data_bits(Psc::serial::DataBits::Data8);
|
||||
serial->set_stop_bits(Psc::serial::StopBits::OneStop);
|
||||
serial->set_flow_control(Psc::serial::FlowControl::HardwareControl);
|
||||
serial->set_buffer_byte_size(10 * 1024);
|
||||
bool ok = serial->open();
|
||||
if (!ok) {
|
||||
std::cerr << "createSerial " + port_name + ":" + std::to_string(baud_rate) + " 打开串口失败!\n";
|
||||
} else {
|
||||
// std::cerr << "createSerial " + serial_name + ":" + std::to_string(baud_rate) + " 打开串口成功!\n";
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<void> _close() override {
|
||||
if (serial) serial->close();
|
||||
co_return;
|
||||
std::string port_name;
|
||||
Baud_Rate_Type baud_rate{};
|
||||
Psc::JSON get_custom_state_json() override { return Psc::JSON::object(); }
|
||||
Serial_Data_Source() { this->type = "Serial_Data_Source"; }
|
||||
concurrencpp::result<void> _open() override {
|
||||
serial = std::make_unique<Psc::serial::Serial_Coro>();
|
||||
serial->set_serial_name(port_name);
|
||||
serial->set_baud_rate(baud_rate);
|
||||
serial->set_parity(Psc::serial::Parity::NoParity);
|
||||
serial->set_data_bits(Psc::serial::DataBits::Data8);
|
||||
serial->set_stop_bits(Psc::serial::StopBits::OneStop);
|
||||
serial->set_flow_control(Psc::serial::FlowControl::HardwareControl);
|
||||
serial->set_buffer_byte_size(10 * 1024);
|
||||
bool ok = serial->open();
|
||||
if (!ok) {
|
||||
std::cerr << "createSerial " + port_name + ":" +
|
||||
std::to_string(baud_rate) + " 打开串口失败!\n";
|
||||
} else {
|
||||
// std::cerr << "createSerial " + serial_name + ":" +
|
||||
// std::to_string(baud_rate) + " 打开串口成功!\n";
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<void> _close() override {
|
||||
if (serial)
|
||||
serial->close();
|
||||
co_return;
|
||||
}
|
||||
|
||||
concurrencpp::result<void> handle_in_loop_coro() override {
|
||||
if (serial) {
|
||||
co_await serial->tick_coro();
|
||||
}
|
||||
co_return;
|
||||
concurrencpp::result<void> handle_in_loop_coro() override {
|
||||
if (serial) {
|
||||
co_await serial->tick_coro();
|
||||
}
|
||||
concurrencpp::result<std::string> read_coro() override {
|
||||
if (!serial) {
|
||||
co_return "";
|
||||
}
|
||||
co_return co_await serial->read_coro();
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<std::string> read_coro() override {
|
||||
if (!serial) {
|
||||
co_return "";
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(port_name);
|
||||
Ret_J(baud_rate);
|
||||
return ret;
|
||||
}
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(port_name) Get_J(baud_rate);
|
||||
}
|
||||
std::unique_ptr<Psc::serial::Serial_Coro> serial{};
|
||||
~Serial_Data_Source() override {
|
||||
if (serial) {
|
||||
serial->close();
|
||||
}
|
||||
co_return co_await serial->read_coro();
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(port_name);
|
||||
Ret_J(baud_rate);
|
||||
return ret;
|
||||
}
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(port_name) Get_J(baud_rate);
|
||||
}
|
||||
std::unique_ptr<Psc::serial::Serial_Coro> serial{};
|
||||
~Serial_Data_Source() override {
|
||||
if (serial) {
|
||||
serial->close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
enum class File_Data_Type {
|
||||
SIMPLE_BIN_Blank, // 没有1a转义�?
|
||||
BIN_Blank_Text,
|
||||
AVR,
|
||||
BIN_Text,
|
||||
BIN_Blank_One_Line_With_Escape,
|
||||
BIN_Blank_One_Line_No_Escape,
|
||||
BIN,
|
||||
Unknown
|
||||
// 纯粹的二进制
|
||||
SIMPLE_BIN_Blank, // 没有1a转义�?
|
||||
BIN_Blank_Text,
|
||||
AVR,
|
||||
BIN_Text,
|
||||
BIN_Blank_One_Line_With_Escape,
|
||||
BIN_Blank_One_Line_No_Escape,
|
||||
BIN,
|
||||
Unknown
|
||||
// 纯粹的二进制
|
||||
};
|
||||
enum Play_Mode { one, loop, analysis, time_batch };
|
||||
|
||||
|
||||
class File_Data_Source : public Data_Source {
|
||||
public:
|
||||
std::string file_path;
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
Play_Mode play_mode = Play_Mode::one;
|
||||
bool have_report_play_back_all_success = false;
|
||||
std::string state = "null";
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto cur_virtual_time = player_clock.get_cur_time_point();
|
||||
auto playback_speed_rate = player_clock.playback_speed_rate;
|
||||
return VAR_JSON_5(cur_virtual_time, playback_speed_rate, state, index, part_infos.size());
|
||||
std::string file_path;
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
Play_Mode play_mode = Play_Mode::one;
|
||||
bool have_report_play_back_all_success = false;
|
||||
std::string state = "null";
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto cur_virtual_time = player_clock.get_cur_time_point();
|
||||
auto playback_speed_rate = player_clock.playback_speed_rate;
|
||||
return VAR_JSON_5(cur_virtual_time, playback_speed_rate, state, index,
|
||||
part_infos.size());
|
||||
}
|
||||
File_Data_Source() { this->type = "File_Data_Source"; }
|
||||
~File_Data_Source() override = default;
|
||||
void before_handle_msg(std::shared_ptr<SSR::Mode_Msg> &msg) override;
|
||||
|
||||
struct Cache_Msg {
|
||||
explicit Cache_Msg(std::shared_ptr<SSR::Mode_S_Msg> msg)
|
||||
: msg(std::move(msg)) {}
|
||||
SSR::Play_Back_Time_Point time() const {
|
||||
return SSR::Play_Back_Time_Point{day_num, msg->mlat_timestamp.daysec};
|
||||
}
|
||||
File_Data_Source() { this->type = "File_Data_Source"; }
|
||||
~File_Data_Source() override = default;
|
||||
void before_handle_msg(std::shared_ptr<SSR::Mode_Msg>& msg) override;
|
||||
std::uint64_t day_num = 0;
|
||||
std::shared_ptr<SSR::Mode_S_Msg> msg;
|
||||
};
|
||||
Player_Clock player_clock;
|
||||
std::shared_ptr<Cache_Msg> pre_cache = nullptr;
|
||||
std::deque<std::shared_ptr<Cache_Msg>> cache_list;
|
||||
|
||||
std::string get_true_file_path() const {
|
||||
return Psc::get_abs_path(file_path);
|
||||
}
|
||||
concurrencpp::result<void> _close() override;
|
||||
concurrencpp::result<void> _open() override;
|
||||
std::vector<std::string> readBinaryFileAsString(const std::string &filepath,
|
||||
size_t part_size);
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(file_path);
|
||||
Get_J(data_type);
|
||||
Get_J(play_mode);
|
||||
}
|
||||
|
||||
struct Cache_Msg {
|
||||
explicit Cache_Msg(std::shared_ptr<SSR::Mode_S_Msg> msg) : msg(std::move(msg)) {}
|
||||
SSR::Play_Back_Time_Point time() const {
|
||||
return SSR::Play_Back_Time_Point{day_num, msg->mlat_timestamp.daysec};
|
||||
}
|
||||
std::uint64_t day_num = 0;
|
||||
std::shared_ptr<SSR::Mode_S_Msg> msg;
|
||||
};
|
||||
Player_Clock player_clock;
|
||||
std::shared_ptr<Cache_Msg> pre_cache = nullptr;
|
||||
std::deque<std::shared_ptr<Cache_Msg>> cache_list;
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(file_path);
|
||||
Ret_J(data_type);
|
||||
Ret_J(play_mode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void origin_data_transform_mode_data(std::string &data) override;
|
||||
|
||||
void handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> msg) override;
|
||||
|
||||
std::string get_true_file_path() const { return Psc::get_abs_path(file_path); }
|
||||
concurrencpp::result<void> _close() override;
|
||||
concurrencpp::result<void> _open() override;
|
||||
std::vector<std::string> readBinaryFileAsString(const std::string& filepath, size_t part_size);
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(file_path);
|
||||
Get_J(data_type);
|
||||
Get_J(play_mode);
|
||||
}
|
||||
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(file_path);
|
||||
Ret_J(data_type);
|
||||
Ret_J(play_mode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void origin_data_transform_mode_data(std::string& data) override;
|
||||
|
||||
|
||||
void handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> msg) override;
|
||||
|
||||
protected:
|
||||
std::optional<std::string> get_raw_line(int &ret_index);
|
||||
long long index = 0;
|
||||
std::vector<std::string> part_infos;
|
||||
std::mutex mtx;
|
||||
protected:
|
||||
std::optional<std::string> get_raw_line(int &ret_index);
|
||||
long long index = 0;
|
||||
std::vector<std::string> part_infos;
|
||||
std::mutex mtx;
|
||||
};
|
||||
class Dll_Data_Source : public Data_Source {
|
||||
public:
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto ret = VAR_JSON_1(state);
|
||||
ret.append({"read_vaild_len", vs.to_string()});
|
||||
return ret;
|
||||
}
|
||||
Psc::Value_Statistics vs;
|
||||
std::string library_path;
|
||||
std::string function_name;
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
Dll_Data_Source() { this->type = "Dll_Data_Source"; }
|
||||
~Dll_Data_Source() override = default;
|
||||
std::size_t buffer_size{};
|
||||
std::vector<std::uint8_t> buffer;
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(library_path);
|
||||
Get_J(function_name);
|
||||
Get_J(data_type);
|
||||
Get_J(buffer_size);
|
||||
buffer.resize(buffer_size);
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(library_path);
|
||||
Ret_J(function_name);
|
||||
Ret_J(data_type);
|
||||
Ret_J(buffer_size);
|
||||
return ret;
|
||||
}
|
||||
void *lib{};
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
auto ret = VAR_JSON_1(state);
|
||||
ret.append({"read_vaild_len", vs.to_string()});
|
||||
return ret;
|
||||
}
|
||||
Psc::Value_Statistics vs;
|
||||
std::string library_path;
|
||||
std::string function_name;
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
Dll_Data_Source() { this->type = "Dll_Data_Source"; }
|
||||
~Dll_Data_Source() override = default;
|
||||
std::size_t buffer_size{};
|
||||
std::vector<std::uint8_t> buffer;
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(library_path);
|
||||
Get_J(function_name);
|
||||
Get_J(data_type);
|
||||
Get_J(buffer_size);
|
||||
buffer.resize(buffer_size);
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(library_path);
|
||||
Ret_J(function_name);
|
||||
Ret_J(data_type);
|
||||
Ret_J(buffer_size);
|
||||
return ret;
|
||||
}
|
||||
void *lib{};
|
||||
|
||||
using Func_Type = size_t (*)(char *buf, std::size_t max_len);
|
||||
// using Func_Type = std::uint16_t (*)(char *buf, std::uint16_t max_len);
|
||||
Func_Type read_func_ptr{};
|
||||
using Func_Type = size_t (*)(char *buf, std::size_t max_len);
|
||||
// using Func_Type = std::uint16_t (*)(char *buf, std::uint16_t max_len);
|
||||
Func_Type read_func_ptr{};
|
||||
|
||||
using Call_Back = void (*)(char *buf, std::size_t len);
|
||||
using set_Call_back = void (*)(Call_Back);
|
||||
|
||||
using Call_Back = void (*)(char *buf, std::size_t len);
|
||||
using set_Call_back = void (*)(Call_Back);
|
||||
|
||||
std::string state;
|
||||
concurrencpp::result<void> _close() override {
|
||||
Psc::free_library(lib);
|
||||
std::string state;
|
||||
concurrencpp::result<void> _close() override {
|
||||
Psc::free_library(lib);
|
||||
co_return;
|
||||
}
|
||||
concurrencpp::result<void> _open() override {
|
||||
{
|
||||
auto r = Psc::try_load_library(Psc::get_abs_path(library_path));
|
||||
if (!r) {
|
||||
state = r.error().message();
|
||||
co_return;
|
||||
}
|
||||
lib = r.value();
|
||||
}
|
||||
concurrencpp::result<void> _open() override {
|
||||
{
|
||||
auto r = Psc::try_load_library(Psc::get_abs_path(library_path));
|
||||
if (!r) {
|
||||
state = r.error().message();
|
||||
co_return;
|
||||
}
|
||||
lib = r.value();
|
||||
}
|
||||
{
|
||||
auto r = Psc::try_load_function(lib, function_name);
|
||||
if (!r) {
|
||||
state = r.error().message();
|
||||
std::cout << LOG_POS << " [" << function_name << "] 函数指针加载失败!" << std::endl;
|
||||
co_return;
|
||||
}
|
||||
read_func_ptr = (Func_Type) r.value();
|
||||
}
|
||||
state = "加载成功";
|
||||
{
|
||||
auto r = Psc::try_load_function(lib, function_name);
|
||||
if (!r) {
|
||||
state = r.error().message();
|
||||
std::cout << LOG_POS << " [" << function_name << "] 函数指针加载失败!"
|
||||
<< std::endl;
|
||||
co_return;
|
||||
}
|
||||
read_func_ptr = (Func_Type)r.value();
|
||||
}
|
||||
void origin_data_transform_mode_data(std::string& data) override;
|
||||
state = "加载成功";
|
||||
co_return;
|
||||
}
|
||||
void origin_data_transform_mode_data(std::string &data) override;
|
||||
};
|
||||
|
||||
|
||||
class Shared_Memory_Data_Source : public Data_Source {
|
||||
public:
|
||||
Psc::JSON get_custom_state_json() override {
|
||||
return Psc::JSON::object();
|
||||
}
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(shared_memory_name);
|
||||
Get_J(shared_memory_size);
|
||||
Get_J(data_type);
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(shared_memory_name);
|
||||
Ret_J(shared_memory_size);
|
||||
Ret_J(data_type);
|
||||
return ret;
|
||||
}
|
||||
concurrencpp::result<void> _open() override;
|
||||
concurrencpp::result<void> _close() override;
|
||||
Psc::JSON get_custom_state_json() override { return Psc::JSON::object(); }
|
||||
void from_json(const Psc::JSON *that_json) override {
|
||||
Data_Source::from_json(that_json);
|
||||
Get_J(shared_memory_name);
|
||||
Get_J(shared_memory_size);
|
||||
Get_J(data_type);
|
||||
}
|
||||
Psc::JSON to_json() override {
|
||||
Psc::JSON ret = Data_Source::to_json();
|
||||
Ret_J(shared_memory_name);
|
||||
Ret_J(shared_memory_size);
|
||||
Ret_J(data_type);
|
||||
return ret;
|
||||
}
|
||||
concurrencpp::result<void> _open() override;
|
||||
concurrencpp::result<void> _close() override;
|
||||
|
||||
void origin_data_transform_mode_data(std::string &data) override;
|
||||
|
||||
void origin_data_transform_mode_data(std::string& data) override;
|
||||
protected:
|
||||
std::unique_ptr<Psc::SM_RingBuffer> sm;
|
||||
std::string shared_memory_name;
|
||||
std::uint64_t shared_memory_size{};
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
std::unique_ptr<Psc::SM_RingBuffer> sm;
|
||||
std::string shared_memory_name;
|
||||
std::uint64_t shared_memory_size{};
|
||||
File_Data_Type data_type = File_Data_Type::BIN_Blank_Text;
|
||||
};
|
||||
|
||||
|
||||
inline std::shared_ptr<Data_Source> create_data_source_from_type(const std::string &t) {
|
||||
std::shared_ptr<Data_Source> ret{};
|
||||
if (t == "Serial_Data_Source")
|
||||
ret = std::make_shared<Serial_Data_Source>();
|
||||
else if (t == "TCP_Client_Data_Source")
|
||||
ret = std::make_shared<TCP_Client_Data_Source>();
|
||||
else if (t == "File_Data_Source")
|
||||
ret = std::make_shared<File_Data_Source>();
|
||||
else if (t == "Dll_Data_Source")
|
||||
ret = std::make_shared<Dll_Data_Source>();
|
||||
else if (t == "Shared_Memory_Data_Source")
|
||||
ret = std::make_shared<Shared_Memory_Data_Source>();
|
||||
else {
|
||||
std::cout << "未知�?Data_Source type类型!" << std::endl;
|
||||
throw std::invalid_argument("unknown Data_Source type: " + t);
|
||||
}
|
||||
return ret;
|
||||
inline std::shared_ptr<Data_Source>
|
||||
create_data_source_from_type(const std::string &t) {
|
||||
std::shared_ptr<Data_Source> ret{};
|
||||
if (t == "Serial_Data_Source")
|
||||
ret = std::make_shared<Serial_Data_Source>();
|
||||
else if (t == "TCP_Client_Data_Source")
|
||||
ret = std::make_shared<TCP_Client_Data_Source>();
|
||||
else if (t == "File_Data_Source")
|
||||
ret = std::make_shared<File_Data_Source>();
|
||||
else if (t == "Dll_Data_Source")
|
||||
ret = std::make_shared<Dll_Data_Source>();
|
||||
else if (t == "Shared_Memory_Data_Source")
|
||||
ret = std::make_shared<Shared_Memory_Data_Source>();
|
||||
else {
|
||||
std::cout << "未知�?Data_Source type类型!" << std::endl;
|
||||
throw std::invalid_argument("unknown Data_Source type: " + t);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
struct Data_Source_Config {
|
||||
Ordered_Map<std::string, std::shared_ptr<Data_Source>> map;
|
||||
Data_Source_Config() = default;
|
||||
void init(const Psc::JSON *that_json) {
|
||||
auto list = that_json->get("list");
|
||||
for (auto &it: list->children) {
|
||||
auto ds = create_from_json(&it);
|
||||
map.push_back(ds);
|
||||
}
|
||||
Ordered_Map<std::string, std::shared_ptr<Data_Source>> map;
|
||||
Data_Source_Config() = default;
|
||||
void init(const Psc::JSON *that_json) {
|
||||
auto list = that_json->get("list");
|
||||
for (auto &it : list->children) {
|
||||
auto ds = create_from_json(&it);
|
||||
map.push_back(ds);
|
||||
}
|
||||
Psc::JSON list() {
|
||||
auto connect_json = Psc::JSON::array();
|
||||
for (auto &it: map.list()) {
|
||||
connect_json.children.emplace_back(it->to_json());
|
||||
}
|
||||
return connect_json;
|
||||
}
|
||||
Psc::JSON list() {
|
||||
auto connect_json = Psc::JSON::array();
|
||||
for (auto &it : map.list()) {
|
||||
connect_json.children.emplace_back(it->to_json());
|
||||
}
|
||||
Psc::JSON to_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
ret.append({"list", list()});
|
||||
return ret;
|
||||
}
|
||||
void server(Global *g);
|
||||
return connect_json;
|
||||
}
|
||||
Psc::JSON to_json() {
|
||||
Psc::JSON ret = Psc::JSON::object();
|
||||
ret.append({"list", list()});
|
||||
return ret;
|
||||
}
|
||||
void server(Global *g);
|
||||
};
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,334 +6,314 @@
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
Aircraft::Aircraft(const std::string &icao) : Aircraft_Info(icao) {
|
||||
auto size = Global::instance()->mode_acs.max_track_point_size.load();
|
||||
air_pos_track_list.init(size);
|
||||
surface_pos_track_list.init(size);
|
||||
Aircraft::Aircraft(const std::string &icao) : Aircraft_Info(icao) {
|
||||
auto size = Global::instance()->mode_acs.max_track_point_size.load();
|
||||
air_pos_track_list.init(size);
|
||||
surface_pos_track_list.init(size);
|
||||
}
|
||||
|
||||
void Aircraft::refresh_external_database_info() {
|
||||
auto& manager = Global::instance()->external_resources_manager;
|
||||
if (!external_database_info_loaded) {
|
||||
external_database_info = manager.query_aircraft_external_databases(icao);
|
||||
external_database_info_loaded = true;
|
||||
}
|
||||
auto &manager = Global::instance()->external_resources_manager;
|
||||
if (!external_database_info_loaded) {
|
||||
external_database_info = manager.query_aircraft_external_databases(icao);
|
||||
external_database_info_loaded = true;
|
||||
}
|
||||
|
||||
auto callsign = flight();
|
||||
if (!callsign) callsign = bds20_call_sign();
|
||||
if (last_external_database_callsign == callsign) {
|
||||
return;
|
||||
}
|
||||
auto callsign = flight();
|
||||
if (!callsign)
|
||||
callsign = bds20_call_sign();
|
||||
if (last_external_database_callsign == callsign) {
|
||||
return;
|
||||
}
|
||||
|
||||
callsign_external_database_info =
|
||||
manager.query_callsign_external_databases(callsign);
|
||||
last_external_database_callsign = std::move(callsign);
|
||||
callsign_external_database_info =
|
||||
manager.query_callsign_external_databases(callsign);
|
||||
last_external_database_callsign = std::move(callsign);
|
||||
}
|
||||
|
||||
std::shared_ptr<SSR::Aircraft_Info> DataBase::get_aircraft(const std::string& icao) {
|
||||
return aircraft_map.get(icao);
|
||||
std::shared_ptr<SSR::Aircraft_Info>
|
||||
DataBase::get_aircraft(const std::string &icao) {
|
||||
return aircraft_map.get(icao);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<SSR::Aircraft_Info> DataBase::create_aircraft(const std::string& icao) {
|
||||
auto ret = aircraft_map.create(icao);
|
||||
ret->refresh_external_database_info();
|
||||
return ret;
|
||||
std::shared_ptr<SSR::Aircraft_Info>
|
||||
DataBase::create_aircraft(const std::string &icao) {
|
||||
auto ret = aircraft_map.create(icao);
|
||||
ret->refresh_external_database_info();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DataBase::delete_timeout_aircraft() {
|
||||
aircraft_map.remove_cond([](const std::shared_ptr<SSR::Aircraft_Info>& item) {
|
||||
if (item->timestamp == 0) {
|
||||
std::cout << "未初始化的 timestamp " << LOG_POS << std::endl;
|
||||
}
|
||||
long long time = std::time(nullptr) - item->timestamp;
|
||||
return time > Global::instance()->mode_acs.timeout_seconds;
|
||||
});
|
||||
aircraft_map.remove_cond([](const std::shared_ptr<SSR::Aircraft_Info> &item) {
|
||||
if (item->timestamp == 0) {
|
||||
std::cout << "未初始化的 timestamp " << LOG_POS << std::endl;
|
||||
}
|
||||
long long time = std::time(nullptr) - item->timestamp;
|
||||
return time > Global::instance()->mode_acs.timeout_seconds;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
JSON DataBase::get_aircraftlist() {
|
||||
JSON json = JSON::array();
|
||||
for (auto& it : aircraft_map.values()) {
|
||||
auto o = Aircraft_List_JSON_Service_O::to_That(this, it.get());
|
||||
json.children.push_back(o.toJson());
|
||||
}
|
||||
return json;
|
||||
JSON json = JSON::array();
|
||||
for (auto &it : aircraft_map.values()) {
|
||||
auto o = Aircraft_List_JSON_Service_O::to_That(this, it.get());
|
||||
json.children.push_back(o.toJson());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
Psc::JSON DataBase::get_aircraftlist(int limit_msg_num) {
|
||||
JSON json = JSON::array();
|
||||
for (auto& it : aircraft_map.values()) {
|
||||
if (it->times < limit_msg_num) continue;
|
||||
auto o = Aircraft_List_JSON_Service_O::to_That(this, it.get());
|
||||
json.children.push_back(o.toJson());
|
||||
}
|
||||
return json;
|
||||
JSON json = JSON::array();
|
||||
for (auto &it : aircraft_map.values()) {
|
||||
if (it->times < limit_msg_num)
|
||||
continue;
|
||||
auto o = Aircraft_List_JSON_Service_O::to_That(this, it.get());
|
||||
json.children.push_back(o.toJson());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
JSON DataBase::get_all_aircraft_json() {
|
||||
JSON json = JSON::array();
|
||||
auto g = Global::instance();
|
||||
size_t num = 0;
|
||||
for (auto& it : aircraft_map.values()) {
|
||||
auto vto = Flight_VTO::to_VTO(it.get());
|
||||
bool have_pos = !it.get()->air_pos_track_list.empty();
|
||||
if (have_pos) {
|
||||
json.children.push_back(vto.toJson());
|
||||
num++;
|
||||
}
|
||||
JSON json = JSON::array();
|
||||
auto g = Global::instance();
|
||||
size_t num = 0;
|
||||
for (auto &it : aircraft_map.values()) {
|
||||
auto vto = Flight_VTO::to_VTO(it.get());
|
||||
bool have_pos = !it.get()->air_pos_track_list.empty();
|
||||
if (have_pos) {
|
||||
json.children.push_back(vto.toJson());
|
||||
num++;
|
||||
}
|
||||
have_pos_aircraft_num = num;
|
||||
return json;
|
||||
}
|
||||
have_pos_aircraft_num = num;
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JSON DataBase::get_aircraft_list_after(time_t timestamp) {
|
||||
JSON json = JSON::array();
|
||||
auto g = Global::instance();
|
||||
for (auto& it : aircraft_map.values()) {
|
||||
auto vto = Flight_VTO::to_VTO(it.get());
|
||||
bool have_pos = !it.get()->air_pos_track_list.empty();
|
||||
if (have_pos && vto.time_stamp > timestamp) {
|
||||
json.children.push_back(vto.toJson());
|
||||
}
|
||||
JSON json = JSON::array();
|
||||
auto g = Global::instance();
|
||||
for (auto &it : aircraft_map.values()) {
|
||||
auto vto = Flight_VTO::to_VTO(it.get());
|
||||
bool have_pos = !it.get()->air_pos_track_list.empty();
|
||||
if (have_pos && vto.time_stamp > timestamp) {
|
||||
json.children.push_back(vto.toJson());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
#ifdef Cache_Some_Mode_S
|
||||
Psc::JSON DataBase::get_limit_mode_s_msg_info() {
|
||||
|
||||
JSON ret = JSON::object();
|
||||
JSON list = JSON::array();
|
||||
std::map<int, size_t> map;
|
||||
std::map<int, size_t> num_test;
|
||||
for (auto& air : aircraft_map.values()) {
|
||||
if (air->total_num > Cache_Some_Mode_S_Num) continue;
|
||||
Psc::JSON air_json = Psc::JSON::object();
|
||||
{
|
||||
Psc::JSON ms = Psc::JSON::array();
|
||||
int n = air->cache.size();
|
||||
for (auto msg : air->cache) {
|
||||
Psc::JSON cur = Psc::JSON::object({
|
||||
{"hex", msg->msg_hex},
|
||||
{"df", to_string(msg->df)}
|
||||
});
|
||||
if (msg->df == Downlink_Format::Extended_Squitter_17) {
|
||||
JSON ret = JSON::object();
|
||||
JSON list = JSON::array();
|
||||
std::map<int, size_t> map;
|
||||
std::map<int, size_t> num_test;
|
||||
for (auto &air : aircraft_map.values()) {
|
||||
if (air->total_num > Cache_Some_Mode_S_Num)
|
||||
continue;
|
||||
Psc::JSON air_json = Psc::JSON::object();
|
||||
{
|
||||
Psc::JSON ms = Psc::JSON::array();
|
||||
int n = air->cache.size();
|
||||
for (auto msg : air->cache) {
|
||||
Psc::JSON cur = Psc::JSON::object(
|
||||
{{"hex", msg->msg_hex}, {"df", to_string(msg->df)}});
|
||||
if (msg->df == Downlink_Format::Extended_Squitter_17) {
|
||||
|
||||
auto tc = type_code(msg->msg_bin);
|
||||
cur.children.push_back({"tc", tc});
|
||||
map[tc]++;
|
||||
num_test[air->total_num] = n;
|
||||
}
|
||||
ms.append(cur);
|
||||
}
|
||||
air_json.children.push_back({"icao", air->icao});
|
||||
air_json.children.push_back({"total_num", air->total_num});
|
||||
air_json.children.push_back({"ms", ms});
|
||||
auto tc = type_code(msg->msg_bin);
|
||||
cur.children.push_back({"tc", tc});
|
||||
map[tc]++;
|
||||
num_test[air->total_num] = n;
|
||||
}
|
||||
list.children.push_back(air_json);
|
||||
ms.append(cur);
|
||||
}
|
||||
air_json.children.push_back({"icao", air->icao});
|
||||
air_json.children.push_back({"total_num", air->total_num});
|
||||
air_json.children.push_back({"ms", ms});
|
||||
}
|
||||
ret.children.push_back({"key", key});
|
||||
for (auto pair : map) {
|
||||
ret.children.push_back({std::to_string(pair.first), pair.second});
|
||||
}
|
||||
Psc::JSON t = Psc::JSON::object();
|
||||
for (auto pair : num_test) {
|
||||
t.children.push_back({std::to_string(pair.first), pair.second});
|
||||
}
|
||||
ret.children.push_back({"数量统计", t});
|
||||
ret.children.push_back({"list", list});
|
||||
return ret;
|
||||
list.children.push_back(air_json);
|
||||
}
|
||||
ret.children.push_back({"key", key});
|
||||
for (auto pair : map) {
|
||||
ret.children.push_back({std::to_string(pair.first), pair.second});
|
||||
}
|
||||
Psc::JSON t = Psc::JSON::object();
|
||||
for (auto pair : num_test) {
|
||||
t.children.push_back({std::to_string(pair.first), pair.second});
|
||||
}
|
||||
ret.children.push_back({"数量统计", t});
|
||||
ret.children.push_back({"list", list});
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t DataBase::get_aircraft_num() { return aircraft_map.size(); }
|
||||
|
||||
#define _init_db \
|
||||
HTTP_REQUIRE_VALUE(data_source_key, params.try_get_string("data_source_key")) \
|
||||
auto db = Global::instance()->source(data_source_key); \
|
||||
if (db == nullptr) { \
|
||||
res->setStatusCode(drogon::k503ServiceUnavailable); \
|
||||
JSON ret; \
|
||||
res->setBody(ret.to_json_string()); \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
void database_server(Global* g) {
|
||||
auto& svr = g->svr;
|
||||
auto& api = g->api;
|
||||
// g->load_aircraft_csv(g->mode_acs.aircraft_csv_path);
|
||||
g->external_resources_manager.load_sqlite_db(
|
||||
Psc::get_abs_path(g->external_resources_manager.ecap_sqlite_path));
|
||||
#define _init_db \
|
||||
HTTP_REQUIRE_VALUE(data_source_key, \
|
||||
params.try_get_string("data_source_key")) \
|
||||
auto db = Global::instance()->source(data_source_key); \
|
||||
if (db == nullptr) { \
|
||||
res->setStatusCode(drogon::k503ServiceUnavailable); \
|
||||
JSON ret; \
|
||||
res->setBody(ret.to_json_string()); \
|
||||
return; \
|
||||
}
|
||||
|
||||
void database_server(Global *g) {
|
||||
auto &svr = g->svr;
|
||||
auto &api = g->api;
|
||||
// g->load_aircraft_csv(g->mode_acs.aircraft_csv_path);
|
||||
g->external_resources_manager.load_sqlite_db(
|
||||
Psc::get_abs_path(g->external_resources_manager.ecap_sqlite_path));
|
||||
|
||||
#ifdef Cache_Some_Mode_S
|
||||
svr.Post(api + "get_cache_some_mode_s_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
auto g = Global::instance();
|
||||
auto ret = JSON::object();
|
||||
if (db) {
|
||||
ret = db->get_limit_mode_s_msg_info();
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_cache_some_mode_s_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db auto g = Global::instance();
|
||||
auto ret = JSON::object();
|
||||
if (db) {
|
||||
ret = db->get_limit_mode_s_msg_info();
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
#endif
|
||||
|
||||
svr.Post(api + "get_base_station_location", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
auto g = Global::instance();
|
||||
auto ret = JSON::object();
|
||||
if (db) {
|
||||
ret = db->base_station.to_Json();
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_base_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
HTTP_REQUIRE_VALUE(icao, params.try_get_string("icao"))
|
||||
auto aircraft = db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr) {
|
||||
auto vto = Flight_VTO::to_VTO(aircraft.get());
|
||||
ret = vto.toJson();
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_detail_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
HTTP_REQUIRE_VALUE(icao, params.try_get_string("icao"))
|
||||
auto aircraft = db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr) {
|
||||
ret = aircraft->toJson();
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_track_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
HTTP_REQUIRE_VALUE(icao, params.try_get_string("icao"))
|
||||
HTTP_REQUIRE_VALUE(last_size, params.try_get_number<std::size_t>("last_size"))
|
||||
auto aircraft = db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr)
|
||||
{
|
||||
ret = aircraft->air_pos_track_list.get_last_array_json(last_size);
|
||||
ret.children.insert(ret.children.begin(), JSON("ds", data_source_key));
|
||||
ret.children.insert(ret.children.begin(), JSON("icao", icao));
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_list_after", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
HTTP_REQUIRE_VALUE(timestamp, params.try_get_number<std::uint32_t>("timestamp"))
|
||||
auto ret = db->get_aircraft_list_after(timestamp);
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_base_station_location", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db auto g = Global::instance();
|
||||
auto ret = JSON::object();
|
||||
if (db) {
|
||||
ret = db->base_station.to_Json();
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_base_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db HTTP_REQUIRE_VALUE(icao,
|
||||
params.try_get_string("icao")) auto aircraft =
|
||||
db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr) {
|
||||
auto vto = Flight_VTO::to_VTO(aircraft.get());
|
||||
ret = vto.toJson();
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_detail_info", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db HTTP_REQUIRE_VALUE(icao,
|
||||
params.try_get_string("icao")) auto aircraft =
|
||||
db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr) {
|
||||
ret = aircraft->toJson();
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_track_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db HTTP_REQUIRE_VALUE(icao, params.try_get_string("icao"))
|
||||
HTTP_REQUIRE_VALUE(last_size, params.try_get_number<std::size_t>(
|
||||
"last_size")) auto aircraft =
|
||||
db->get_aircraft(icao);
|
||||
JSON ret;
|
||||
if (aircraft != nullptr) {
|
||||
ret = aircraft->air_pos_track_list.get_last_array_json(last_size);
|
||||
ret.children.insert(ret.children.begin(), JSON("ds", data_source_key));
|
||||
ret.children.insert(ret.children.begin(), JSON("icao", icao));
|
||||
}
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_aircraft_list_after", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db HTTP_REQUIRE_VALUE(
|
||||
timestamp, params.try_get_number<std::uint32_t>("timestamp")) auto ret =
|
||||
db->get_aircraft_list_after(timestamp);
|
||||
res->setBody(ret.to_json_string());
|
||||
});
|
||||
|
||||
svr.Post(api + "aircraft_change_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db
|
||||
JSON ret = JSON::array();
|
||||
if (db) {
|
||||
ret = db->get_all_aircraft_json();
|
||||
} else
|
||||
{
|
||||
svr.Post(api + "aircraft_change_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
_init_db JSON ret = JSON::array();
|
||||
if (db) {
|
||||
ret = db->get_all_aircraft_json();
|
||||
} else {
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
|
||||
}
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Get(R"(/aircraftlist.json)", [](HTTP_Param) {
|
||||
auto list = Global::instance()->mode_acs.data_source_config.map.list();
|
||||
std::shared_ptr<Data_Source> ts = nullptr;
|
||||
auto ret = JSON::array();
|
||||
for (const auto &li : list) {
|
||||
if (li->enable) {
|
||||
ret = li->get_aircraftlist();
|
||||
break;
|
||||
}
|
||||
}
|
||||
res->setBody(ret.to_json_string("", "\n", ""));
|
||||
});
|
||||
|
||||
// aircraftlist.json 的带数据源版本
|
||||
svr.Post(api + "aircraft_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
auto g = Global::instance();
|
||||
HTTP_REQUIRE_VALUE(data_source_key,
|
||||
params.try_get_string("data_source_key"))
|
||||
std::shared_ptr<Data_Source> db;
|
||||
{
|
||||
db = g->source(data_source_key);
|
||||
}
|
||||
if (db == nullptr) {
|
||||
res->setStatusCode(drogon::k503ServiceUnavailable);
|
||||
JSON ret;
|
||||
res->setBody(ret.to_json_string());
|
||||
return;
|
||||
}
|
||||
|
||||
svr.Get(R"(/aircraftlist.json)", [](HTTP_Param) {
|
||||
auto list = Global::instance()->mode_acs.data_source_config.map.list();
|
||||
std::shared_ptr<Data_Source> ts = nullptr;
|
||||
auto ret = JSON::array();
|
||||
for (const auto& li : list) {
|
||||
if (li->enable) {
|
||||
ret = li->get_aircraftlist();
|
||||
break;
|
||||
}
|
||||
}
|
||||
res->setBody(ret.to_json_string("", "\n", ""));
|
||||
});
|
||||
|
||||
// aircraftlist.json 的带数据源版本
|
||||
svr.Post(api + "aircraft_list", [](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
auto g = Global::instance();
|
||||
HTTP_REQUIRE_VALUE(data_source_key, params.try_get_string("data_source_key"))
|
||||
std::shared_ptr<Data_Source> db;
|
||||
{
|
||||
db = g->source(data_source_key);
|
||||
}
|
||||
if (db == nullptr) {
|
||||
res->setStatusCode(drogon::k503ServiceUnavailable);
|
||||
JSON ret;
|
||||
res->setBody(ret.to_json_string());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto limit_msg_num = g->mode_acs.default_min_aircraft_list_num.load();
|
||||
auto t = params.get("limit_msg_num");
|
||||
if (t) {
|
||||
HTTP_REQUIRE_VALUE(requested_limit_msg_num, t->try_number_val<int>())
|
||||
limit_msg_num = requested_limit_msg_num;
|
||||
}
|
||||
JSON ret = JSON::array();
|
||||
{
|
||||
Scope_Timer timer(
|
||||
"aircraft_list.db_query",
|
||||
g->http_monitor_config.slow_scope_threshold_ms);
|
||||
ret = db->get_aircraftlist(limit_msg_num);
|
||||
}
|
||||
std::string body;
|
||||
{
|
||||
Scope_Timer timer(
|
||||
"aircraft_list.json_serialization",
|
||||
g->http_monitor_config.slow_scope_threshold_ms);
|
||||
body = warp(ret).to_json_string();
|
||||
}
|
||||
res->setBody(body);
|
||||
});
|
||||
|
||||
auto limit_msg_num = g->mode_acs.default_min_aircraft_list_num.load();
|
||||
auto t = params.get("limit_msg_num");
|
||||
if (t) {
|
||||
HTTP_REQUIRE_VALUE(requested_limit_msg_num, t->try_number_val<int>())
|
||||
limit_msg_num = requested_limit_msg_num;
|
||||
}
|
||||
JSON ret = JSON::array();
|
||||
{
|
||||
Scope_Timer timer("aircraft_list.db_query",
|
||||
g->http_monitor_config.slow_scope_threshold_ms);
|
||||
ret = db->get_aircraftlist(limit_msg_num);
|
||||
}
|
||||
std::string body;
|
||||
{
|
||||
Scope_Timer timer("aircraft_list.json_serialization",
|
||||
g->http_monitor_config.slow_scope_threshold_ms);
|
||||
body = warp(ret).to_json_string();
|
||||
}
|
||||
res->setBody(body);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static std::string output;
|
||||
|
||||
static void log_i(const std::string& label, const std::string& value,
|
||||
const std::string& unit = "") {
|
||||
std::ostringstream oss;
|
||||
// Format the label and value
|
||||
oss << std::left << std::setw(30) << label << ": " << value;
|
||||
// Add unit if not empty
|
||||
if (!unit.empty()) {
|
||||
oss << " " << unit << "\n";
|
||||
} else {
|
||||
oss << "\n";
|
||||
}
|
||||
// Append formatted string to output
|
||||
output += oss.str();
|
||||
static void log_i(const std::string &label, const std::string &value,
|
||||
const std::string &unit = "") {
|
||||
std::ostringstream oss;
|
||||
// Format the label and value
|
||||
oss << std::left << std::setw(30) << label << ": " << value;
|
||||
// Add unit if not empty
|
||||
if (!unit.empty()) {
|
||||
oss << " " << unit << "\n";
|
||||
} else {
|
||||
oss << "\n";
|
||||
}
|
||||
// Append formatted string to output
|
||||
output += oss.str();
|
||||
}
|
||||
|
||||
static void log_i(const std::string& label, double value,
|
||||
const std::string& unit = "") {
|
||||
log_i(label, std::to_string(value), unit);
|
||||
static void log_i(const std::string &label, double value,
|
||||
const std::string &unit = "") {
|
||||
log_i(label, std::to_string(value), unit);
|
||||
}
|
||||
|
||||
@@ -4,22 +4,20 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
struct Player_Clock {
|
||||
using clock = std::chrono::system_clock;
|
||||
SSR::Play_Back_Time_Point start_time; // 抽象时间起点
|
||||
std::chrono::time_point<std::chrono::system_clock> true_start_time; // 真正开始回放的墙钟起点
|
||||
SSR::Play_Back_Time_Point start_time; // 抽象时间起点
|
||||
std::chrono::time_point<std::chrono::system_clock>
|
||||
true_start_time; // 真正开始回放的墙钟起点
|
||||
double playback_speed_rate = 20.0;
|
||||
Player_Clock() {
|
||||
true_start_time = clock::now();
|
||||
}
|
||||
Player_Clock() { true_start_time = clock::now(); }
|
||||
SSR::Play_Back_Time_Point get_cur_time_point() const noexcept {
|
||||
|
||||
const auto now = clock::now();
|
||||
|
||||
// 防御:系统时间回拨或还没初始化导致 now < true_start_time
|
||||
const double real_elapsed_sec =
|
||||
std::max(0.0, std::chrono::duration<double>(now - true_start_time).count());
|
||||
const double real_elapsed_sec = std::max(
|
||||
0.0, std::chrono::duration<double>(now - true_start_time).count());
|
||||
|
||||
const double sim_elapsed_sec = real_elapsed_sec * playback_speed_rate;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user