This commit is contained in:
2026-08-05 11:59:45 +08:00
parent 18e64dfe22
commit 587c1d6d01
22 changed files with 2517 additions and 3049 deletions
+59 -63
View File
@@ -5,7 +5,7 @@ namespace Psc {
class SM_RingBuffer;
}
class Data_Source;
std::shared_ptr<Data_Source> create_from_json(const Psc::JSON* that_json);
std::shared_ptr<Data_Source> create_from_json(const Psc::JSON* that_json, bool not_exist_use_default_value);
class Input_Format {
public:
Input_Format() {
@@ -17,7 +17,8 @@ public:
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;
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});
@@ -29,7 +30,8 @@ public:
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;
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;
@@ -38,12 +40,14 @@ public:
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;
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;
if (dfv >= static_cast<std::uint8_t>(SSR::Downlink_Format::Unknown))
return false;
return test_v[dfv];
}
protected:
@@ -77,12 +81,12 @@ public:
ret.append({"map3d", map3d.to_base_json()});
return ret;
}
void from_base_json(const Psc::JSON* that_json) {
void from_base_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
if (that_json == nullptr || that_json->valueType != Psc::Object) {
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "map_display");
}
map2d.from_base_json(that_json->get("map2d"));
map3d.from_base_json(that_json->get("map3d"));
map2d.from_base_json(that_json->get("map2d"), not_exist_use_default_value);
map3d.from_base_json(that_json->get("map3d"), not_exist_use_default_value);
}
};
class Data_Source_Data {
@@ -97,29 +101,18 @@ public:
Psc::Copyable_Atomic<bool> keep_mode = true;
[[nodiscard]] Psc::JSON to_base_json() const {
auto ret = Psc::JSON::object();
Ret_J(base_station_has_valid_position)
ret.append({"map_display", map_display.to_base_json()});
Ret_J(lat)
Ret_J(lon)
Ret_J(alt)
Ret_J(ignore_msg_time)
Ret_J(update_form_gps)
Ret_J(keep_mode)
return ret;
Ret_J(base_station_has_valid_position) ret.append({"map_display", map_display.to_base_json()});
Ret_J(lat) Ret_J(lon) Ret_J(alt) Ret_J(ignore_msg_time) Ret_J(update_form_gps) Ret_J(keep_mode) return ret;
}
void from_base_json(const Psc::JSON* that_json) {
void from_base_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
Get_J(base_station_has_valid_position)
map_display.from_base_json(that_json->get("map_display"));
Get_J(lat)
Get_J(lon)
Get_J(alt)
Get_J(ignore_msg_time)
Get_J(update_form_gps)
Get_J(keep_mode)
map_display.from_base_json(that_json->get("map_display"), not_exist_use_default_value);
Get_J(lat) Get_J(lon) Get_J(alt) Get_J(ignore_msg_time) Get_J(update_form_gps) Get_J(keep_mode)
}
};
class Data_Source : public std::enable_shared_from_this<Data_Source>,
public Data_Source_Handler, public Data_Source_Data {
public Data_Source_Handler,
public Data_Source_Data {
public:
std::shared_ptr<Data_Source> that();
virtual asio::awaitable<std::string> read_coro() {
@@ -149,9 +142,9 @@ public:
virtual Psc::JSON to_json() {
return With_Loop_Coro::to_base_json() += Data_Source_Data::to_base_json();
}
virtual void from_json(const Psc::JSON* that_json) {
With_Loop_Coro::from_base_json(that_json);
Data_Source_Data::from_base_json(that_json);
virtual void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
With_Loop_Coro::from_base_json(that_json, not_exist_use_default_value);
Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
}
std::string buffer;
std::atomic_bool ask_sleep = false;
@@ -193,9 +186,9 @@ public:
Psc::JSON to_json() override {
return Data_Source::to_json() += TCP_Client_Data_Source_Data::to_base_json();
}
void from_json(const Psc::JSON* that_json) override {
Data_Source::from_json(that_json);
TCP_Client_Data_Source_Data::from_base_json(that_json);
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Source::from_json(that_json, not_exist_use_default_value);
TCP_Client_Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
}
asio::awaitable<std::string> read_coro() override {
co_return co_await cli.read_coro();
@@ -226,8 +219,7 @@ public:
serial->set_buffer_byte_size(10 * 1024);
bool ok = serial->open();
if (!ok) {
std::cerr << "createSerial " + port_name + ":" +
std::to_string(baud_rate) + " 打开串口失败!\n";
std::cerr << "createSerial " + port_name + ":" + std::to_string(baud_rate) + " 打开串口失败!\n";
}
else {
// std::cerr << "createSerial " + serial_name + ":" +
@@ -236,7 +228,8 @@ public:
co_return;
}
asio::awaitable<void> _close() override {
if (serial) serial->close();
if (serial)
serial->close();
co_return;
}
asio::awaitable<void> handle_in_loop_coro() override {
@@ -254,9 +247,9 @@ public:
Psc::JSON to_json() override {
return Data_Source::to_json() += Serial_Data_Source_Data::to_base_json();
}
void from_json(const Psc::JSON* that_json) override {
Data_Source::from_json(that_json);
Serial_Data_Source_Data::from_base_json(that_json);
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Source::from_json(that_json, not_exist_use_default_value);
Serial_Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
}
std::unique_ptr<Psc::serial::Serial_Coro> serial{};
~Serial_Data_Source() override {
@@ -291,8 +284,7 @@ public:
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());
return VAR_JSON_5(cur_virtual_time, playback_speed_rate, state, index, part_infos.size());
}
File_Data_Source() {
this->type = "File_Data_Source";
@@ -300,7 +292,8 @@ public:
~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)) {}
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};
}
@@ -315,17 +308,16 @@ public:
}
asio::awaitable<void> _close() override;
asio::awaitable<void> _open() override;
std::vector<std::string> readBinaryFileAsString(std::string_view filepath,
size_t part_size);
void from_json(const Psc::JSON* that_json) override {
Data_Source::from_json(that_json);
File_Data_Source_Data::from_base_json(that_json);
std::vector<std::string> readBinaryFileAsString(std::string_view filepath, size_t part_size);
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Source::from_json(that_json, not_exist_use_default_value);
File_Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
}
Psc::JSON to_json() override {
return Data_Source::to_json() += File_Data_Source_Data::to_base_json();
}
void origin_data_transform_mode_data(std::string& data) override;
void handle_mode_s(std::shared_ptr<SSR::Mode_S_Msg> msg) 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;
@@ -353,9 +345,9 @@ public:
}
~Dll_Data_Source() override = default;
std::vector<std::uint8_t> buffer;
void from_json(const Psc::JSON* that_json) override {
Data_Source::from_json(that_json);
Dll_Data_Source_Data::from_base_json(that_json);
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Source::from_json(that_json, not_exist_use_default_value);
Dll_Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
buffer.resize(buffer_size);
}
Psc::JSON to_json() override {
@@ -385,8 +377,7 @@ public:
auto r = Psc::try_load_function(lib, function_name);
if (!r) {
state = r.error().message();
std::cout << LOG_POS << " [" << function_name << "] 函数指针加载失败!"
<< std::endl;
std::cout << LOG_POS << " [" << function_name << "] 函数指针加载失败!" << std::endl;
co_return;
}
read_func_ptr = (Func_Type)r.value();
@@ -408,9 +399,9 @@ 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);
Shared_Memory_Data_Source_Data::from_base_json(that_json);
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Source::from_json(that_json, not_exist_use_default_value);
Shared_Memory_Data_Source_Data::from_base_json(that_json, not_exist_use_default_value);
}
Psc::JSON to_json() override {
return Data_Source::to_json() += Shared_Memory_Data_Source_Data::to_base_json();
@@ -423,13 +414,18 @@ protected:
};
inline std::shared_ptr<Data_Source> create_data_source_from_type(std::string_view 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>();
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;
std::cout << "未知 Data_Source type类型!" << std::endl;
throw std::invalid_argument("unknown Data_Source type: " + std::string(t));
}
return ret;
@@ -437,10 +433,10 @@ inline std::shared_ptr<Data_Source> create_data_source_from_type(std::string_vie
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) {
void init(const Psc::JSON* that_json, bool not_exist_use_default_value) {
auto list = that_json->get("list");
for (auto& it : list->children) {
auto ds = create_from_json(&it);
auto ds = create_from_json(&it, not_exist_use_default_value);
map.push_back(ds);
}
}