修改modbus-rtu轮询服务,让他不在阻塞终止信号

This commit is contained in:
GuanYuankai 2025-10-15 14:34:53 +08:00
parent cb6d594e49
commit f7e676a87a
3 changed files with 13 additions and 7 deletions

View File

@ -96,6 +96,7 @@ target_link_libraries(edge_proxy PRIVATE
# =================================================================
add_executable(test
src/test.cc
src/SQL/data_storage.cc
)

View File

@ -74,15 +74,13 @@ RUN cd /tmp/build-context/external/paho.mqtt.c && \
# 在所有 apt 操作完成后,最后进行清理
rm -rf /var/lib/apt/lists/*
COPY piper_models/ /app/piper_models/
# 5. 设置默认用户
# =================================
# 容器的默认用户将是 'dev'
USER dev
RUN pip install --no-cache-dir --user piper-tts
# 将 ~/.local/bin (包含 piper 二进制文件) 添加到 PATH
RUN echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bash_profile
# 现在dev 用户可以使用 `piper` 命令了,只要 shell 环境被正确加载。
# 我们可以将最终的 CMD 设置为加载环境然后执行一个命令,或者留空让用户交互。
# 5. 设置默认用户
# =================================
# 容器的默认用户将是 'dev'
USER dev

View File

@ -92,7 +92,14 @@ void ModbusRtuPollerService::run() {
}
// 在本线程中等待,不影响主线程的事件循环
std::this_thread::sleep_for(std::chrono::milliseconds(m_config.poll_interval_ms));
auto wake_up_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(m_config.poll_interval_ms);
while (std::chrono::steady_clock::now() < wake_up_time) {
if (m_stop_flag) {
break;
}
// 每次只“打盹”100毫秒
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
// 线程退出前关闭串口