Files
2026-02-01 22:23:06 +08:00

236 lines
9.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
*该类用于与Xilinx FPGA芯片(K7) XDMA框架进行交互
*
*/
#ifndef DATAINJECT_H
#define DATAINJECT_H
#include "../Common/IO/GIOParams.h"
#include "../Common/IO/FileStream/Raw/FileStream.h"
//#include "../Common/OpenGLView.h"
#include "../Common/qlog.h"
#include "../Common/IO/DeviceStream/GdPCIE/PcieFun.h"
#include <QLineEdit>
#include <QFuture>
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include <QLabel>
#include <QSlider>
#include <atomic>
class GLWidget;
class MainWindow;
class DataInject: public QObject
{
Q_OBJECT
public:
explicit DataInject(QObject* parent = 0);
virtual ~DataInject();
/***********************************************图像注入接口****************************************************/
/**
* @brief 【接口1】StartInject 开始进行数据注入
* @param injectParam [in]参数设置(包括采集卡光纤端口号 图像分辨率、帧率、参数行数、图像类型)
* @param openglview [in]显示控件(可为nullptr)
* @param uiFileProgressLabel [in] 文件播放进度显示label控件(可为nullptr)
* @return [out] 是否成功开始注入
*/
bool StartInject(GFrameFormat* injectParam, void* openglview = nullptr, void* uiFileProgressLabel = nullptr);
/**
* @brief 【接口2】 停止注入
* @param channelIndex 采集卡光纤端口号
*/
void StopInject(int channelIndex);
/** --------------------该接口为非必要接口------------------------
* @brief 【接口3】更新模拟热像仪参数,可实时更新或多次更新(只有在需要模拟热像仪参数注入时才调用,属于非必要接口)
* @param 采集卡光纤端口号
* @param isInjectParamSimulate [in]是否注入该模拟参数
* @param param [in]模拟热像仪参数
*/
void UpdateParamSimulate(int channelindex, bool isInjectParamSimulate, THERMAL_IMG_PARAMS param);
/***********************************************控制命令注入接口**************************************************/
/**
* @brief 【接口4】 控制命令下发注入---与接口1/2/3独立
* @param iChannelIndex [in] 光纤通道号: 0 ~ 7
* @param cmdData [in] 控制命令
* @return
*/
void WriteControlCmd(int iChannelIndex, QByteArray cmdData);
/** --------------------该接口为非必要接口------------------------
* @brief 获取延时信息 返回结构体
*/
InjectDelayStatusInfo* GetDelayStatus(int channelIndex);
/** --------------------该接口为非必要接口------------------------
* @brief 是否正在注入
* @return
*/
bool IsStartInject(int channelIndex) {return m_bIsStartInjectMap.value(channelIndex);}
/** --------------------该接口为非必要接口------------------------
* @brief 将外部的全屏控件的指针传进来
* @param channelIndex
* @param fullScreenOpenglview
*/
void SetFullScreenWgt(int channelIndex, void* fullScreenOpenglview = nullptr);
/** --------------------该接口为非必要接口------------------------
* @brief 设置是否保存程序运行期间的日志信息
* @param isSaved
*/
void SetSaveLog(bool isSaved) {m_bIsSaveLog = isSaved; }
/** --------------------该接口为非必要接口------------------------
* @brief SetOsdHidden
* @param isHidden
*/
void SetOsdHidden(bool isHidden) {m_bIsHiddenOsd = isHidden ; }
private:
static void OnProgress(int nFrameIndex, int nFrameCount, void* pOwner, int iChannelIndex);
void SetProgress(int nFrameIndex, int nFrameCount, int iChannelIndex);
void CalcuImgFps(int channelIndex); //计算图像帧率
//参数初始化 点击"选择文件"按键
bool Init(GFrameFormat* injectParam, void* openglview = nullptr, void* uiFileProgressLabel = nullptr);
bool BrowseRawFile(QString& filePathEdit);
int GetByteOfPixel(ePixelType ePT);
QString CurrentTime();
inline void SleepAccurate(int milliseconds);
//开启文件数据读取线程
bool StartThread_DealRawFileData();
void StopThread_DealRawFileData();
//开启注入线程
bool StartThread_InjectData();
void StopThread_InjectData();
//开启图像处理和显示进程
bool StartThread_ImgProcessData();
void StopThread_ImgProcessData();
//实体
void ThreadFun_FetchRawFileData(int distribute);
// void ThreadFun_FetchRawFileData02();
void ThreadFun_InjectData();
void ThreadFun_ImgProcessData01();
void ThreadFun_ImgProcessData02();
void ThreadFun_WriteCmdControlData(); //命令控制注入
private:
typedef void (DataInject::*ThreadRunFunPtr)();
static void ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner);
QString ShowHex(char* str, int length); //Hex to String
typedef void (DataInject::*InjectThreadRunFunPtr)(int channelIndex);
static void InjectThreadEntry(InjectThreadRunFunPtr pRunFun, void* pOwner, int channelIndex);
//文件处理线程
bool m_bDealRawThreadRunning;
std::thread* m_ptrThread_DealRaw01;
std::thread* m_ptrThread_DealRaw02;
//注入线程
bool m_bInjectThreadRunning;
std::thread* m_ptrThread_InjectData;
//图像处理显示线程
bool m_bImgProcessThreadRunning;
std::thread* m_ptrThread_ImgProcess01;
std::thread* m_ptrThread_ImgProcess02;
//命令注入线程
bool m_bWriteCmdThreadRunning;
std::thread* m_ptrThread_WriteCmd;
// QObject* m_pParentWgt;
QVector<QVector<QRgb> > m_varColorTable;
QTimer m_varTimer;
//注入延时状态数组
InjectDelayStatusInfo m_szInjectStatus[ChannelCacheNum];
//***********
QMap<int, GLWidget*>m_pOpenGlMap; //opengl显示控件集合
QMap<int, QLabel*>m_pLabelMap; //注入状态label对应的Map
QMap<int, GCycleQueue*> m_pGCycleQueueMap; //循环队列
QMap<int, QLog*> m_pDataInjectLogMap; //数据注入日志Map
QMap<int, QLog*> m_pCmdInjectLogMap; //命令注入日志Map
QMap<int, GFrameFormat> m_frameFormatMap;
QMap<int, bool> m_bIsStartInjectMap; //是否开始注入状态
QMap<int, int> m_uiHostWriteBuffNoMap; //上位机在上一个循环中最后写到的BuffNo索引值 取值: 0~(ChannelCacheNum-1)
QMap<int, GLWidget*>m_pFullScreenOpenGlMap; //全屏对应的OpenGL
QMap<int, int > m_iFileStreamCurrIndexMap; //key: ChannelIndex value: 录像文件当前帧编号
QMap<int, int > m_iFileStreamTotalCountMap; //key: ChannelIndex value: 录像文件总帧数
QMap<int, bool > m_bIsInjectParamSimulateMap; //key: ChannelIndex value: 是否模拟参数行注入
QMap<int, THERMAL_IMG_PARAMS> m_varThermalImgParamsMap; //key: ChannelIndex value: 模拟热像仪参数行
QMap<int, DynamicArray*> m_varInjectCMDMap; // /key: ChannelIndex value:动态数组 命令注入
//********************
//对于每帧图像的大小有3种不同的表达
//01.iVideoFileFrameSize ---- 即将注入的视频文件(RAW)的每帧图像的大小 iVideoFileFrameSize = 图像宽 x (图像高 + 参数行数)
//02.iInjectFrameTotalSize ------实际注入的每帧图像的总大小 iInjectFrameTotalSize = iVideoFileFrameSize + 界面模拟注入参数(图像宽 * 1 * 图像格式字节数)
//03.iFPGABufferCacheSize(采集卡DDR每帧Buff的缓存首地址) ---- FPGA读DDR的Buff缓存的首地址需以2048字节对齐---->由iInjectFrameTotalSize向上对齐
//********************
QMap<int, uint> m_iVideoFileFrameSizeMap; //key: ChannelIndex value:录像视频文件 每帧图像图像Byte大小
QMap<int, uint> m_iInjectFrameTotalSizeMap; //key: ChannelIndex value: 每帧注入图像的总大小(包括文件参数行 + 模拟参数行)
QMap<int, uint> m_iDDRBufferCacheSizeMap; //key: ChannelIndex value:FPGA 缓存区Buff大小
QMap<int, GCycleQueue*> m_pInjectDataQueueMap; //key: ChannelIndex value: 注入数据(文件)缓存队列
QMap<int, GCycleQueue*> m_varImgDisplayDataQueueMap; //key: ChannelIndex value: 图像显示(文件)缓存队列
QMap<int, FileStream*> m_pFileStreamMap; //key: ChannelIndex value: 文件读取对象
//帧率计算
QMap<int, uint> m_uiCurrFrameRateCountMap; //key: 通道号 value:当前帧数
QMap<int, int64_t> m_iFrameTimeStartMap; //key: 通道号 value:开始统计的时间戳
QMap<int, uint> m_uiCalcuFramesMap; //key: 通道号 value: 多少帧数计算一次 100
QMap<int, double> m_dInjectFrameRateMap; //key: 通道号 value:采集帧率
QMap<int, uint> m_uiInjectFrameNoGenerateMap; //key: 通道号 value:注入图像的帧编号(为验证长时间同时注入和采集的稳定性(是否丢帧)注入帧编号由上位机构造从0开始)
byte* m_szY8ImgData_Thread01;
byte* m_szRGBAImgData_Thread01;
byte* m_szY8ImgData_Thread02;
byte* m_szRGBAImgData_Thread02;
uint m_iInjectEnableStatus; //注入使能状态
// uint uiThreadSleepTime; //线程休眠时间
bool m_bIsSaveLog; // 是否保存日志
bool m_bIsOpenInjectThread; //是否打开注入线程
MainWindow* m_pParent;
QLog* m_pLog; //所有通道共用同一Log
bool m_bIsHiddenOsd;
QLog* m_pReadFileLog; //所有通道共用同一Log
uint m_uiAXIFrequence = 0;
QMap<void*, uint> m_uiCpuCoreIndexUsedMap;
};
#endif // DATAINJECT_H