文件存储完成

This commit is contained in:
2021-12-08 17:43:27 +08:00
parent 3de7eb3da7
commit ec8bb49b8f
26 changed files with 373 additions and 75 deletions

View File

@ -1 +0,0 @@
EnvironmentalContext,CaseHumidity,,CaseTemperature,,GPS_Altitude,50,GPS_Latitude,118,GPS_Longtitude,117,GPS_North,on,Location,beijing,UTCDateTime,2021_12_06 09:17:15,DownlaodAddress,http://www.iris-rs.cn,DownloadUserID,newuser,HTTPServer,,InstallationTime,2021-11-18,NameOfMaintenanceStaff,renlixin,PhoneNumberOfMaintenanceStaff,110110110,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,6 @@
[DEVICE INFO]
TotalSpectrometer=1
[FS2]
Model=OSIFBeta
Port=-1
UID=QEP02975
TotalSpectrometer=2
[FS1]
Model=OSIFBeta
Port=-1
@ -12,6 +9,13 @@ AEMax=0.85
AEMin=0.75
Depth=65535
[FS2]
Model=OSIFAlpha
Port=-1
UID=QEP02975
AEMax=0.85
AEMin=0.75
Depth=65535
[FS3]
Model=Null
[LINEAR SHUTTER]
Port=4

View File

@ -42,10 +42,16 @@ int main(int argc, char *argv[])
testDG.InitializeWorkers();
testDG.SetupMsgPipelines();
testDG.StartWorkers();
m_pqDataGrabberThreadHolder->start();
m_pqDataGrabberThreadHolder->start();
testDG.StartGrab();
//QString qstrTest = "This is a test message 2";
//qDebug() << qstrTest;
//cout << "This is a test message";

View File

@ -366,13 +366,13 @@ int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fM
return 2;
}
HeapSort(dfTemp.usData, m_daDeviceAttr.iPixels);
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
double dSum = 0;
int iCount = m_daDeviceAttr.iPixels / 100;
for (int i = 0; i < iCount; i++)
{
dSum += dfTemp.usData[i];
dSum += dfTemp.lData[i];
}
double dTemp = dSum / iCount;
@ -519,7 +519,7 @@ int ZZ_ATPControl_Serial_Qt::SingleShot(DataFrame &dfData)
else
{
int iDataSizeInPixel = (qbRecv.size() - 1) / 2;
memcpy(dfData.usData, qbRecv.data() + 1, iDataSizeInPixel * 2);
memcpy(dfData.lData, qbRecv.data() + 1, iDataSizeInPixel * 2);
}

View File

@ -24,10 +24,23 @@ void DataFileProcessor::SetManmadeEnviromentalContext(MEContext struMEC)
m_struMEC = struMEC;
}
void DataFileProcessor::SetDeviceInfo(FSContext struDeviceContext)
{
m_struDeviceContext = struDeviceContext;
}
void DataFileProcessor::SetData(std::vector<std::vector<DataFrame>> vecData)
{
m_vecData.clear();
m_vecData = vecData;
}
bool DataFileProcessor::WriteDataFile()
{
GenerateFilePath();
WriteInfo();
WriteEnvironmentInfo();
WriteDeviceInfo();
WriteData();
bool res = true;
return res;
}
@ -46,7 +59,7 @@ void DataFileProcessor::GenerateFilePath()
{
m_struEC.qstrLocation = "Unknown";
}
m_qstrFullFileName= m_qstrFullFileName+"/"+m_struEC.qstrLocation + qstrAddHMS+".txt";
m_qstrFullFileName= m_qstrFullFileName+"/"+m_struEC.qstrLocation + qstrAddHMS+".csv";
QDir qdirPath(m_qstrFilePath);
if (!qdirPath.exists())
@ -55,7 +68,7 @@ void DataFileProcessor::GenerateFilePath()
}
}
bool DataFileProcessor::WriteInfo()
bool DataFileProcessor::WriteEnvironmentInfo()
{
bool bRes = true;
QFile qfData(m_qstrFullFileName);
@ -90,7 +103,6 @@ bool DataFileProcessor::WriteInfo()
qfData.write("UTCDateTime,");
qfData.write(m_struEC.qstrUTCDateTime.toLatin1());
qfData.write(",");
//qfData.write("\n");
//MEC
@ -112,14 +124,109 @@ bool DataFileProcessor::WriteInfo()
qfData.write(",");
qfData.write("PhoneNumberOfMaintenanceStaff,");
qfData.write(m_struMEC.qstrPhoneNumberOfMaintenanceStaff.toLatin1());
qfData.write(",");
//qfData.write(",");
qfData.close();
return bRes;
}
void DataFileProcessor::WriteDeviceInfo()
{
QFile qfData(m_qstrFullFileName);
bool bRes = qfData.open(QFile::WriteOnly | QFile::Text | QIODevice::Append);
QString qstrTemp;
qfData.write("\n");
qfData.write("TotalSpectrometer,");
qstrTemp = QString::number(m_struDeviceContext.ucDeviceNumber);
qfData.write(qstrTemp.toLatin1());
qfData.write("\n");
for (int i=0;i< m_struDeviceContext.ucDeviceNumber;i++)
{
qstrTemp = QString("FS%1_Info").arg(i + 1);
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
qfData.write("Model,");
using namespace ZZ_MISCDEF::IRIS;
qstrTemp = QString::fromStdString(GetDeviceModelName(m_struDeviceContext.ucDeviceModel[i]));
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
qfData.write("SN,");
qstrTemp = QString::fromStdString(m_struDeviceContext.strSN[i]);
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
qfData.write("Pixels,");
qstrTemp = QString::number(m_struDeviceContext.usPixels[i]);
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
qfData.write("Depth,");
qstrTemp = QString::number(m_struDeviceContext.lDepth[i]);
qfData.write(qstrTemp.toLatin1());
qfData.write("\n");
qfData.write("Wavelength,");
for (unsigned short j = 0; j < m_struDeviceContext.usPixels[i]-1; j++)
{
qstrTemp = QString::number(m_struDeviceContext.fWavelength[i][j]);
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
}
qstrTemp = QString::number(m_struDeviceContext.fWavelength[i][m_struDeviceContext.usPixels[i] - 1]);
qfData.write(qstrTemp.toLatin1());
qfData.write("\n");
}
qfData.close();
}
bool DataFileProcessor::WriteData()
{
QFile qfData(m_qstrFullFileName);
bool bRes = qfData.open(QFile::WriteOnly | QFile::Text | QIODevice::Append);
QString qstrTemp;
qfData.write("Data Section");
qfData.write("\n");
using namespace ZZ_MISCDEF::IRIS;
for (int i=0;i<m_struDeviceContext.ucDeviceNumber;i++)
{
for (int j=0;j<m_vecData[i].size();j++)
{
qstrTemp = QString::fromStdString(GetDeviceModelName(m_struDeviceContext.ucDeviceModel[i]));
qfData.write(qstrTemp.toLatin1());
qstrTemp = QString("_P%1").arg(j + 1);
qfData.write(qstrTemp.toLatin1());
qfData.write(",");
qfData.write("valid");
qfData.write(",");
qstrTemp = QString::number(m_vecData[i][j].usExposureTimeInMS);
qfData.write(qstrTemp.toLatin1());
for (int k=0;k< m_struDeviceContext.usPixels[i];k++)
{
qfData.write(",");
qstrTemp = QString::number(m_vecData[i][j].lData[k]);
qfData.write(qstrTemp.toLatin1());
}
qfData.write("\n");
}
}
bool res = true;
return res;
}

View File

@ -2,18 +2,24 @@
#include "pch.h"
#include "ZZ_Types.h"
using namespace ZZ_MISCDEF::ZZ_DATAFILE;
using namespace ZZ_MISCDEF::ZZ_RUNPARAMS;
using namespace ZZ_MISCDEF::IRIS::FS;
class DataFileProcessor
{
public:
DataFileProcessor();
virtual ~DataFileProcessor();
public:
public:
void SetEnvironmentContex(EContext struEC);
void SetManmadeEnviromentalContext(MEContext truMEC);
void SetManmadeEnviromentalContext(MEContext struMEC);
void SetDeviceInfo(FSContext struDeviceContext);
void SetData(std::vector<std::vector<DataFrame>> vecData);
bool WriteDataFile();
private:
void GenerateFilePath();
bool WriteInfo();
bool WriteEnvironmentInfo();
void WriteDeviceInfo();
bool WriteData();
@ -22,7 +28,11 @@ private:
QString m_qstrFullFileName;
QString m_qstrFileName;
QString m_qstrFilePath;
QDateTime m_qdtTime;
EContext m_struEC;
MEContext m_struMEC;
QDateTime m_qdtTime;
FSContext m_struDeviceContext;
std::vector<std::vector<DataFrame>> m_vecData;
};

View File

@ -285,7 +285,7 @@ int OceanOptics_lib::SingleShot(DataFrame &dfData)
for (int tmp = 0; tmp < spec_length; tmp++)
{
dfData.usData[tmp] = spectrum[tmp];
dfData.lData[tmp] = spectrum[tmp];
}
int exposureTimeInMS;

View File

@ -6,11 +6,14 @@
#include <string>
#define MAX_DEVICENUMBER_FS 2
#define MAX_LINEARSHUTTER_POSITION 12
#define ZZ_Enum2String(x) #x
namespace ZZ_MISCDEF
{
typedef unsigned char ZZ_U8;
typedef unsigned short int ZZ_U16;
typedef unsigned long int ZZ_U32;
typedef long int ZZ_S32;
namespace IRIS
@ -21,11 +24,13 @@ namespace ZZ_MISCDEF
typedef struct tagDataFrame
{
ZZ_U16 usExposureTimeInMS;
ZZ_U16 usData[4096];
float fTemperature;
ZZ_S32 lData[4096];
float fTemperature = -1000;
double dTimes = 0;
}DataFrame;
typedef struct tagDeviceInfo
{
std::string strPN;
@ -40,6 +45,11 @@ namespace ZZ_MISCDEF
float fWaveLengthInNM[4096];
}DeviceAttribute;
// inline DataFrame GetIndex(DataFrame dfDark, DataFrame dfSignal)
// {
//
// }
}
enum DeviceModel
@ -51,46 +61,48 @@ namespace ZZ_MISCDEF
IS2
};
// inline std::string GetDeviceModelName(int iModel)
// {
// switch (iModel)
// {
// case DeviceModel::OSIFAlpha: return "OSIFAlpha"; break;
// case DeviceModel::OSIFBeta: return "OSIFBeta"; break;
// case DeviceModel::ISIF: return "ISIF"; break;
// case DeviceModel::IS1: return "IS1"; break;
// case DeviceModel::IS2: return "IS2"; break;
// default: return "error"; break;
// }
// }
//
// inline int GetIndex(std::string strDeviceModelName)
// {
// if (strDeviceModelName== "OSIFAlpha")
// {
// return DeviceModel::OSIFAlpha;
// }
// else if (strDeviceModelName == "OSIFBeta")
// {
// return DeviceModel::OSIFBeta;
// }
// else if (strDeviceModelName == "ISIF")
// {
// return DeviceModel::ISIF;
// }
// else if (strDeviceModelName == "IS1")
// {
// return DeviceModel::IS1;
// }
// else if(strDeviceModelName == "IS2")
// {
// return DeviceModel::IS2;
// }
// else
// {
// return -1;
// }
// }
inline std::string GetDeviceModelName(int iModel)
{
switch (iModel)
{
case DeviceModel::OSIFAlpha: return "OSIFAlpha"; break;
case DeviceModel::OSIFBeta: return "OSIFBeta"; break;
case DeviceModel::ISIF: return "ISIF"; break;
case DeviceModel::IS1: return "IS1"; break;
case DeviceModel::IS2: return "IS2"; break;
default: return "error"; break;
}
}
inline int GetIndex(std::string strDeviceModelName)
{
if (strDeviceModelName == "OSIFAlpha")
{
return DeviceModel::OSIFAlpha;
}
else if (strDeviceModelName == "OSIFBeta")
{
return DeviceModel::OSIFBeta;
}
else if (strDeviceModelName == "ISIF")
{
return DeviceModel::ISIF;
}
else if (strDeviceModelName == "IS1")
{
return DeviceModel::IS1;
}
else if (strDeviceModelName == "IS2")
{
return DeviceModel::IS2;
}
else
{
return -1;
}
}
};
@ -176,6 +188,8 @@ namespace ZZ_MISCDEF
long lDepth[MAX_DEVICENUMBER_FS];
float fMinFactor[MAX_DEVICENUMBER_FS];
float fMaxFactor[MAX_DEVICENUMBER_FS];
ZZ_U16 usPixels[MAX_DEVICENUMBER_FS];
float fWavelength[MAX_DEVICENUMBER_FS][4096];
}FSContext;
typedef struct tagLinearShutterContext

View File

@ -42,6 +42,7 @@ int CAbstractFSController::InitializeFSControl()
qDebug() << "OSIFAlpha Not Opened";
return 2;
}
break;
case DeviceModel::OSIFBeta:
m_pFSCtrl = new OceanOptics_lib;
@ -83,9 +84,9 @@ int CAbstractFSController::InitializeFSControl()
}
int iRes = m_pFSCtrl->GetDeviceAttribute(m_daDeviceAttr);
if (iRes !=0 )
if (iRes != 0)
{
qDebug() << "GetDeviceAttribute Failed"<< iRes;
qDebug() << "GetDeviceAttribute Failed" << iRes;
return 4;
}
@ -93,6 +94,12 @@ int CAbstractFSController::InitializeFSControl()
return 0;
}
int CAbstractFSController::GetDeviceAttr(DeviceAttribute &daAttr)
{
daAttr = m_daDeviceAttr;
return 0;
}
int CAbstractFSController::PerformAutoExposure()
{
qDebug() << "--------------------------Starting PerformAutoExposure" << " Thread ID:" << m_iThreadID;
@ -146,13 +153,13 @@ int CAbstractFSController::PerformAutoExposure()
return 2;
}
HeapSort(dfTemp.usData, m_daDeviceAttr.iPixels);
HeapSort(dfTemp.lData, m_daDeviceAttr.iPixels);
double dSum = 0;
int iCount = m_daDeviceAttr.iPixels / 100;
for (int i = 0; i < iCount; i++)
{
dSum += dfTemp.usData[i];
dSum += dfTemp.lData[i];
}
double dTemp = dSum / iCount;
@ -219,6 +226,10 @@ int CAbstractFSController::PerformAutoExposure()
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;
}
@ -291,7 +302,10 @@ int CAbstractFSController::StartAcquisitionSignal()
// m_pFSCtrl->SetExposureTime(10000000);
// m_pFSCtrl->GetExposureTime(iii);
// m_pFSCtrl->SingleShot(struDF);
PerformAutoExposure();
//PerformAutoExposure();
TakeSignalFrame();
qDebug() << "Stop acq Signal" << " Thread ID:" << m_iThreadID;
@ -321,10 +335,13 @@ int CAbstractFSController::ClearBuffer()
return 0;
}
int CAbstractFSController::GetBuffer(std::vector<DataFrame> *pvecDataFrameDark, std::vector<DataFrame> *pvecDataFrameSignal)
int CAbstractFSController::GetBuffer(std::vector<DataFrame> &pvecDataFrameDark, std::vector<DataFrame> &pvecDataFrameSignal)
{
pvecDataFrameDark = &m_vecDataFrameDark;
pvecDataFrameSignal = &m_vecDataFrameSignal;
for (size_t i=0; i < m_vecDataFrameSignal.size(); i++)
{
pvecDataFrameSignal.push_back(m_vecDataFrameSignal[i]);
pvecDataFrameDark.push_back(m_vecDataFrameDark[i]);
}
return 0;
}

View File

@ -28,7 +28,9 @@ public:
//create derived class from base class
virtual int InitializeFSControl();
DataFrame GetLastDataFrame();
//sync info
virtual int GetDeviceAttr(DeviceAttribute &daAttr);
//DataFrame GetLastDataFrame();
private:
CIrisFSBase *m_pFSCtrl;
@ -50,7 +52,7 @@ public slots:
virtual int StartAcquisitionDark();
virtual int StopAcquisition();
virtual int ClearBuffer();
virtual int GetBuffer(std::vector<DataFrame> *pvecDataFrameDark, std::vector<DataFrame> *pvecDataFrameSignal);
virtual int GetBuffer(std::vector<DataFrame> &pvecDataFrameDark, std::vector<DataFrame> &pvecDataFrameSignal);
signals:

View File

@ -48,6 +48,14 @@ void CMainDataGrabber::Delay_MSec(ZZ_U16 usMS)
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::SetGrabberParams(RunTimeGrabberParams struGrabberRTParams)
{
m_struAcqTime = struGrabberRTParams.atsParams;
@ -108,8 +116,18 @@ int CMainDataGrabber::InitializeWorkers()
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_pdfpSaver->SetDeviceInfo(m_struDeviceContext);
return 0;
}
@ -298,7 +316,7 @@ int CMainDataGrabber::GrabOnceFinished()
}
m_iFlagIsCapturing = 1;
m_struAcqPosSetting.iTotalPosition = 2;
m_struAcqPosSetting.iTotalPosition = 5;
//m_pdfpSaver->WriteDataFile();
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
@ -329,11 +347,20 @@ int CMainDataGrabber::GrabOnceFinished()
}
std::vector<DataFrame> test,test1;
std::vector<std::vector<DataFrame>> vecData;
for (ZZ_U8 i = 0; i < m_struDeviceContext.ucDeviceNumber; i++)
{
m_pControlThread[i]->GetBuffer(&test, &test1);
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);
}
m_pdfpSaver->SetData(vecData);
m_pdfpSaver->WriteDataFile();
// qDebug() << "-------------------------------------------busy" << QTime::currentTime().toString();
// QThread::msleep(5000);
// return 0;

View File

@ -38,6 +38,7 @@ private:
QTimer *m_GrabTimer;
private:
void Delay_MSec(ZZ_U16 usMS);
void SubDataFrame(DataFrame& dfLeft, DataFrame const dfRight,int iCount);
public:
//Call this first
int SetGrabberParams(RunTimeGrabberParams struGrabberRTParams);