This commit is contained in:
2021-11-05 17:00:48 +08:00
parent 5e421006e0
commit 377be64388
16 changed files with 431 additions and 35 deletions

View File

@ -13,6 +13,9 @@ file(GLOB_RECURSE SRC_LIST "source/*.cpp")
include_directories("source") include_directories("source")
include_directories("source/ATP") include_directories("source/ATP")
include_directories("source/Logger") include_directories("source/Logger")
include_directories("source/ZZ_SDK")
include_directories("source/Settings")
include_directories("source/Thread")
add_executable( TowerOptoSifAndSpectral add_executable( TowerOptoSifAndSpectral
main.cpp main.cpp

View File

@ -2,7 +2,7 @@
#include "ATPControl_Serial_QT.h" #include "ATPControl_Serial_QT.h"
#include "Logger.h" #include "Logger.h"
using namespace std; using namespace std;
#pragma once
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -12,6 +12,7 @@ int main(int argc, char *argv[])
//QT_LOG::ZZ_InitLogger(QCoreApplication::applicationDirPath() + "/Log/"); //QT_LOG::ZZ_InitLogger(QCoreApplication::applicationDirPath() + "/Log/");
QString qstrTest="This is a test message 2"; QString qstrTest="This is a test message 2";
qDebug() << qstrTest; qDebug() << qstrTest;
cout << "This is a test message";
//////////////////////////////////////////////////////////////////////////test //////////////////////////////////////////////////////////////////////////test
ZZ_ATPControl_Serial_Qt m_ctrlATP; ZZ_ATPControl_Serial_Qt m_ctrlATP;
QByteArray qbTest; QByteArray qbTest;

View File

@ -1,5 +1,6 @@
#include "pch.h" #include "pch.h"
#include "ATPControl_Serial_QT.h" #include "ATPControl_Serial_QT.h"
#include "ZZ_Math_HDRONLY.h"
ZZ_ATPControl_Serial_Qt::ZZ_ATPControl_Serial_Qt() ZZ_ATPControl_Serial_Qt::ZZ_ATPControl_Serial_Qt()
{ {
@ -62,17 +63,47 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceInfo()
qbSend.clear(); qbSend.clear();
qbRecv.clear(); qbRecv.clear();
qbSend.append(GET_PN_NUMBER); qbSend.append(GET_PN_NUMBER);
SendCommand(qbSend); int iRes = SendCommand(qbSend);
RecvData(qbRecv); if (iRes != 0)
ParseData(qbRecv); {
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
iRes = RecvData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
iRes = ParseData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
m_adiDeviceInfo.strPN = qbRecv.data(); m_adiDeviceInfo.strPN = qbRecv.data();
qbSend.clear(); qbSend.clear();
qbRecv.clear(); qbRecv.clear();
qbSend.append(GET_SN_NUMBER); qbSend.append(GET_SN_NUMBER);
SendCommand(qbSend); iRes = SendCommand(qbSend);
RecvData(qbRecv); if (iRes != 0)
ParseData(qbRecv); {
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
iRes = RecvData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
iRes = ParseData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceInfo Failed,Communication error.Exit Code:1";
return 1;
}
m_adiDeviceInfo.strSN = qbRecv.data(); m_adiDeviceInfo.strSN = qbRecv.data();
@ -86,22 +117,62 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute()
qbSend.clear(); qbSend.clear();
qbRecv.clear(); qbRecv.clear();
qbSend.append(GET_MIN_INTEGRATION_TIME); qbSend.append(GET_MIN_INTEGRATION_TIME);
SendCommand(qbSend); int iRes = SendCommand(qbSend);
RecvData(qbRecv); if (iRes != 0)
ParseData(qbRecv); {
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = RecvData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = ParseData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
m_adaDeviceAttr.iMinIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256; m_adaDeviceAttr.iMinIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256;
qbSend.clear(); qbSend.clear();
qbRecv.clear(); qbRecv.clear();
qbSend.append(GET_MAX_INTEGRATION_TIME); qbSend.append(GET_MAX_INTEGRATION_TIME);
SendCommand(qbSend); iRes = SendCommand(qbSend);
RecvData(qbRecv); if (iRes != 0)
ParseData(qbRecv); {
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = RecvData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = ParseData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
m_adaDeviceAttr.iMaxIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256; m_adaDeviceAttr.iMaxIntegrationTime = (ZZ_U8)qbRecv[1] + (ZZ_U8)qbRecv[0] * 256;
SetExposureTime(m_adaDeviceAttr.iMinIntegrationTime); iRes = SetExposureTime(m_adaDeviceAttr.iMinIntegrationTime);
SingleShot(m_adaDeviceAttr.iPixels); if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Call SetExposureTime error.Exit Code:2";
return 2;
}
iRes = SingleShot(m_adaDeviceAttr.iPixels);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Call SingleShot error.Exit Code:3";
return 3;
}
qbSend.clear(); qbSend.clear();
@ -110,15 +181,30 @@ int ZZ_ATPControl_Serial_Qt::GetDeviceAttribute()
qbSend.resize(3); qbSend.resize(3);
qbSend[1] = 0x00; qbSend[1] = 0x00;
qbSend[2] = 0x01; qbSend[2] = 0x01;
SendCommand(qbSend); iRes = SendCommand(qbSend);
RecvData(qbRecv); if (iRes != 0)
ParseData(qbRecv); {
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = RecvData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
iRes = ParseData(qbRecv);
if (iRes != 0)
{
qDebug() << "Err:GetDeviceAttribute Failed,Communication error.Exit Code:1";
return 1;
}
float fWaveLengthCoef[4]; float fWaveLengthCoef[4];
memcpy(fWaveLengthCoef, qbRecv.data()+16, 4 * sizeof(float)); memcpy(fWaveLengthCoef, qbRecv.data()+16, 4 * sizeof(float));
// for () for (int i=0;i< m_adaDeviceAttr.iPixels;i++)
// { {
// } m_adaDeviceAttr.fWaveLength[i] = fWaveLengthCoef[0] * i*i*i + fWaveLengthCoef[1] * i*i + fWaveLengthCoef[2] * i + fWaveLengthCoef[3];
}
return 0; return 0;
} }
@ -144,7 +230,7 @@ int ZZ_ATPControl_Serial_Qt::SendCommand(QByteArray qbCommand)
qint64 qi64Write= m_pSerialPort->write(qbSend); qint64 qi64Write= m_pSerialPort->write(qbSend);
if (qi64Write != qbSend.size()) if (qi64Write != qbSend.size())
{ {
qDebug() << "Err:write Failed.Exit Code:1"; qDebug() << "Err:write Failed.Exit Code:1"<< qi64Write;
return 1; return 1;
} }
@ -165,7 +251,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
if (iCounter > 10) if (iCounter > 10)
{ {
qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1"<<qbData.size(); qDebug() << "Err:RecvData Failed,Not Enough Data.Exit Code:1"<< qbData.size();
return 1; return 1;
} }
iCounter++; iCounter++;
@ -173,7 +259,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
if ((ZZ_U8)qbData[0] != (ZZ_U8)0xaa || (ZZ_U8)qbData[1] != (ZZ_U8)0x55) if ((ZZ_U8)qbData[0] != (ZZ_U8)0xaa || (ZZ_U8)qbData[1] != (ZZ_U8)0x55)
{ {
qDebug() << "Err:RecvData Failed,Wrong Header.Exit Code:2" << qbData.size(); qDebug() << "Err:RecvData Failed,Wrong Header.Exit Code:2" << qbData.size();
return 2; return 2;
} }
@ -186,7 +272,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
if (iCounter > 100) if (iCounter > 100)
{ {
qDebug() << "Err:RecvData Failed,Incomplete Data.Exit Code:3" << qbData.size(); qDebug() << "Err:RecvData Failed,Incomplete Data.Exit Code:3" << qbData.size();
return 3; return 3;
} }
iCounter++; iCounter++;
@ -206,7 +292,7 @@ int ZZ_ATPControl_Serial_Qt::RecvData(QByteArray &qbData)
ZZ_U8 ucTemp = qbData[qbData.size() - 1]; ZZ_U8 ucTemp = qbData[qbData.size() - 1];
if ((ZZ_U8)usCheckSum != ucTemp) if ((ZZ_U8)usCheckSum != ucTemp)
{ {
qDebug() << "Err:RecvData Failed,Incorrect Check Sum.Exit Code:4" << qbData.size(); qDebug() << "Err:RecvData Failed,Incorrect Check Sum.Exit Code:4" << qbData.size();
qbData.clear(); qbData.clear();
return 4; return 4;
} }
@ -218,7 +304,7 @@ int ZZ_ATPControl_Serial_Qt::ParseData(QByteArray &qbData)
{ {
if (qbData.size() < 6) if (qbData.size() < 6)
{ {
qDebug() << "Err:ParseData Failed,Not Enough Data.Exit Code:1" << qbData.size(); qDebug() << "Err:ParseData Failed,Not Enough Data.Exit Code:1" << qbData.size();
return 1; return 1;
} }
qbData.remove(0, 5); qbData.remove(0, 5);
@ -228,6 +314,136 @@ int ZZ_ATPControl_Serial_Qt::ParseData(QByteArray &qbData)
int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float &fPredictedExposureTime) int ZZ_ATPControl_Serial_Qt::PerformAutoExposure(float fMinScaleFactor, float fMaxScaleFactor, float &fPredictedExposureTime)
{ {
using namespace ZZ_MATH;
int iDeviceDepth = 65535;
bool bFlagIsOverTrying = false;
bool bFlagIsLowerMinExposureTime = false;
bool bFlagIsOverMaxExposureTime = false;
bool bFlagIsAutoExposureOK = false;
bool bFlagIsAutoExposureFailed = false;
bool bIsValueOverflow = false;
bool bIsLastValueOverflow = false;
float fExposureTime = 0;
float fTempExposureTime = 0;
double fLastExposureTime = 0.1;
int iRepeatCount = 0;
int iRes = SetExposureTime(2000);//need change to load from files
if (iRes != 0)
{
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:1";
return 1;
}
while (!bFlagIsAutoExposureOK && !bFlagIsAutoExposureFailed)
{
ATPDataFrame dfTemp;
if (iRepeatCount++ > 30)
{
bFlagIsAutoExposureFailed = true;
bFlagIsOverTrying = true;
break;
}
fExposureTime = (float)m_adaDeviceAttr.iMinIntegrationTime;
fTempExposureTime = fExposureTime;
iRes = SingleShot(dfTemp);
if (iRes != 0)
{
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:2";
return 2;
}
HeapSort(dfTemp.usData, m_adaDeviceAttr.iPixels);
double dSum = 0;
int iCount = m_adaDeviceAttr.iPixels / 100;
for (int i = 0; i < iCount; i++)
{
dSum += dfTemp.usData[i];
}
double dTemp = dSum / iCount;
if (dTemp >= iDeviceDepth * 0.99)
{
bIsValueOverflow = true;
if (!bIsLastValueOverflow)
{
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
}
else
{
fExposureTime = fExposureTime / 2;
}
}
else if (iDeviceDepth * fMaxScaleFactor >= dTemp && dTemp >= iDeviceDepth * fMinScaleFactor)
{
bFlagIsAutoExposureOK = 1;
}
else if (dTemp > iDeviceDepth * fMaxScaleFactor)
{
bIsValueOverflow = true;
if (!bIsLastValueOverflow)
{
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
}
else
{
fExposureTime = fExposureTime * 3 / 4;
}
}
else if (dTemp < iDeviceDepth * fMinScaleFactor)
{
bIsValueOverflow = false;
if (bIsLastValueOverflow)
{
fExposureTime = (float)(fLastExposureTime + fExposureTime) / 2;
}
else
{
double dFactor;
dFactor = dTemp / (iDeviceDepth * fMaxScaleFactor);
fExposureTime = (float)(fExposureTime / dFactor);
}
if (/*fExposureTime > 100 || */fExposureTime < 10)
{
bFlagIsAutoExposureOK = false;
bFlagIsAutoExposureFailed = true;
bFlagIsLowerMinExposureTime = true;
}
}
bIsLastValueOverflow = bIsValueOverflow;
fLastExposureTime = fTempExposureTime;
if (fExposureTime > 13000)
{
bFlagIsAutoExposureOK = false;
bFlagIsAutoExposureFailed = true;
fPredictedExposureTime = 13000;
iRes = SetExposureTime(13000);
if (iRes != 0)
{
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:3";
return 3;
}
bFlagIsOverMaxExposureTime = true;
break;
}
iRes = SetExposureTime((int)fExposureTime);
if (iRes != 0)
{
qDebug() << "Err:PerformAutoExposure Failed.Exit Code:4";
return 3;
}
}
fPredictedExposureTime = fExposureTime;
return 0; return 0;
} }
@ -279,11 +495,8 @@ int ZZ_ATPControl_Serial_Qt::SingleShot(ATPDataFrame &dfData)
{ {
int iDataSizeInPixel = (qbRecv.size() - 1) / 2; int iDataSizeInPixel = (qbRecv.size() - 1) / 2;
memcpy(dfData.usData, qbRecv.data() + 1, iDataSizeInPixel * 2); memcpy(dfData.usData, qbRecv.data() + 1, iDataSizeInPixel * 2);
}
//int isize = qbRecv.size(); }
//m_adaDeviceAttr.iPixels = isize / 2;
return 0; return 0;
} }

View File

@ -13,9 +13,6 @@ public:
ZZ_ATPControl_Serial_Qt(); ZZ_ATPControl_Serial_Qt();
virtual ~ZZ_ATPControl_Serial_Qt(); virtual ~ZZ_ATPControl_Serial_Qt();
//////////////////////////////////////////////////////////////////////////shutter control stub code s
int SetExtShutter(int iShutterA,int iShutterB); //0:close 1:open
//////////////////////////////////////////////////////////////////////////shutter control stub code e
public: public:
int SetBaudRate(int iBaud); int SetBaudRate(int iBaud);
@ -28,6 +25,7 @@ public:
int SingleShotDeducted(ATPDataFrame &dfData); int SingleShotDeducted(ATPDataFrame &dfData);
int SetExposureTime(int iExposureTimeInMS); int SetExposureTime(int iExposureTimeInMS);
int GetExposureTime(int &iExposureTimeInMS);
//int GetWaveLength(float *pfWaveLength); //int GetWaveLength(float *pfWaveLength);
int GetDeviceInfo(); int GetDeviceInfo();
@ -49,6 +47,10 @@ private:
//ATP //ATP
ATPDeviceInfo m_adiDeviceInfo; ATPDeviceInfo m_adiDeviceInfo;
ATPDeviceAttribute m_adaDeviceAttr; ATPDeviceAttribute m_adaDeviceAttr;
//////////////////////////////////////////////////////////////////////////shutter control stub code s
int SetExtShutter(int iShutterA, int iShutterB); //0:close 1:open
//////////////////////////////////////////////////////////////////////////shutter control stub code e
int SendCommand(QByteArray qbCommand); int SendCommand(QByteArray qbCommand);
int RecvData(QByteArray &qbData); int RecvData(QByteArray &qbData);
int ParseData(QByteArray &qbData); int ParseData(QByteArray &qbData);

View File

View File

@ -0,0 +1 @@
#pragma once

View File

@ -39,6 +39,7 @@ namespace ZZ_MISCDEF
const int SET_GPIO = 0x61; const int SET_GPIO = 0x61;
//const int SYNCHRONIZATION_GET_DARK = 0x23 //const int SYNCHRONIZATION_GET_DARK = 0x23
//////////////////////////////////////////////////////////////////////////device
enum Model enum Model
{ {
ATP1010 = 0, ATP1010 = 0,
@ -67,6 +68,37 @@ namespace ZZ_MISCDEF
float fWaveLength[4096]; float fWaveLength[4096];
}ATPDeviceAttribute; }ATPDeviceAttribute;
//////////////////////////////////////////////////////////////////////////config file
}
namespace ZZ_DATAFILE
{
typedef struct tagEnvironmentalContext
{
}EnvironmentalContext;
typedef struct tagIS1Information
{
}IS1Info;
typedef struct tagISIFInformation
{
}ISIFInfo;
typedef struct tagATPDataHeader
{
}ATPDataHeader;
} }
} }

View File

@ -0,0 +1,25 @@
#include "SystemConfigger.h"
ZZ_SysConfigger::ZZ_SysConfigger(QObject *parent /*= nullptr*/)
{
m_qstrFilePath = QCoreApplication::applicationDirPath()+ "/Settings/DeviceSettings.ini";
}
ZZ_SysConfigger::~ZZ_SysConfigger()
{
}
int ZZ_SysConfigger::LoadSettings_IS1()
{
return 0;
}
int ZZ_SysConfigger::LoadSettings_iSIF()
{
return 0;
}
int ZZ_SysConfigger::LoadSettings_System()
{
return 0;
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "pch.h"
class ZZ_SysConfigger :public QObject
{
Q_OBJECT
public:
ZZ_SysConfigger(QObject *parent = nullptr);
virtual ~ZZ_SysConfigger();
public:
int LoadSettings_IS1();
int LoadSettings_iSIF();
int LoadSettings_System();
private:
QString m_qstrFilePath;
};

View File

View File

@ -0,0 +1 @@
#pragma once

View File

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,12 @@
#pragma once
#include "pch.h"
class ZZ_iSIFControlThread :public QObject
{
Q_OBJECT
public:
ZZ_iSIFControlThread(QObject* parent = nullptr);
~ZZ_iSIFControlThread();
};

View File

View File

@ -0,0 +1,84 @@
#pragma once
namespace ZZ_MATH
{
template<typename T>
void MinHeapify(T*arry, int size, int element)
{
int lchild = element * 2 + 1, rchild = lchild + 1;
while (rchild < size)
{
if (arry[element] <= arry[lchild] && arry[element] <= arry[rchild])
{
return;
}
if (arry[lchild] <= arry[rchild])
{
std::swap(arry[element], arry[lchild]);
element = lchild;
}
else
{
std::swap(arry[element], arry[rchild]);
element = rchild;
}
lchild = element * 2 + 1;
rchild = lchild + 1;
}
if (lchild < size&&arry[lchild] < arry[element])
{
std::swap(arry[lchild], arry[element]);
}
return;
}
template<typename T>
void MaxHeapify(T*arry, int size, int element)
{
int lchild = element * 2 + 1, rchild = lchild + 1;
while (rchild < size)
{
if (arry[element] >= arry[lchild] && arry[element] >= arry[rchild])
{
return;
}
if (arry[lchild] >= arry[rchild])
{
std::swap(arry[element], arry[lchild]);
element = lchild;
}
else
{
std::swap(arry[element], arry[rchild]);
element = rchild;
}
lchild = element * 2 + 1;
rchild = lchild + 1;
}
if (lchild<size&&arry[lchild]>arry[element])
{
std::swap(arry[lchild], arry[element]);
}
return;
}
template<typename T>
void HeapSort(T*arry, int size)
{
int i;
for (i = size - 1; i >= 0; i--)
{
MinHeapify(arry, size, i);
}
while (size > 0)
{
std::swap(arry[size - 1], arry[0]);
size--;
MinHeapify(arry, size, 0);
}
return;
}
}