|
- #pragma once
-
- #include "plc_communication_gateway.h"
-
- #include <cstddef>
- #include <functional>
- #include <string>
- #include <vector>
-
- // 自动搜索正在尝试的串口参数和总体进度
- struct PlcDiscoveryProgress
- {
- PlcSerialConfiguration configuration;
- std::size_t currentAttempt = 0;
- std::size_t totalAttempts = 0;
- };
-
- // 自动搜索结束结果;found 和 cancelled 不会同时为 true
- struct PlcDiscoveryOutcome
- {
- bool found = false;
- bool cancelled = false;
- PlcSerialConfiguration configuration;
- std::string message;
- };
-
- /**
- * 按优先级生成搜索组合
- *
- * 站号和通信时序沿用界面当前值,只遍历可用端口及项目支持的串口参数
- */
- std::vector<PlcSerialConfiguration> buildPlcDiscoveryCandidates(
- const PlcSerialConfiguration &preferred,
- const std::vector<std::string> &available_ports);
-
- // UI 使用的异步 PLC 自动搜索契约,具体串口实现位于 infrastructure
- class PlcDiscoveryGateway
- {
- public:
- virtual ~PlcDiscoveryGateway() = default;
-
- // 开始搜索,实际进度和结果通过回调通知
- virtual PlcCommunicationResult startDiscovery(
- const PlcSerialConfiguration &preferred) = 0;
- // 取消当前搜索;串口释放后通过结束回调通知
- virtual void cancelDiscovery() = 0;
- // 返回当前是否正在搜索或等待释放搜索串口
- virtual bool isDiscovering() const = 0;
- // 替换进度和结束回调,传入空函数可取消通知
- virtual void setCallbacks(
- std::function<void(const PlcDiscoveryProgress &)> progress_changed,
- std::function<void(const PlcDiscoveryOutcome &)> discovery_finished) = 0;
- };
|