Files
2024-09-27 14:31:22 +08:00

131 lines
4.9 KiB
C++

#ifndef Logic_processtask_H
#define Logic_processtask_H
#include <QObject>
#include <QTimer>
//#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "Logic_myiothread.h"
#pragma execution_character_set("utf-8")
//无法用信号槽传递图像?
//返回图片的结构体
struct LsendImgStruct
{
cv::Mat send_Mat; //返回的图像
QString cameraKey_index; //关键字_序号
};
class Logic_processtask : public QObject
{
Q_OBJECT
public:
explicit Logic_processtask(QObject *parent = nullptr);
~Logic_processtask();
void setLoadFlag(int index);
void setInitFlag(int index);
void setCreateThread(int index){ modulethread_flag = index;}
void setRunFlag(int index);
void setJsonObject(QJsonObject obj);
bool check_cmeraCfg(QJsonObject obj,QString& errMessage);
void setJsonPath(QString path){ JsonPath = path;}
void initClearSignal();
//加载模块、初始化、开启类线程
bool initTask();
bool startTask();
bool stopTask();
bool exitTask();
bool restartTask(); // 重新加载任务
bool clearStationData();
// 加载所有模块;初始化所有模块
bool loadAllModule();
bool initTcpModule();
// 初始化所有模块
bool initStationsModule();
// 创建线程
bool createModuleThread();
bool loadCameraAndAlgorithmModule( QJsonArray stationlist_array );
bool decodePackage(QString name,cv::Mat mtx);
//加载单个模块:通信、相机、算法
bool loadModule( QString cameraName,QJsonObject module_obj,QByteArray initByte );
QByteArray encodeAlgorithmData( QJsonArray array,QString calConfig ); // 算法cal配置文件路径
QByteArray initCameraParam( QString key,QJsonArray array ); // 相机初始化参数编码
QJsonObject getFinsTcpObject(QJsonArray array);
MyModule getModule(QString key);
QList<MyModule> getModuleList(int thread_index, QString stationKey);
QJsonArray getTaskAlgorithmObject(int thread_index,QJsonArray array);
QJsonArray getCameraConfigArray(QString key); // 获取相机初始化配置文件
QList<Logic_taskthread*> task_thread_list;
void thread_checkAll_Status();
void thread_Logic_hdataintegration();
void thread_reciveImageData();
QMutex* LsendImgStructMutex = nullptr;
QQueue< LsendImgStruct> Lqueue_sendImgStruct;//图像及数据列表
bool getImageData(QQueue< LsendImgStruct>&);
bool sendPLC(QString cmd);
bool reLoadJsonSetParameter(QStringList moduleKeyList);
public:
Q_INVOKABLE void reciveImageData(); // 接收数据
private:
bool exitFlag = false;
QTimer* DeleteFileTimer = nullptr;
int init_flag = 0; // 0:代表未初始化 1:代表已初始化
int load_flag = 0; // 0:代表未加载 1:代表已加载
int modulethread_flag = 0; // 0:代表未创建 1:代表已创建
int run_flag = 0; // 0:代表未运行 1:代表已运行
// 设置本地保存文件夹的路径
QString saveImageDir;
QString LogPath;
bool deleteingImg = false;
bool deleteingLog = false;
cv::Mat ai_mat;
QString m_AiName;
QString JsonPath = nullptr;
//整个配置文件
QJsonObject programObj;
QJsonArray tcplist_array;
QJsonArray stationlist_array;
QJsonArray m_cameramodulelist; // 相机列表
ReleaseFunction destory_finstcp = nullptr; //释放
QList<QLibrary*> lib_list;
QList<MyModule> module_list;
//QList<Logic_hdataintegration*> dataIntegrationThread_list;
QMutex *m_io_mutex = nullptr;
QMutex* write_data_mutex = nullptr;
QMutex *m_showimage_mutex = nullptr;
Base* finstcp_ptr;
QQueue<ReleaseFunction> destory_Communication; //释放
//Logic_myiothread*m_IoThread = nullptr;
//ReadPackThread *m_readThread = nullptr;
QMap<QString,QList<MyModule>> camera_algorithm_map; // 存储相机对应的算法
QTimer *check_tcp_status = nullptr;
bool isStartThread = false;
//配置文件读取的,"savePath"的值,保存路径总文件夹
QString m_savePath = nullptr;
//配置文件检查标志,true已检查且OK
bool ifChecked = false;
//项目通信流程,1简单流程,2标准流程;
int CommunicationProcessLevel = 0;
//发送的数据是否自动拼接PLC指令头
bool ifAddCmdHead = true;
signals:
//void LsendImage(QString, cv::Mat); // 传递拍到的图片
void sendTcpStatus(bool);
void LwriteData(QString,QString,QString,QByteArray); // 传递结果数据 算法名称+相机名称+产品sn码+结果信息,最后一个参数是-3使用的特殊参数
void cameraDisconnect(QString msg, bool status);//0106 相机状态改变弹窗
void CommunicationDisconnect(QString msg, bool status);//通信状态改变弹窗
private slots:
bool FindFileForDelete(const QString&, int);
};
#endif // Logic_processtask_H