GrabBag/App/BeltTearing/BeltTearingConfig/Inc/IVrBeltTearingConfig.h

236 lines
6.4 KiB
C
Raw Normal View History

2026-03-28 10:49:55 +08:00
#ifndef IVRBELTTEARINGCONFIG_H
#define IVRBELTTEARINGCONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#ifdef QT_CORE_LIB
2026-03-28 10:49:55 +08:00
#include <QtCore/QMetaType>
#endif
2026-03-28 10:49:55 +08:00
/**
* @brief 项目类型枚举
*/
enum class BeltTearingProjectType
{
BeltTearing = 0, // 皮带撕裂检测
BeltMonitoring = 1, // 皮带监控
};
/**
* @brief ModbusTCP协议类型枚举
*/
enum class ModbusTCPProtocolType
{
Standard = 0, // 标准协议(支持5个撕裂信息,每个包含ID、状态、宽度、深度)
Simplified = 1, // 简化协议(仅报警标志、最大长度、最大宽度、最大撕裂ID和复位)
};
enum class ByteDataType {
Text = 0x01,
Image = 0x02,
ReadConfig = 0x03,
WriteConfig = 0x04,
2026-08-12 18:03:28 +08:00
PointCloud = 0x05,
2026-03-28 10:49:55 +08:00
};
/**
* @brief 服务器信息结构
*/
struct ServerInfo
{
std::string name; // 服务器名称
std::string ip; // 服务器IP地址
2026-08-12 18:03:28 +08:00
int port = 5900; // 服务器端口,配置未指定时使用5900
2026-03-28 10:49:55 +08:00
};
/**
* @brief 皮带撕裂检测参数 - 简化版本
*/
struct BeltTearingParam
{
double scanXScale = 1.0; // 3D扫描仪X方向标尺
double scanYScale = 1.0; // 3D扫描仪Y方向标尺
double differnceBinTh = 1.0; // 一层次分割阈值调整
double tearingMinLen = 5.0; // 最小撕裂长度
double tearingMinGap = 2.0; // 撕裂间距阈值
double tearingMinDepth = 2.0;
double tearingMinYWidth = 2.0;
double tearingMaxYWidth = 150.0;
2026-03-28 10:49:55 +08:00
// 特征提取参数
double sameGapTh = 2.0; // 相同gap阈值
int gapChkWin = 5; // gap检查窗口
};
/**
* @brief 监控参数
*/
struct MonitoringParam
{
int checkInterval = 1000; // 检查间隔(毫秒)
double alertThreshold = 3.0; // 报警阈值
};
/**
* @brief 队列处理参数
*/
struct QueueProcessParam
{
int maxQueueSize = 300; // 最大队列大小
int generationInterval = 100; // 图像生成间隔(每N条线生成一次)
2026-08-12 18:03:28 +08:00
int imageLineCount = 300; // 每张图使用的最近激光线数量
};
/**
* @brief TCP点云发送参数
*/
struct PointCloudSendParam
{
bool enabled = true; // 是否发送激光线点云
int lineStep = 1; // 每N条激光线发送1条,1表示不抽线
int pointStep = 1; // 每N个点发送1个点,1表示不抽点
2026-03-28 10:49:55 +08:00
};
/**
* @brief 相机配置参数
*/
struct CameraParam
{
std::string cameraIP = ""; // 相机IP地址
};
/**
* @brief 串口配置参数(用于 Modbus RTU)
*/
struct SerialPortParam
{
std::string portName = ""; // 串口名称(如 /dev/ttyS4 或 COM10)
int baudRate = 115200; // 波特率
char parity = 'N'; // 校验位(N=无校验, E=偶校验, O=奇校验)
int dataBits = 8; // 数据位
int stopBits = 1; // 停止位
SerialPortParam()
{
#ifdef _WIN32
portName = "COM10"; // Windows 默认串口
#else
portName = "/dev/ttyS4"; // ARM/Linux 默认串口
#endif
}
};
/**
* @brief 调试参数
*/
struct DebugParam
{
bool enableDebug = false; // 是否开启调试模式
bool saveDebugImage = false; // 是否保存调试图像
bool printDetailLog = false; // 是否打印详细日志
std::string debugOutputPath = ""; // 调试输出路径
};
/**
* @brief 算法参数配置结构
*/
struct BeltTearingAlgorithmParams
{
BeltTearingParam beltTearingParam; // 皮带撕裂检测参数
MonitoringParam monitoringParam; // 监控参数
};
/**
* @brief 配置加载结果
*/
struct BeltTearingConfigResult
{
std::vector<ServerInfo> servers; // 服务器列表
BeltTearingAlgorithmParams algorithmParams; // 算法参数
DebugParam debugParam; // 调试参数
BeltTearingProjectType projectType; // 项目类型
std::vector<CameraParam> cameras; // 相机列表
QueueProcessParam queueProcessParam; // 队列处理参数
2026-08-12 18:03:28 +08:00
PointCloudSendParam pointCloudSendParam;// TCP点云发送参数
2026-03-28 10:49:55 +08:00
SerialPortParam serialPortParam; // 串口参数(用于 Modbus RTU)
ModbusTCPProtocolType modbusTCPProtocol; // ModbusTCP协议类型(默认使用简化协议)
int serverPort = 5900; // 上下位机通信端口
int tcpPort = 5800; // 客户协议-TCP协议端口(新协议-TearingTcpProtocol)
// 构造函数,设置默认值
BeltTearingConfigResult()
: projectType(BeltTearingProjectType::BeltTearing)
, modbusTCPProtocol(ModbusTCPProtocolType::Simplified) // 默认使用简化协议
{}
};
/**
* @brief 配置改变通知接口
*/
class IVrBeltTearingConfigChangeNotify
{
public:
virtual ~IVrBeltTearingConfigChangeNotify() {}
/**
* @brief 配置数据改变通知
* @param configResult 新的配置数据
*/
virtual void OnConfigChanged(const BeltTearingConfigResult& configResult) = 0;
};
/**
* @brief BeltTearingConfig接口类
*/
class IVrBeltTearingConfig
{
public:
/**
* @brief 虚析构函数
*/
virtual ~IVrBeltTearingConfig() = default;
/**
* @brief 创建实例
* @return 实例
*/
static bool CreateInstance(IVrBeltTearingConfig** ppVrConfig);
/**
* @brief 加载配置文件
* @param filePath 配置文件路径
* @return 加载的配置结果
*/
virtual BeltTearingConfigResult LoadConfig(const std::string& filePath) = 0;
/**
* @brief 保存配置文件
* @param filePath 配置文件路径
* @param configResult 配置结果
* @return 是否保存成功
*/
virtual bool SaveConfig(const std::string& filePath, BeltTearingConfigResult& configResult) = 0;
/**
* @brief 设置配置改变通知回调
* @param notify 通知接口指针
*/
virtual void SetConfigChangeNotify(IVrBeltTearingConfigChangeNotify* notify) = 0;
};
// 声明元类型,以便在QVariant中使用
#ifdef QT_CORE_LIB
2026-03-28 10:49:55 +08:00
Q_DECLARE_METATYPE(ServerInfo)
Q_DECLARE_METATYPE(BeltTearingParam)
Q_DECLARE_METATYPE(CameraParam)
Q_DECLARE_METATYPE(SerialPortParam)
Q_DECLARE_METATYPE(BeltTearingConfigResult)
#endif
2026-03-28 10:49:55 +08:00
#endif // IVRBELTTEARINGCONFIG_H