串口改协程前
This commit is contained in:
@@ -133,8 +133,13 @@ std::optional<std::string> convert_to_send_format(Data_Source* ds, const std::sh
|
||||
return send_msg;
|
||||
}
|
||||
|
||||
void data_feed_thread(std::atomic<bool>& running) {
|
||||
ucoro::awaitable<void> data_feed_thread_coro(std::atomic<bool>& running) {
|
||||
auto g = Global::instance();
|
||||
for (auto& source : g->mode_acs.data_source_config.map.list()) {
|
||||
if (source->enable) {
|
||||
source->open();
|
||||
}
|
||||
}
|
||||
for (auto& t : g->mode_acs.data_feed_config.map.list()) {
|
||||
if (t->enable) {
|
||||
auto ret = t->check_and_open();
|
||||
@@ -150,8 +155,14 @@ void data_feed_thread(std::atomic<bool>& running) {
|
||||
auto& report_data_feed_msg_mum = mode_acs.report_data_feed_msg_mum;
|
||||
std::vector<std::shared_ptr<Data_Feed>> enable_feeds; // all_feed 保证声明周期仍然存在
|
||||
auto monitor_msg_live = mode_acs.monitor_msg_live.load();
|
||||
bool all_empty = true;
|
||||
while (running.load(std::memory_order_acquire) == true) {
|
||||
bool all_empty = true;
|
||||
for (auto& source : mode_acs.data_source_config.map.list()) {
|
||||
if (!source->enable) continue;
|
||||
if (!source->is_open() && !source->open()) continue;
|
||||
co_await source->source_step_coro();
|
||||
}
|
||||
|
||||
// 这两个每次循环都要重新计算 保证实时性
|
||||
// if (flush_limit.test()) {
|
||||
auto all_feed = cfg.map.list();
|
||||
@@ -160,7 +171,7 @@ void data_feed_thread(std::atomic<bool>& running) {
|
||||
if (!feed->enable) continue;
|
||||
enable_feeds.push_back(feed);
|
||||
// 执行特定的刷新逻辑 比如 tcp_server 检查自身的连接
|
||||
feed->handle_in_loop();
|
||||
co_await feed->handle_in_loop_coro();
|
||||
}
|
||||
|
||||
|
||||
@@ -200,22 +211,7 @@ void data_feed_thread(std::atomic<bool>& running) {
|
||||
std::cout << "警告:未知原因:" << feed->key << "内有空的消息体" << std::endl;
|
||||
continue;
|
||||
}
|
||||
if (feed->type == "Data_Feed_TCP_Server") {
|
||||
auto it = dynamic_cast<Data_Feed_TCP_Server*>(feed.get());
|
||||
ucoro::sync_await(it->svr.write_to_all_clients_coro(*str));
|
||||
}
|
||||
else if (feed->type == "Data_Feed_UDP_Server") {
|
||||
auto it = dynamic_cast<Data_Feed_UDP_Server*>(feed.get());
|
||||
ucoro::sync_await(it->svr.write_to_all_clients_coro(*str));
|
||||
}
|
||||
else if (feed->type == "Data_Feed_TCP_Client") {
|
||||
auto it = dynamic_cast<Data_Feed_TCP_Client*>(feed.get());
|
||||
ucoro::sync_await(it->cli.send_coro(*str));
|
||||
}
|
||||
else if (feed->type == "Data_Feed_UDP_Client") {
|
||||
auto it = dynamic_cast<Data_Feed_UDP_Client*>(feed.get());
|
||||
ucoro::sync_await(it->cli.send_coro(*str));
|
||||
}
|
||||
co_await feed->send_coro(*str);
|
||||
}
|
||||
}
|
||||
if (t != 0) {
|
||||
@@ -226,5 +222,10 @@ void data_feed_thread(std::atomic<bool>& running) {
|
||||
}
|
||||
}
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
|
||||
void data_feed_thread(std::atomic<bool>& running) {
|
||||
ucoro::sync_await(data_feed_thread_coro(running));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user