V20260829-2.6.1
完成框架目录和模块重构;新增核心、单例、工具、加密及框架 SDK;统一任务、相机和 RPC 接口,并增加离线检测、相机标定、备份恢复、版本管理、崩溃守护和心跳监控功能。
This commit is contained in:
+102
-36
@@ -1,59 +1,125 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <QByteArray>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
|
||||
static const std::string getExeDirectoryx()
|
||||
{
|
||||
char buffer[MAX_PATH];
|
||||
if (GetModuleFileNameA(nullptr, buffer, MAX_PATH) == 0) {
|
||||
return ""; // 获取失败时返回空字符串。
|
||||
}
|
||||
std::filesystem::path exePath(buffer);
|
||||
return exePath.parent_path().string();
|
||||
}
|
||||
|
||||
class dsModuleBase : public QObject
|
||||
{
|
||||
public:
|
||||
bool init_flag; //是否初始化,false,true
|
||||
bool status = true; //相机状态(判断相机是否断开连接)
|
||||
std::string paras; //传输数据
|
||||
cv::Mat m_mat; //传输图片
|
||||
std::string moduleName; //模块名称
|
||||
bool init_flag; // 是否初始化:false/true
|
||||
bool status = true; // 相机状态,用于判断相机是否断开连接
|
||||
std::string paras; // 传输数据
|
||||
cv::Mat m_mat; // 传输图片
|
||||
std::string moduleName; // 模块名称
|
||||
|
||||
public:
|
||||
dsModuleBase() {}
|
||||
virtual ~dsModuleBase() {}
|
||||
virtual bool readData(std::vector<cv::Mat>&,QByteArray&){return true;}
|
||||
virtual bool writeData(std::vector<cv::Mat>&,QByteArray&){return true;}
|
||||
virtual bool initParas(QByteArray&){return true;}
|
||||
virtual bool run() {return true;}
|
||||
virtual bool checkStatus() { return true; };
|
||||
virtual bool readData(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool writeData(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool initParas(QByteArray&) { return true; }
|
||||
virtual bool run() { return true; }
|
||||
virtual bool checkStatus() { return true; }
|
||||
virtual void showDialog() {};
|
||||
};
|
||||
|
||||
class rpcModuleBase : public QObject
|
||||
{
|
||||
public:
|
||||
bool init_flag; //是否初始化,false,true
|
||||
bool status = true; //相机状态(判断相机是否断开连接)
|
||||
std::string paras; //传输数据
|
||||
cv::Mat m_mat; //传输图片
|
||||
std::string moduleName; //模块名称
|
||||
public:
|
||||
rpcModuleBase() {}
|
||||
virtual ~rpcModuleBase() {}
|
||||
virtual bool readData(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool writeData(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool initParas(QByteArray&) { return true; }
|
||||
virtual bool run() { return true; }
|
||||
virtual QByteArray executeReadCommand(QByteArray& input) = 0;
|
||||
virtual bool executeWriteCommand(QByteArray& input) = 0;
|
||||
virtual bool initParas(QByteArray&) { return true; }
|
||||
virtual bool run() { return true; }
|
||||
virtual void showDialog() {};
|
||||
};
|
||||
|
||||
class cameraModuleBase : public QObject
|
||||
|
||||
// ========== 通用超时定时器 ==========
|
||||
// 继承 QThread,到达指定时间后调用外部注册的回调函数。
|
||||
class CleanupTimer : public QThread
|
||||
{
|
||||
public:
|
||||
bool init_flag; //是否初始化,false,true
|
||||
bool status = true; //相机状态(判断相机是否断开连接)
|
||||
std::string paras; //传输数据
|
||||
cv::Mat m_mat; //传输图片
|
||||
std::string moduleName; //模块名称
|
||||
public:
|
||||
cameraModuleBase() {}
|
||||
virtual ~cameraModuleBase() {}
|
||||
virtual bool captrue(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool writeData(std::vector<cv::Mat>&, QByteArray&) { return true; }
|
||||
virtual bool initParas(QByteArray&) { return true; }
|
||||
CleanupTimer() = default;
|
||||
|
||||
/// 设置定时时间,单位:毫秒
|
||||
void setInterval(int msec) { m_intervalMs.store(msec); }
|
||||
|
||||
/// 获取当前定时时间,单位:毫秒
|
||||
int intervalMs() const { return m_intervalMs.load(); }
|
||||
|
||||
/// 注册超时回调函数
|
||||
void setCallback(std::function<void()> callback) { m_callback = std::move(callback); }
|
||||
|
||||
/// 停止定时器
|
||||
void stop() { m_runFlag.store(false); }
|
||||
|
||||
protected:
|
||||
void run() override
|
||||
{
|
||||
m_runFlag.store(true);
|
||||
int counter = 0;
|
||||
while (m_runFlag.load() && counter < m_intervalMs.load())
|
||||
{
|
||||
QThread::msleep(m_checkMs);
|
||||
counter += m_checkMs;
|
||||
}
|
||||
if (m_runFlag.load() && counter >= m_intervalMs.load())
|
||||
{
|
||||
if (m_callback)
|
||||
m_callback();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> m_callback; ///< 超时回调函数
|
||||
std::atomic<bool> m_runFlag{ false };
|
||||
std::atomic<int> m_intervalMs{ 1500 };
|
||||
int m_checkMs{ 10 };
|
||||
};
|
||||
|
||||
//enum initStatusEnum {
|
||||
// CAMERA_NOT_FOUND, // 未找到相机
|
||||
// INIT_FAILED, // 初始化失败
|
||||
// INIT_SUCCESS, // 初始化成功
|
||||
//};
|
||||
|
||||
struct generalResultStruct {
|
||||
bool status; // 初始化状态
|
||||
std::string message; // 详细信息
|
||||
};
|
||||
|
||||
//class euiCameraModuleBase : public QObject {
|
||||
//public:
|
||||
// virtual ~euiCameraModuleBase() {}
|
||||
// virtual initStatusEnum init(const std::string& initStr) = 0; // 输入配置文件路径,不存在时由调用方引导用户创建
|
||||
// virtual bool capture(std::vector<cv::Mat>&) = 0; // 阻塞取图接口,输出参数为取图结果;超时补图由模块内部处理
|
||||
// virtual bool asyncCapture(std::function<void(bool, const std::vector<cv::Mat>&)> callback) = 0; // 异步取图接口,回调参数为取图状态和图像数据
|
||||
// virtual bool connectionCheck() = 0; // 获取连接状态接口,返回当前相机连接状态
|
||||
// virtual void clearCache() = 0; // 手动清除相机模块内的缓存
|
||||
//};
|
||||
|
||||
Reference in New Issue
Block a user