mirror of
http://172.16.0.230/r/SIF/TowerOptoSifAndSpectral.git
synced 2025-12-16 03:23:32 +08:00
调试上传用
This commit is contained in:
358
source/CaptureThread/AbstractFSController.cpp
Normal file
358
source/CaptureThread/AbstractFSController.cpp
Normal file
@ -0,0 +1,358 @@
|
||||
#include "AbstractFSController.h"
|
||||
#include "ZZ_Math_HDRONLY.h"
|
||||
CAbstractFSController::CAbstractFSController(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_pFSCtrl = NULL;
|
||||
m_iThreadID = -1;
|
||||
m_vecDataFrameDark.clear();
|
||||
m_vecDataFrameSignal.clear();
|
||||
}
|
||||
|
||||
CAbstractFSController::~CAbstractFSController()
|
||||
{
|
||||
if (m_pFSCtrl!= 0 )
|
||||
{
|
||||
delete m_pFSCtrl;
|
||||
}
|
||||
}
|
||||
|
||||
int CAbstractFSController::SetRunParas(int iThreadID, FSInfo fsInfo)
|
||||
{
|
||||
m_iThreadID = iThreadID;
|
||||
m_fsInfo = fsInfo;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CAbstractFSController::InitializeFSControl()
|
||||
{
|
||||
using namespace ZZ_MISCDEF::IRIS;
|
||||
if (m_iThreadID == -1/*|| m_iDeviceType == -1*/)
|
||||
{
|
||||
qDebug() << "Params Err. Call SetRunParas first";
|
||||
return 1;
|
||||
}
|
||||
switch (m_fsInfo.ucDeviceModel)
|
||||
{
|
||||
case DeviceModel::OSIFAlpha:
|
||||
m_pFSCtrl = new OceanOptics_lib;
|
||||
if (m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, m_fsInfo.strSN) != 0)
|
||||
{
|
||||
qDebug() << "OSIFAlpha Not Opened";
|
||||
return 2;
|
||||
}
|
||||
|
||||
break;
|
||||
case DeviceModel::OSIFBeta:
|
||||
m_pFSCtrl = new OceanOptics_lib;
|
||||
if (m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, m_fsInfo.strSN) !=0)
|
||||
{
|
||||
qDebug() << "OSIFBeta Not Opened";
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
case DeviceModel::ISIF:
|
||||
m_pFSCtrl = new ZZ_ATPControl_Serial_Qt;
|
||||
m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, NULL);
|
||||
if (m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, m_fsInfo.strSN) != 0)
|
||||
{
|
||||
qDebug() << "ISIF Not Opened";
|
||||
return 3;
|
||||
}
|
||||
break;
|
||||
case DeviceModel::IS1:
|
||||
m_pFSCtrl = new ZZ_ATPControl_Serial_Qt;
|
||||
m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, NULL);
|
||||
if (m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, m_fsInfo.strSN) != 0)
|
||||
{
|
||||
qDebug() << "IS1 Not Opened";
|
||||
return 3;
|
||||
}
|
||||
break;
|
||||
case DeviceModel::IS2:
|
||||
m_pFSCtrl = new ZZ_ATPControl_Serial_Qt;
|
||||
m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, NULL);
|
||||
if (m_pFSCtrl->Initialize(false, m_fsInfo.strInterface, m_fsInfo.strSN) != 0)
|
||||
{
|
||||
qDebug() << "IS2 Not Opened";
|
||||
return 3;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int iRes = m_pFSCtrl->GetDeviceAttribute(m_daDeviceAttr);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "GetDeviceAttribute Failed" << iRes;
|
||||
return 4;
|
||||
}
|
||||
|
||||
iRes = m_pFSCtrl->SetDeviceTemperature(0);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "SetDeviceTemperature Failed" << iRes;
|
||||
return 5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::GetDeviceAttr(DeviceAttribute &daAttr)
|
||||
{
|
||||
daAttr = m_daDeviceAttr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::PerformAutoExposure()
|
||||
{
|
||||
qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||
using namespace ZZ_MATH;
|
||||
float fPredictedExposureTime;
|
||||
int iDeviceDepth = (int)m_fsInfo.lDepth;
|
||||
|
||||
qDebug() << "MAX---Min" << m_fsInfo.fMaxFactor << "---" << m_fsInfo.fMinFactor;
|
||||
|
||||
bool bFlagIsOverTrying = false;
|
||||
bool bFlagIsLowerMinExposureTime = false;
|
||||
bool bFlagIsOverMaxExposureTime = false;
|
||||
bool bFlagIsAutoExposureOK = false;
|
||||
bool bFlagIsAutoExposureFailed = false;
|
||||
|
||||
bool bIsValueOverflow = false;
|
||||
bool bIsLastValueOverflow = false;
|
||||
|
||||
int iExposureTime = 0;
|
||||
float fTempExposureTime = 0;
|
||||
double fLastExposureTime = 0.1;
|
||||
int iRepeatCount = 0;
|
||||
|
||||
//int iRes = m_pFSCtrl->SetExposureTime(1000);//need change to load from files
|
||||
int iRes = 0;
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
|
||||
{
|
||||
DataFrame dfTemp;
|
||||
|
||||
if (iRepeatCount++ > 30)
|
||||
{
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
bFlagIsOverTrying = true;
|
||||
break;
|
||||
}
|
||||
//m_pFSCtrl->SetExposureTime(5000);
|
||||
m_pFSCtrl->GetExposureTime(iExposureTime);
|
||||
//m_pFSCtrl->SetExposureTime(2500);
|
||||
//fExposureTime = (float)m_daDeviceAttr.iMinIntegrationTimeInMS;
|
||||
fTempExposureTime = iExposureTime;
|
||||
|
||||
iRes = m_pFSCtrl->SingleShot(dfTemp);
|
||||
//iRes = m_pFSCtrl->SingleShot(dfTemp);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
|
||||
return 2;
|
||||
}
|
||||
|
||||
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
|
||||
|
||||
double dSum = 0;
|
||||
int iCount = m_daDeviceAttr.iPixels / 100;
|
||||
for (int i = 0; i < iCount; i++)
|
||||
{
|
||||
dSum += dfTemp.lData[i];
|
||||
}
|
||||
double dTemp = dSum / iCount;
|
||||
|
||||
qDebug() << "Avg " << dTemp;
|
||||
|
||||
if (dTemp >= iDeviceDepth * 0.99)
|
||||
{
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
iExposureTime = iExposureTime / 2;
|
||||
}
|
||||
}
|
||||
|
||||
else if (iDeviceDepth * m_fsInfo.fMaxFactor >= dTemp && dTemp >= iDeviceDepth * m_fsInfo.fMinFactor)
|
||||
{
|
||||
qDebug() << "trace bFlagIsAutoExposureOK =1" << iExposureTime;
|
||||
bFlagIsAutoExposureOK = 1;
|
||||
}
|
||||
else if (dTemp > iDeviceDepth * m_fsInfo.fMaxFactor)
|
||||
{
|
||||
bIsValueOverflow = true;
|
||||
if (!bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
iExposureTime = iExposureTime * 3 / 4;
|
||||
}
|
||||
}
|
||||
else if (dTemp < iDeviceDepth * m_fsInfo.fMinFactor)
|
||||
{
|
||||
bIsValueOverflow = false;
|
||||
if (bIsLastValueOverflow)
|
||||
{
|
||||
iExposureTime = (float)(fLastExposureTime + iExposureTime) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
double dFactor;
|
||||
dFactor = dTemp / (iDeviceDepth * m_fsInfo.fMaxFactor);
|
||||
iExposureTime = (float)(iExposureTime / dFactor);
|
||||
}
|
||||
if (/*fExposureTime > 100 || */iExposureTime < 10)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
bFlagIsLowerMinExposureTime = true;
|
||||
}
|
||||
}
|
||||
bIsLastValueOverflow = bIsValueOverflow;
|
||||
fLastExposureTime = fTempExposureTime;
|
||||
|
||||
if (iExposureTime > 120000)
|
||||
{
|
||||
bFlagIsAutoExposureOK = false;
|
||||
bFlagIsAutoExposureFailed = true;
|
||||
float fPredictedExposureTime = 120000;
|
||||
iRes = m_pFSCtrl->SetExposureTime(120000);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Warning:PerformAutoExposure exceed max integration time.Will be limited to 30sec";
|
||||
}
|
||||
bFlagIsOverMaxExposureTime = true;
|
||||
break;
|
||||
}
|
||||
|
||||
iRes = m_pFSCtrl->SetExposureTime((int)iExposureTime);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
|
||||
return 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Success:PerformAutoExposure. Value"<< iExposureTime;
|
||||
}
|
||||
}
|
||||
fPredictedExposureTime = iExposureTime;
|
||||
qDebug() << "--------------------------Stop PerformAutoExposure" << " Thread ID:" << m_iThreadID;
|
||||
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::TakeDarkFrame()
|
||||
{
|
||||
qDebug() << "Starting TakeDarkFrame" << " Thread ID:" << m_iThreadID;
|
||||
|
||||
m_vecDataFrameDark.push_back(TakeOneFrame());
|
||||
|
||||
|
||||
qDebug() << "Stop TakeDarkFrame" << " Thread ID:" << m_iThreadID;
|
||||
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::TakeSignalFrame()
|
||||
{
|
||||
qDebug() << "Starting TakeSignal" << " Thread ID:" << m_iThreadID;
|
||||
|
||||
m_vecDataFrameSignal.push_back(TakeOneFrame());
|
||||
|
||||
qDebug() << "Stop TakeSignal" << " Thread ID:" << m_iThreadID;
|
||||
//emit SignalAcqFinished(m_iThreadID, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DataFrame CAbstractFSController::TakeOneFrame()
|
||||
{
|
||||
|
||||
DataFrame dfTemp;
|
||||
int iRes = m_pFSCtrl->SingleShot(dfTemp);
|
||||
if (iRes != 0)
|
||||
{
|
||||
qDebug() << "Err. SingleShot" << " Thread ID:" << m_iThreadID;
|
||||
}
|
||||
|
||||
return dfTemp;
|
||||
}
|
||||
|
||||
int CAbstractFSController::SaveDataFile()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::StartAcquisitionSignal()
|
||||
{
|
||||
//
|
||||
qDebug() << "Starting acq Signal" << " Thread ID:" << m_iThreadID;
|
||||
// DataFrame struDF;
|
||||
// int iii;
|
||||
// m_pFSCtrl->SetExposureTime(10000000);
|
||||
// m_pFSCtrl->GetExposureTime(iii);
|
||||
// m_pFSCtrl->SingleShot(struDF);
|
||||
|
||||
|
||||
|
||||
//PerformAutoExposure();
|
||||
TakeSignalFrame();
|
||||
|
||||
qDebug() << "Stop acq Signal" << " Thread ID:" << m_iThreadID;
|
||||
emit SignalAcqFinished_Signal(m_iThreadID, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::StartAcquisitionDark()
|
||||
{
|
||||
qDebug() << "Starting acq Dark" << " Thread ID:" << m_iThreadID;
|
||||
TakeDarkFrame();
|
||||
qDebug() << "Stop acq Dark"<< " Thread ID:" << m_iThreadID;
|
||||
emit SignalAcqFinished_Dark(m_iThreadID, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::StopAcquisition()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::ClearBuffer()
|
||||
{
|
||||
m_vecDataFrameDark.clear();
|
||||
m_vecDataFrameSignal.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CAbstractFSController::GetBuffer(std::vector<DataFrame> &pvecDataFrameDark, std::vector<DataFrame> &pvecDataFrameSignal)
|
||||
{
|
||||
for (size_t i=0; i < m_vecDataFrameSignal.size(); i++)
|
||||
{
|
||||
pvecDataFrameSignal.push_back(m_vecDataFrameSignal[i]);
|
||||
pvecDataFrameDark.push_back(m_vecDataFrameDark[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
62
source/CaptureThread/AbstractFSController.h
Normal file
62
source/CaptureThread/AbstractFSController.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "ATPControl_Serial_QT.h"
|
||||
#include "OControl_USB.h"
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
typedef struct tagFSInfo
|
||||
{
|
||||
ZZ_U8 ucDeviceModel;
|
||||
std::string strInterface;
|
||||
std::string strSN;
|
||||
long lDepth;
|
||||
float fMinFactor;
|
||||
float fMaxFactor;
|
||||
}FSInfo;
|
||||
|
||||
class CAbstractFSController :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CAbstractFSController(QObject* parent = nullptr);
|
||||
virtual ~CAbstractFSController();
|
||||
public:
|
||||
//call first
|
||||
virtual int SetRunParas(int iThreadID, FSInfo fsInfo);
|
||||
|
||||
//create derived class from base class
|
||||
virtual int InitializeFSControl();
|
||||
|
||||
//sync info
|
||||
virtual int GetDeviceAttr(DeviceAttribute &daAttr);
|
||||
//DataFrame GetLastDataFrame();
|
||||
|
||||
private:
|
||||
CIrisFSBase *m_pFSCtrl;
|
||||
int m_iThreadID;
|
||||
FSInfo m_fsInfo;
|
||||
//DataFrame m_dfDark,m_dfSignal;
|
||||
std::vector<DataFrame> m_vecDataFrameDark, m_vecDataFrameSignal;
|
||||
|
||||
DeviceAttribute m_daDeviceAttr;
|
||||
private:
|
||||
int PerformAutoExposure();
|
||||
int TakeDarkFrame();
|
||||
int TakeSignalFrame();
|
||||
DataFrame TakeOneFrame();
|
||||
int SaveDataFile();
|
||||
|
||||
public slots:
|
||||
virtual int StartAcquisitionSignal();
|
||||
virtual int StartAcquisitionDark();
|
||||
virtual int StopAcquisition();
|
||||
virtual int ClearBuffer();
|
||||
virtual int GetBuffer(std::vector<DataFrame> &pvecDataFrameDark, std::vector<DataFrame> &pvecDataFrameSignal);
|
||||
|
||||
|
||||
signals:
|
||||
void SignalAcqStarted();
|
||||
void SignalAcqFinished_Signal(int iThreadID, int iFlagStatus);
|
||||
void SignalAcqFinished_Dark (int iThreadID, int iFlagStatus);
|
||||
};
|
||||
486
source/CaptureThread/MainDataGrabber.cpp
Normal file
486
source/CaptureThread/MainDataGrabber.cpp
Normal file
@ -0,0 +1,486 @@
|
||||
#include "MainDataGrabber.h"
|
||||
|
||||
CMainDataGrabber::CMainDataGrabber(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Signal = NULL;
|
||||
m_piFlagCaptureThreadStatus_Dark = NULL;
|
||||
|
||||
//m_GrabTimer = new QTimer(this);
|
||||
|
||||
m_iFlagIsCapturing = false;
|
||||
m_iFlagIsCapturing_Signal = false;
|
||||
m_iFlagIsCapturing_Dark = false;
|
||||
|
||||
//qRegisterMetaType<DataFrame>("DataFrame");
|
||||
//qRegisterMetaType<vector<vector<DataFrame>>>();
|
||||
}
|
||||
|
||||
CMainDataGrabber::~CMainDataGrabber()
|
||||
{
|
||||
if (m_pControlThread.size() != 0)
|
||||
{
|
||||
for (int i=0;i< m_pControlThread.size();i++)
|
||||
{
|
||||
delete m_pControlThread[i];
|
||||
}
|
||||
}
|
||||
m_pControlThread.clear();
|
||||
|
||||
if (m_piFlagCaptureThreadStatus_Signal!=NULL)
|
||||
{
|
||||
delete m_piFlagCaptureThreadStatus_Signal;
|
||||
}
|
||||
|
||||
if (m_piFlagCaptureThreadStatus_Dark != NULL)
|
||||
{
|
||||
delete m_piFlagCaptureThreadStatus_Dark;
|
||||
}
|
||||
|
||||
|
||||
// if (m_GrabTimer!=NULL)
|
||||
// {
|
||||
// m_GrabTimer->stop();
|
||||
// delete m_GrabTimer;
|
||||
// }
|
||||
}
|
||||
|
||||
void CMainDataGrabber::Delay_MSec(ZZ_U16 usMS)
|
||||
{
|
||||
QEventLoop qeLoop;
|
||||
QTimer::singleShot(usMS, &qeLoop, SLOT(quit()));
|
||||
qeLoop.exec();
|
||||
}
|
||||
|
||||
void CMainDataGrabber::SubDataFrame(DataFrame& dfLeft, DataFrame const dfRight, int iCount)
|
||||
{
|
||||
for (int i = 0; i < iCount; i++)
|
||||
{
|
||||
dfLeft.lData[i] = dfLeft.lData[i]- dfRight.lData[i];
|
||||
}
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetContext(RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler)
|
||||
{
|
||||
SetGrabberParams(struGrabberRTParams);
|
||||
SetGrabberFileProcessor(dfpSaver);
|
||||
SetTimer(sScheduler);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetContext(RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler, CMainDataUploader &mduUploader)
|
||||
{
|
||||
SetGrabberParams(struGrabberRTParams);
|
||||
SetGrabberFileProcessor(dfpSaver);
|
||||
SetTimer(sScheduler);
|
||||
SetUploader(mduUploader/*, struGrabberRTParams*/);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMainDataGrabber::Init_Normal()
|
||||
{
|
||||
InitThreadStatus();
|
||||
InitializeWorkers();
|
||||
SetupMsgPipelines();
|
||||
StartWorkers();
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetGrabberParams(RunTimeGrabberParams struGrabberRTParams)
|
||||
{
|
||||
m_struAcqTime = struGrabberRTParams.atsParams;
|
||||
m_struDeviceContext = struGrabberRTParams.fscParams;
|
||||
m_struAcqPosSetting = struGrabberRTParams.apsParams;
|
||||
m_struLinearShutterContext = struGrabberRTParams.lscParam;
|
||||
|
||||
m_iTotalThreads = m_struDeviceContext.ucDeviceNumber;
|
||||
|
||||
m_struRTGP = struGrabberRTParams;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetGrabberFileProcessor(DataFileProcessor &dfpSaver)
|
||||
{
|
||||
m_pdfpSaver = &dfpSaver;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetTimer(Scheduler &sScheduler)
|
||||
{
|
||||
m_psScheduler = &sScheduler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetUploader(CMainDataUploader &mduUploader/*, RunTimeGrabberParams struGrabberRTParams*/)
|
||||
{
|
||||
m_pmduUploader = &mduUploader;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::InitLS()
|
||||
{
|
||||
PortInfo piTemp;
|
||||
piTemp.qstrFullPortName = QString::fromStdString(m_struLinearShutterContext.strInterface);
|
||||
m_ctrlLS.ILMES_InitializeComm(piTemp, m_struLinearShutterContext.ucProtocolType, m_struLinearShutterContext.ucCmdID);
|
||||
ControllerParams cpTemp;
|
||||
bool res = m_ctrlLS.ILMES_InitializeParams(cpTemp);
|
||||
|
||||
m_ctrlLS.ILMES_SetPosition(m_struAcqPosSetting.iPosition, m_struAcqPosSetting.iTotalPosition);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::InitThreadStatus()
|
||||
{
|
||||
if (m_piFlagCaptureThreadStatus_Signal!=NULL)
|
||||
{
|
||||
delete m_piFlagCaptureThreadStatus_Signal;
|
||||
}
|
||||
m_piFlagCaptureThreadStatus_Signal = new int[m_iTotalThreads];
|
||||
for (int i = 0; i < m_iTotalThreads; i++)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Signal[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
if (m_piFlagCaptureThreadStatus_Dark != NULL)
|
||||
{
|
||||
delete m_piFlagCaptureThreadStatus_Dark;
|
||||
}
|
||||
m_piFlagCaptureThreadStatus_Dark = new int[m_iTotalThreads];
|
||||
for (int i = 0; i < m_iTotalThreads; i++)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Dark[i] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::InitializeWorkers()
|
||||
{
|
||||
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Signal[i] = 0;
|
||||
m_piFlagCaptureThreadStatus_Dark[i] = 0;
|
||||
|
||||
FSInfo fsInfo;
|
||||
fsInfo.strInterface = m_struDeviceContext.strInterface[i];
|
||||
fsInfo.ucDeviceModel = m_struDeviceContext.ucDeviceModel[i];
|
||||
fsInfo.strSN = m_struDeviceContext.strSN[i];
|
||||
fsInfo.fMaxFactor = m_struDeviceContext.fMaxFactor[i];
|
||||
fsInfo.fMinFactor = m_struDeviceContext.fMinFactor[i];
|
||||
fsInfo.lDepth = m_struDeviceContext.lDepth[i];
|
||||
|
||||
CAbstractFSController* m_pWorkThread = new CAbstractFSController;
|
||||
m_pWorkThread->SetRunParas(i, fsInfo);
|
||||
m_pWorkThread->InitializeFSControl();
|
||||
|
||||
DeviceAttribute daAttrTemp;
|
||||
m_pWorkThread->GetDeviceAttr(daAttrTemp);
|
||||
m_struDeviceContext.usPixels[i] = (ZZ_U16)daAttrTemp.iPixels;
|
||||
for (ZZ_U16 j=0;j< daAttrTemp.iPixels;j++)
|
||||
{
|
||||
m_struDeviceContext.fWavelength[i][j] = daAttrTemp.fWaveLengthInNM[j];
|
||||
}
|
||||
m_pControlThread.push_back(m_pWorkThread);
|
||||
}
|
||||
m_struRTGP.fscParams = m_struDeviceContext;
|
||||
m_pdfpSaver->SetDeviceInfo(m_struDeviceContext);
|
||||
m_pmduUploader->SetRTGP(m_struRTGP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::StartWorkers()
|
||||
{
|
||||
|
||||
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
|
||||
{
|
||||
QThread *pWorkThreadHolder = new QThread();
|
||||
m_pControlThread[i]->moveToThread(pWorkThreadHolder);
|
||||
pWorkThreadHolder->start();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::SetupMsgPipelines()
|
||||
{
|
||||
//connect(this, &CMainDataGrabber::SignalStartGrabOnce, this, &CMainDataGrabber::StartGrab);
|
||||
|
||||
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
|
||||
{
|
||||
connect(this, &CMainDataGrabber::SignalStartGrabOnce_Signal, m_pControlThread[i], &CAbstractFSController::StartAcquisitionSignal);
|
||||
connect(this, &CMainDataGrabber::SignalStartGrabOnce_Dark, m_pControlThread[i], &CAbstractFSController::StartAcquisitionDark);
|
||||
connect(m_pControlThread[i], &CAbstractFSController::SignalAcqFinished_Signal, this, &CMainDataGrabber::HandleThreadEvent_Signal);
|
||||
connect(m_pControlThread[i], &CAbstractFSController::SignalAcqFinished_Dark, this, &CMainDataGrabber::HandleThreadEvent_Dark);
|
||||
}
|
||||
|
||||
connect(this, &CMainDataGrabber::SignalGrabOnceFinished, this, &CMainDataGrabber::GrabOnceFinished);
|
||||
|
||||
//connect(m_GrabTimer, &QTimer::timeout, this, &CMainDataGrabber::OnTimeCounter);
|
||||
connect(m_psScheduler, &Scheduler::SignalGrabOnce, this, &CMainDataGrabber::OnTimeCounter);
|
||||
|
||||
connect(this, &CMainDataGrabber::SignalStartGrab, this, &CMainDataGrabber::StartGrabTimer);
|
||||
|
||||
connect(this, &CMainDataGrabber::SignalGrabOnceFinished_Signal, this, &CMainDataGrabber::GrabOnceFinished_Signal);
|
||||
connect(this, &CMainDataGrabber::SignalGrabOnceFinished_Dark, this, &CMainDataGrabber::GrabOnceFinished_Dark);
|
||||
|
||||
connect(this, &CMainDataGrabber::SignalPushOneDataFrame, m_pmduUploader,&CMainDataUploader::SlotPushOneDataFrame);
|
||||
|
||||
qDebug()<<connect(this,&CMainDataGrabber::SignalLSInit,this,&CMainDataGrabber::InitLS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::StartGrab()
|
||||
{
|
||||
emit SignalStartGrab();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMainDataGrabber::Init_Self()
|
||||
{
|
||||
//emit SignalLSInit();
|
||||
return;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::HandleThreadEvent_Signal(int iThreadID, int iFlagStatus)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Signal[iThreadID] = iFlagStatus;
|
||||
|
||||
bool bFinished = true;
|
||||
for (int i = 0; i < m_iTotalThreads; i++)
|
||||
{
|
||||
if (m_piFlagCaptureThreadStatus_Signal[i] != 1)
|
||||
{
|
||||
bFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFinished)
|
||||
{
|
||||
emit SignalGrabOnceFinished_Signal();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::HandleThreadEvent_Dark(int iThreadID, int iFlagStatus)
|
||||
{
|
||||
m_piFlagCaptureThreadStatus_Dark[iThreadID] = iFlagStatus;
|
||||
|
||||
bool bFinished = true;
|
||||
for (int i = 0; i < m_iTotalThreads; i++)
|
||||
{
|
||||
if (m_piFlagCaptureThreadStatus_Dark[i] != 1)
|
||||
{
|
||||
bFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFinished)
|
||||
{
|
||||
emit SignalGrabOnceFinished_Dark();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::GrabOnceFinished_Signal()
|
||||
{
|
||||
m_iFlagIsCapturing_Signal = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::GrabOnceFinished_Dark()
|
||||
{
|
||||
m_iFlagIsCapturing_Dark = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//int CMainDataGrabber::InitLS_Self(/*RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler*/)
|
||||
//{
|
||||
// //SetGrabberFileProcessor(dfpSaver);
|
||||
// //SetGrabberParams(struGrabberRTParams);
|
||||
// //SetTimer(sScheduler);
|
||||
// InitLS();
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
int CMainDataGrabber::StartGrabTimer()
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////start
|
||||
////check start time
|
||||
// bool bStopWait = false;
|
||||
// while (!bStopWait)
|
||||
// {
|
||||
// QTime qtTime = QTime::currentTime();
|
||||
// if (m_struAcqTime.qtStartTime >= qtTime && qtTime<m_struAcqTime.qtStopTime)
|
||||
// {
|
||||
// bStopWait = true;
|
||||
// }
|
||||
// }
|
||||
//start
|
||||
//int iIntervalInMS =m_struAcqTime.qtInterval.hour()*3600*1000+ m_struAcqTime.qtInterval.minute()*60*1000+ m_struAcqTime.qtInterval.second()*1000;
|
||||
//m_GrabTimer->start(3000);
|
||||
//////////////////////////////////////////////////////////////////////////test
|
||||
// m_iFlagIsCapturing = true;
|
||||
// emit SignalStartGrabOnce();
|
||||
// while (m_iFlagIsCapturing)
|
||||
// {
|
||||
// QThread::msleep(1000);
|
||||
// }
|
||||
//
|
||||
// m_iFlagIsCapturing = true;
|
||||
// InitThreadStatus();
|
||||
// emit SignalStartGrabOnce();
|
||||
// while (m_iFlagIsCapturing)
|
||||
// {
|
||||
// QThread::msleep(1000);
|
||||
// }
|
||||
// qDebug() << "Allgrab stopped" << " Thread ID:" <<2;
|
||||
////final test code eat my ass
|
||||
// m_iFlagIsCapturing = 1;
|
||||
//
|
||||
//
|
||||
// for (int i=0;i<5;i++)
|
||||
// {
|
||||
// m_iFlagIsCapturing_Signal = 1;
|
||||
// emit SignalStartGrabOnce_Signal();
|
||||
// while (m_iFlagIsCapturing_Signal)
|
||||
// {
|
||||
// Delay_MSec(200);
|
||||
// qDebug() << "msleep" << 200;
|
||||
// }
|
||||
//
|
||||
// m_iFlagIsCapturing_Dark = 1;
|
||||
// emit SignalStartGrabOnce_Dark();
|
||||
// while (m_iFlagIsCapturing_Dark)
|
||||
// {
|
||||
// Delay_MSec(200);
|
||||
// qDebug() << "msleep" << 200;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// qDebug() << "for quit";
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::GrabOnceFinished()
|
||||
{
|
||||
m_iFlagIsCapturing = false;
|
||||
// QTimer t;
|
||||
// t.start();
|
||||
// while (1)
|
||||
// {
|
||||
// QThread::msleep(1);
|
||||
// QCoreApplication::processEvents();
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMainDataGrabber::OnTimeCounter()
|
||||
{
|
||||
if (m_iFlagIsCapturing)
|
||||
{
|
||||
qDebug() << "Fatal Thread Err.";
|
||||
return 1000;
|
||||
}
|
||||
m_iFlagIsCapturing = 1;
|
||||
|
||||
//return 0;
|
||||
// m_struAcqPosSetting.iTotalPosition = 5;
|
||||
|
||||
//m_pdfpSaver->WriteDataFile();
|
||||
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
|
||||
{
|
||||
m_pControlThread[i]->ClearBuffer();
|
||||
}
|
||||
|
||||
for (int i=0;i< m_struAcqPosSetting.iTotalPosition-1;i++)
|
||||
{
|
||||
////move to
|
||||
qDebug()<<"Start ILMES_MoveToPos:"<<i+1;
|
||||
//m_ctrlLS.ILMES_MoveToPos(i+1);
|
||||
qDebug() << "Stop ILMES_MoveToPos:" << i + 1;
|
||||
m_struAcqPosSetting.iPosition[i + 1];
|
||||
m_iFlagIsCapturing_Signal = 1;
|
||||
emit SignalStartGrabOnce_Signal();
|
||||
while (m_iFlagIsCapturing_Signal)
|
||||
{
|
||||
Delay_MSec(1000);
|
||||
}
|
||||
|
||||
|
||||
////move to
|
||||
qDebug() << "Start ILMES_MoveToPos:" << 0;
|
||||
//m_ctrlLS.ILMES_MoveToPos(0);
|
||||
qDebug() << "Stop ILMES_MoveToPos:" << 0;
|
||||
m_struAcqPosSetting.iPosition[0];
|
||||
m_iFlagIsCapturing_Dark = 1;
|
||||
emit SignalStartGrabOnce_Dark();
|
||||
while (m_iFlagIsCapturing_Dark)
|
||||
{
|
||||
Delay_MSec(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::vector<DataFrame>> vecData;
|
||||
|
||||
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
|
||||
{
|
||||
std::vector<DataFrame> vecDark, vecSignal, vecResult;
|
||||
m_pControlThread[i]->GetBuffer(vecDark, vecSignal);
|
||||
for (size_t j=0;j< vecDark.size();j++)
|
||||
{
|
||||
SubDataFrame(vecSignal[j], vecDark[j], m_struDeviceContext.usPixels[i]);
|
||||
}
|
||||
vecData.push_back(vecSignal);
|
||||
}
|
||||
|
||||
//emit SignalPushOneDataFrame(vecData);
|
||||
m_pmduUploader->SetData(vecData);
|
||||
emit SignalPushOneDataFrame();
|
||||
m_pdfpSaver->SetData(vecData);
|
||||
m_pdfpSaver->WriteDataFile();
|
||||
m_iFlagIsCapturing = 0;
|
||||
|
||||
// qDebug() << "-------------------------------------------busy" << QTime::currentTime().toString();
|
||||
// QThread::msleep(5000);
|
||||
// return 0;
|
||||
// if (m_iFlagIsCapturing)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// m_iFlagIsCapturing = 1;
|
||||
//qDebug() << "-------------------------------------------return";
|
||||
//return 1;
|
||||
// for (int i = 0; i < 5; i++)
|
||||
// {
|
||||
// m_iFlagIsCapturing_Signal = 1;
|
||||
// emit SignalStartGrabOnce_Signal();
|
||||
// while (m_iFlagIsCapturing_Signal)
|
||||
// {
|
||||
// //Delay_MSec(1000);
|
||||
// QThread::msleep(100);
|
||||
// QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
// //qDebug() << "msleep" << 1000;
|
||||
// }
|
||||
//
|
||||
// m_iFlagIsCapturing_Dark = 1;
|
||||
// emit SignalStartGrabOnce_Dark();
|
||||
// while (m_iFlagIsCapturing_Dark)
|
||||
// {
|
||||
// Delay_MSec(1000);
|
||||
// QThread::msleep(100);
|
||||
// QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
// //qDebug() << "msleep" << 1000;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// qDebug() << "for quit";
|
||||
//
|
||||
//
|
||||
// emit SignalGrabOnceFinished();
|
||||
return 0;
|
||||
}
|
||||
|
||||
99
source/CaptureThread/MainDataGrabber.h
Normal file
99
source/CaptureThread/MainDataGrabber.h
Normal file
@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
#include"pch.h"
|
||||
#include <vector>
|
||||
#include "AbstractFSController.h"
|
||||
#include "DataFileProcessor.h"
|
||||
#include "Scheduler.h"
|
||||
#include "VSMD12XControl.h"
|
||||
#include "MainDataUploader.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ZZ_MISCDEF::ZZ_RUNPARAMS;
|
||||
|
||||
//Q_DECLARE_METATYPE(vector<vector<DataFrame>>)
|
||||
|
||||
class CMainDataGrabber :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CMainDataGrabber(QObject* parent = nullptr);
|
||||
~CMainDataGrabber();
|
||||
|
||||
private:
|
||||
vector<CAbstractFSController *> m_pControlThread;
|
||||
vector<QThread* > m_pqThreadHolder;
|
||||
|
||||
int *m_piFlagCaptureThreadStatus_Signal;
|
||||
int *m_piFlagCaptureThreadStatus_Dark;
|
||||
|
||||
int m_iTotalThreads;
|
||||
|
||||
int m_iFlagIsCapturing;
|
||||
int m_iFlagIsCapturing_Signal;
|
||||
int m_iFlagIsCapturing_Dark;
|
||||
|
||||
DataFileProcessor * m_pdfpSaver;
|
||||
Scheduler * m_psScheduler;
|
||||
CMainDataUploader * m_pmduUploader;
|
||||
|
||||
CVSMD12XControl m_ctrlLS;
|
||||
|
||||
FSContext m_struDeviceContext;
|
||||
LSContext m_struLinearShutterContext;
|
||||
AcqPosSettings m_struAcqPosSetting;
|
||||
AcqTimeSettings m_struAcqTime;
|
||||
RunTimeGrabberParams m_struRTGP;
|
||||
|
||||
//QTimer *m_GrabTimer;
|
||||
private:
|
||||
void Delay_MSec(ZZ_U16 usMS);
|
||||
void SubDataFrame(DataFrame& dfLeft, DataFrame const dfRight,int iCount);
|
||||
|
||||
//Call this first
|
||||
int SetGrabberParams(RunTimeGrabberParams struGrabberRTParams);
|
||||
int SetGrabberFileProcessor(DataFileProcessor &dfpSaver);
|
||||
int SetTimer(Scheduler &sScheduler);
|
||||
int SetUploader(CMainDataUploader &mduUploader/*, RunTimeGrabberParams struGrabberRTParams*/);
|
||||
|
||||
int InitThreadStatus();
|
||||
int InitializeWorkers();
|
||||
int StartWorkers();
|
||||
int SetupMsgPipelines();
|
||||
int StartGrab();
|
||||
|
||||
|
||||
public:
|
||||
int SetContext(RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler);
|
||||
int SetContext(RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler,CMainDataUploader &mduUploader);
|
||||
void Init_Normal();
|
||||
void Init_Self();
|
||||
|
||||
public slots:
|
||||
//int InitLS_Self(/*RunTimeGrabberParams struGrabberRTParams, DataFileProcessor &dfpSaver, Scheduler &sScheduler*/);
|
||||
int InitLS();
|
||||
int StartGrabTimer();
|
||||
int OnTimeCounter();
|
||||
|
||||
int HandleThreadEvent_Signal(int iThreadID, int iFlagStatus);
|
||||
int HandleThreadEvent_Dark(int iThreadID, int iFlagStatus);
|
||||
|
||||
int GrabOnceFinished_Signal();
|
||||
int GrabOnceFinished_Dark();
|
||||
int GrabOnceFinished();
|
||||
|
||||
signals:
|
||||
void SignalStartGrabOnce_Signal();
|
||||
void SignalStartGrabOnce_Dark();
|
||||
|
||||
void SignalGrabOnceFinished_Signal();
|
||||
void SignalGrabOnceFinished_Dark();
|
||||
void SignalGrabOnceFinished();
|
||||
|
||||
|
||||
void SignalStopGrab();
|
||||
void SignalStartGrab();
|
||||
|
||||
void SignalLSInit();
|
||||
void SignalPushOneDataFrame();
|
||||
//void SignalPushOneDataFrame(std::vector<std::vector<DataFrame>> vecData);
|
||||
};
|
||||
74
source/CaptureThread/Scheduler.cpp
Normal file
74
source/CaptureThread/Scheduler.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include "Scheduler.h"
|
||||
|
||||
Scheduler::Scheduler(QObject* parent /*= nullptr*/)
|
||||
{
|
||||
m_GrabTimer = new QTimer(this);
|
||||
connect(m_GrabTimer, &QTimer::timeout, this, &Scheduler::OnTimeCounter);
|
||||
connect(this, &Scheduler::SignalSelfStart, this, &Scheduler::StartAsPlanned);
|
||||
}
|
||||
|
||||
Scheduler::~Scheduler()
|
||||
{
|
||||
if (m_GrabTimer != NULL)
|
||||
{
|
||||
m_GrabTimer->stop();
|
||||
delete m_GrabTimer;
|
||||
}
|
||||
}
|
||||
|
||||
void Scheduler::SetAcqTimeParams(AcqTimeSettings struAcqTime)
|
||||
{
|
||||
m_struAcqTime = struAcqTime;
|
||||
}
|
||||
|
||||
void Scheduler::Preheating()
|
||||
{
|
||||
qDebug() << "Start Preheating";
|
||||
#ifdef _DEBUG
|
||||
QThread::msleep(5000);
|
||||
#else
|
||||
QThread::msleep(10000);//NEED TO CHANGE BEFOR HAND TO CUSTOM
|
||||
#endif
|
||||
qDebug() << "Preheating Finished";
|
||||
}
|
||||
|
||||
void Scheduler::SelfStart()
|
||||
{
|
||||
emit SignalSelfStart();
|
||||
}
|
||||
|
||||
void Scheduler::StartAsPlanned()
|
||||
{
|
||||
bool bStopWait = false;
|
||||
QTime qtTime = QTime::currentTime();
|
||||
while (!bStopWait)
|
||||
{
|
||||
QThread::msleep(100);
|
||||
if (m_struAcqTime.qtStartTime <= qtTime && qtTime < m_struAcqTime.qtStopTime)
|
||||
{
|
||||
bStopWait = true;
|
||||
}
|
||||
}
|
||||
|
||||
int iIntervalInMS = m_struAcqTime.qtInterval.hour() * 3600 * 1000 + m_struAcqTime.qtInterval.minute() * 60 * 1000 + m_struAcqTime.qtInterval.second() * 1000;
|
||||
|
||||
m_GrabTimer->start(iIntervalInMS);
|
||||
}
|
||||
|
||||
int Scheduler::OnTimeCounter()
|
||||
{
|
||||
QTime qtTime = QTime::currentTime();
|
||||
if (m_struAcqTime.qtStartTime <= qtTime && qtTime < m_struAcqTime.qtStopTime)
|
||||
{
|
||||
qDebug() << "it's time to work...work work.";
|
||||
emit SignalGrabOnce();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
system("gpio write 1 0");//<2F>豸<EFBFBD>ϵ<EFBFBD>
|
||||
qDebug() << "gpio write 1 0......"<<endl;
|
||||
qDebug() << "Non working time. Idling......";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
26
source/CaptureThread/Scheduler.h
Normal file
26
source/CaptureThread/Scheduler.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include"pch.h"
|
||||
#include "ZZ_Types.h"
|
||||
using namespace std;
|
||||
using namespace ZZ_MISCDEF::ZZ_RUNPARAMS;
|
||||
class Scheduler :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Scheduler(QObject* parent = nullptr);
|
||||
~Scheduler();
|
||||
private:
|
||||
QTimer *m_GrabTimer;
|
||||
AcqTimeSettings m_struAcqTime;
|
||||
private:
|
||||
void StartAsPlanned();
|
||||
public:
|
||||
void SetAcqTimeParams(AcqTimeSettings struAcqTime);
|
||||
void Preheating();
|
||||
void SelfStart();
|
||||
public slots:
|
||||
int OnTimeCounter();
|
||||
signals:
|
||||
void SignalGrabOnce();
|
||||
void SignalSelfStart();
|
||||
};
|
||||
Reference in New Issue
Block a user