初步修改
This commit is contained in:
@@ -53,11 +53,13 @@ Data_Source::Data_Source() {
|
||||
// parse_format = std::make_shared<Input_Format>();
|
||||
// 写入到配置文件是懒加载 其他保存时他跟着保存
|
||||
base_station.handle_when_updated = [this](SSR::HULC_Status_Message msg) {
|
||||
if (this->update_form_gps) {
|
||||
lat = msg.get_latitude();
|
||||
lon = msg.get_longitude();
|
||||
alt = msg.Alt;
|
||||
}
|
||||
if (!settings.member<&Data_Source_Data::update_form_gps>().snapshot())
|
||||
return;
|
||||
settings.write([&](auto& value) {
|
||||
value.lat = msg.get_latitude();
|
||||
value.lon = msg.get_longitude();
|
||||
value.alt = msg.Alt;
|
||||
});
|
||||
};
|
||||
}
|
||||
std::string Data_Source::thread_key() const {
|
||||
@@ -177,14 +179,15 @@ std::optional<std::string> File_Data_Source::get_raw_line(int& ret_index) {
|
||||
}
|
||||
std::optional<std::string> log_info = std::nullopt;
|
||||
if (index == part_infos.size()) {
|
||||
if (play_mode == Play_Mode::loop) {
|
||||
const auto config = specific.snapshot();
|
||||
if (config.play_mode == Play_Mode::loop) {
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
if (!have_report_play_back_all_success) {
|
||||
std::ostringstream oss;
|
||||
oss << SSR::get_current_date() << " " << SSR::get_current_time()
|
||||
<< " [进程:" << std::this_thread::get_id() << "] " << file_path + " 全部加载成功!\n"
|
||||
<< " [进程:" << std::this_thread::get_id() << "] " << config.file_path + " 全部加载成功!\n"
|
||||
<< std::flush;
|
||||
std::cout << oss.str() << std::flush;
|
||||
have_report_play_back_all_success = true;
|
||||
@@ -305,13 +308,14 @@ asio::awaitable<void> File_Data_Source::_close() {
|
||||
}
|
||||
asio::awaitable<void> File_Data_Source::_open() {
|
||||
std::lock_guard g(mtx);
|
||||
auto path = get_true_file_path();
|
||||
const auto config = specific.snapshot();
|
||||
auto path = Psc::get_abs_path(config.file_path);
|
||||
namespace fs = std::filesystem;
|
||||
if (!fs::exists(path)) {
|
||||
state = "文件不存在";
|
||||
co_return;
|
||||
}
|
||||
if (data_type == File_Data_Type::BIN) {
|
||||
if (config.data_type == File_Data_Type::BIN) {
|
||||
part_infos = readBinaryFileAsString(path, 1000);
|
||||
}
|
||||
else {
|
||||
@@ -356,9 +360,10 @@ void File_Data_Source::origin_data_transform_mode_data(std::string& mode_data) {
|
||||
std::lock_guard g(mtx);
|
||||
assert(mode_data.size() == 0);
|
||||
int ret_index = 0;
|
||||
if (play_mode != Play_Mode::analysis) {
|
||||
const auto config = specific.snapshot();
|
||||
if (config.play_mode != Play_Mode::analysis) {
|
||||
std::optional<std::string> log_info = get_raw_line(ret_index);
|
||||
mode_data = log_info.has_value() ? get_true_from_raw_line(this, data_type, ret_index, log_info.value()) : "";
|
||||
mode_data = log_info.has_value() ? get_true_from_raw_line(this, config.data_type, ret_index, log_info.value()) : "";
|
||||
}
|
||||
else {
|
||||
int num = 0;
|
||||
@@ -367,7 +372,7 @@ void File_Data_Source::origin_data_transform_mode_data(std::string& mode_data) {
|
||||
while (log_info.has_value()) {
|
||||
num++;
|
||||
auto data = log_info.value();
|
||||
auto cur = get_true_from_raw_line(this, data_type, ret_index, data);
|
||||
auto cur = get_true_from_raw_line(this, config.data_type, ret_index, data);
|
||||
ret += cur;
|
||||
// 一定要在这个位置,否则会导致遗漏报文
|
||||
if (num == 1000) {
|
||||
@@ -414,8 +419,9 @@ void Dll_Data_Source::origin_data_transform_mode_data(std::string& mode_data) {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
if (read_func_ptr == nullptr)
|
||||
return;
|
||||
const auto config = specific.snapshot();
|
||||
auto buf = reinterpret_cast<char*>(buffer.data());
|
||||
auto len = read_func_ptr(buf, buffer_size);
|
||||
auto len = read_func_ptr(buf, config.buffer_size);
|
||||
vs.update(len);
|
||||
std::string data(buf, len);
|
||||
if (data.empty()) {
|
||||
@@ -424,15 +430,16 @@ void Dll_Data_Source::origin_data_transform_mode_data(std::string& mode_data) {
|
||||
// std::cout << "Dll_Data_Source::read cost: " << cost << " us\n";
|
||||
return;
|
||||
}
|
||||
auto ret = get_true_from_raw_line(this, data_type, -1, data);
|
||||
auto ret = get_true_from_raw_line(this, config.data_type, -1, data);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
auto cost = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
// std::cout << "Dll_Data_Source::read cost: " << cost << " us\n";
|
||||
mode_data = ret;
|
||||
}
|
||||
asio::awaitable<void> Shared_Memory_Data_Source::_open() {
|
||||
const auto config = specific.snapshot();
|
||||
sm = std::make_unique<Psc::SM_RingBuffer>();
|
||||
sm->init(shared_memory_name, shared_memory_size);
|
||||
sm->init(config.shared_memory_name, config.shared_memory_size);
|
||||
co_return;
|
||||
}
|
||||
asio::awaitable<void> Shared_Memory_Data_Source::_close() {
|
||||
@@ -454,87 +461,29 @@ void Shared_Memory_Data_Source::origin_data_transform_mode_data(std::string& mod
|
||||
if (Global::instance()->console_config.mode_s_console) {
|
||||
std::cout << "read:" << data << std::endl;
|
||||
}
|
||||
auto ret = get_true_from_raw_line(this, data_type, -1, data);
|
||||
const auto config = specific.snapshot();
|
||||
auto ret = get_true_from_raw_line(this, config.data_type, -1, data);
|
||||
mode_data = ret;
|
||||
}
|
||||
void Data_Source_Config::server(Global* g) {
|
||||
auto& svr = g->svr;
|
||||
auto& api = g->api;
|
||||
std::string name = "data_source";
|
||||
// 返回所有 JSON 数据的 API
|
||||
svr.Post(api + "get_data_source_connect", [this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
HTTP_REQUIRE_VALUE(key, params.try_get_string("key"))
|
||||
auto t = map.get(key);
|
||||
auto value = map.get(key);
|
||||
JSON ret{nullptr};
|
||||
if (t.has_value()) {
|
||||
ret = t.value()->get_all_connect_feed();
|
||||
}
|
||||
if (value.has_value())
|
||||
ret = value.value()->get_all_connect_feed();
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_data_source_state", [this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
HTTP_REQUIRE_VALUE(key, params.try_get_string("key"))
|
||||
auto t = map.get(key);
|
||||
auto value = map.get(key);
|
||||
JSON ret{nullptr};
|
||||
if (t.has_value()) {
|
||||
ret = t.value()->get_state();
|
||||
}
|
||||
if (value.has_value())
|
||||
ret = value.value()->get_state();
|
||||
res->setBody(warp(ret).to_json_string());
|
||||
});
|
||||
svr.Post(api + "get_mode_s_data_source_config",
|
||||
[this](HTTP_Param) { res->setBody(warp(to_json()).to_json_string()); });
|
||||
svr.Post(api + svr.update + name, [this, g](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
std::cout << "Data_Source:" << req->path() << that_json->to_json_string();
|
||||
HTTP_REQUIRE_VALUE(key, params.try_get_string("key"))
|
||||
HTTP_REQUIRE_VALUE(ds, map.get(key))
|
||||
ds->from_json(¶ms, true);
|
||||
g->save();
|
||||
g->mode_acs.source_feed_relation_config.set_need_refresh();
|
||||
res->setBody(warp(ds->to_json()).to_json_string());
|
||||
});
|
||||
svr.Post(api + svr.insert + name, [g, this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
std::cout << "Data_Source:" << req->path() << that_json->to_json_string();
|
||||
HTTP_REQUIRE_VALUE(index, params.try_get_number<int>("index"))
|
||||
HTTP_REQUIRE_PTR(data, params.get("data"))
|
||||
HTTP_REQUIRE_VALUE(t, data->try_get_string("type"))
|
||||
std::cout << params.to_json_string() << std::endl;
|
||||
std::shared_ptr<Data_Source> ds = create_data_source_from_type(t);
|
||||
ds->from_json(data, true);
|
||||
HTTP_REQUIRE_VALUE(enable, data->try_get_bool("enable"))
|
||||
(void)enable;
|
||||
HTTP_REQUIRE_TRUE(map.insert(index, ds), "index");
|
||||
g->mode_acs.source_feed_relation_config.set_need_refresh();
|
||||
Config::save();
|
||||
res->setBody(warp(to_json()).to_json_string());
|
||||
});
|
||||
svr.Post(api + svr.remove + name, [g, this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
std::cout << "Data_Source:" << req->path() << that_json->to_json_string();
|
||||
HTTP_REQUIRE_VALUE(index, params.try_get_number<int>("index"))
|
||||
HTTP_REQUIRE_VALUE(ds, map.try_get(index))
|
||||
ds->async_stop();
|
||||
HTTP_REQUIRE_TRUE(map.remove(index), "index")
|
||||
g->save();
|
||||
res->setBody(warp(to_json()).to_json_string());
|
||||
g->mode_acs.source_feed_relation_config.set_need_refresh();
|
||||
});
|
||||
svr.Post(api + svr.rise + name, [g, this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
HTTP_REQUIRE_VALUE(index, params.try_get_number<int>("index"))
|
||||
HTTP_REQUIRE_TRUE(map.swap(index, index - 1), "index")
|
||||
g->save();
|
||||
res->setBody(warp(to_json()).to_json_string());
|
||||
g->mode_acs.source_feed_relation_config.set_need_refresh();
|
||||
});
|
||||
svr.Post(api + svr.fall + name, [g, this](HTTP_Param) {
|
||||
CHECK_JSON_PARAM
|
||||
HTTP_REQUIRE_VALUE(index, params.try_get_number<int>("index"))
|
||||
HTTP_REQUIRE_TRUE(map.swap(index, index + 1), "index")
|
||||
g->save();
|
||||
res->setBody(warp(to_json()).to_json_string());
|
||||
g->mode_acs.source_feed_relation_config.set_need_refresh();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user