Compare commits
9 Commits
09d224075a
...
2e158431e7
Author | SHA1 | Date | |
---|---|---|---|
2e158431e7 | |||
6473a1f4ce | |||
cc76d62ded | |||
e620c87ecf | |||
47002ad894 | |||
5337a40837 | |||
6b78db5bc3 | |||
73f9b00b02 | |||
6fc2680a1c |
@ -26,7 +26,7 @@
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
|
||||
template <typename T, size_t BlockSize = 16368000>
|
||||
template <typename T, size_t BlockSize = 409200000>
|
||||
class MemoryPool
|
||||
{
|
||||
public:
|
||||
|
@ -34,9 +34,14 @@ public:
|
||||
bool getspatialBin(int &spatialBin);
|
||||
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
|
||||
bool getEffectiveWindowRoi(int &width, int &offsetx);
|
||||
bool getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString);//spectralBinString = "bin1"或者”bin2“
|
||||
bool getGainOffset(float &gain, float &offset);
|
||||
bool getGainOffsetOfSpectralBin1(float &gain, float &offset);
|
||||
bool getSN(QString &SN);
|
||||
|
||||
bool getBufferPolicy(int &bufferPolicy);
|
||||
bool getAcqBufferSize(int &acqBufferSize);
|
||||
|
||||
bool createConfigFile();
|
||||
bool updateConfigFile();
|
||||
|
||||
|
@ -67,6 +67,7 @@ public slots:
|
||||
|
||||
void sendXimeaImageStatus(int ximeaImageStatus);
|
||||
void sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime);
|
||||
void sendXimeaBinState(int spatialBin, int spectralBin);
|
||||
void sendXimeaImageFrameRate(double frameRate);
|
||||
void sendCopyFileStatus(int fileStatus);
|
||||
};
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <exception>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
@ -62,7 +64,7 @@ public:
|
||||
DataBuffer();
|
||||
~DataBuffer();
|
||||
|
||||
unsigned short data[425600];//304*1400=425600,为了兼容所有设置spectral bin和spatial bin
|
||||
unsigned short data[41040000];//1368*300*100=41040000,为了兼容所有设置spectral bin和spatial bin
|
||||
|
||||
private:
|
||||
|
||||
@ -98,18 +100,22 @@ Q_OBJECT
|
||||
|
||||
public:
|
||||
WriteData2Disk();
|
||||
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||||
void setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
|
||||
|
||||
private:
|
||||
queue<DataBuffer *> * m_q;
|
||||
queue<int> * m_qFrameCounter;
|
||||
QString m_QbaseFileName;
|
||||
int m_iFrameSizeInByte;
|
||||
int m_iNumber_WriteDisk;
|
||||
MemoryPool<DataBuffer> * m_pool;
|
||||
bool isExitWriteData2Disk;
|
||||
|
||||
rgbImage * m_rgbImage;
|
||||
|
||||
public slots:
|
||||
void write2Disk();
|
||||
void exitWriteData2Disk();
|
||||
|
||||
signals:
|
||||
};
|
||||
@ -139,6 +145,7 @@ public:
|
||||
|
||||
void stopRecord();
|
||||
int getFrameCounter();
|
||||
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
|
||||
|
||||
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
|
||||
|
||||
@ -148,12 +155,16 @@ private:
|
||||
int m_iImagerState;
|
||||
int m_iImagerStateTemp;
|
||||
|
||||
int m_iOffsetyOfSpectralBin1, m_iOffsetyOfSpectralBin2;
|
||||
int m_iHeightOfSpectralBin1, m_iHeightOfSpectralBin2;
|
||||
|
||||
QThread * m_recordTempThread;
|
||||
RecordXimeaTemperature * m_ximeaTemperature;
|
||||
|
||||
QThread * writeData2DiskThread;
|
||||
WriteData2Disk * writeData2Disk;
|
||||
queue<DataBuffer *> * q;
|
||||
queue<int> * m_qFrameCounter;
|
||||
MemoryPool<DataBuffer> * m_pool;
|
||||
|
||||
QString m_baseFileName;
|
||||
@ -170,23 +181,10 @@ private:
|
||||
|
||||
void processXiApiErrorCodes(int xiApiErrorCodes);
|
||||
|
||||
inline double getSbgTime(double TimeDifferenceBetweensOSAndSbg)
|
||||
inline double getSbgTime(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
|
||||
{
|
||||
struct timespec systemTime;
|
||||
clock_gettime(CLOCK_REALTIME,&systemTime);
|
||||
tm systemTime_rili;
|
||||
localtime_r(&systemTime.tv_sec, &systemTime_rili);
|
||||
|
||||
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
|
||||
double nanosecondSystem=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
|
||||
|
||||
|
||||
// printf("\n");
|
||||
// printf("XimeaImager::getSbgTime------系统时间纳秒%d\n", systemTime.tv_nsec);
|
||||
// printf("XimeaImager::getSbgTime------系统时间(未偏移)%f\n", nanosecondSystem);
|
||||
// printf("XimeaImager::getSbgTime------系统时间(偏移)%f\n", nanosecondSystem-TimeDifferenceBetweensOSAndSbg);
|
||||
|
||||
return nanosecondSystem-TimeDifferenceBetweensOSAndSbg;
|
||||
double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
|
||||
return ximeaTime + timeDifferenceBetweenSbgAndXimea;
|
||||
}
|
||||
|
||||
Configfile m_configfile;
|
||||
@ -197,6 +195,7 @@ public slots:
|
||||
void openImger();
|
||||
void closeImger();
|
||||
|
||||
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
|
||||
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
|
||||
|
||||
signals:
|
||||
@ -208,5 +207,6 @@ signals:
|
||||
|
||||
void autoExposeMaxValueOfOneFrame(int, double);
|
||||
void frameRateSignal(double);
|
||||
void binSignal(int, int);
|
||||
};
|
||||
#endif // XIMEAIMAGER_H
|
||||
|
@ -166,6 +166,28 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
|
||||
if(!(spectralArgument.lookupValue("height", height)
|
||||
&& spectralArgument.lookupValue("offsety", offsety)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getGainOffset(float &gain, float &offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
@ -206,6 +228,35 @@ bool Configfile::getGainOffset(float &gain, float &offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getGainOffsetOfSpectralBin1(float &gain, float &offset)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
|
||||
try
|
||||
{
|
||||
const Setting &gainOffset = root["gainOffset"];
|
||||
int count = gainOffset.getLength();
|
||||
|
||||
string spectralBinString = "spectralBin1";
|
||||
|
||||
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
|
||||
string name = gainOffsetSetting.getName();
|
||||
|
||||
if(!(gainOffsetSetting.lookupValue("gain", gain)
|
||||
&& gainOffsetSetting.lookupValue("offset", offset)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
// Ignore.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getSN(QString &SN)
|
||||
{
|
||||
try
|
||||
@ -222,6 +273,50 @@ bool Configfile::getSN(QString &SN)
|
||||
}
|
||||
}
|
||||
|
||||
bool Configfile::getBufferPolicy(int &bufferPolicy)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
const Setting &ximeadll = root["ximeadll"];
|
||||
|
||||
try
|
||||
{
|
||||
if(!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::getAcqBufferSize(int &acqBufferSize)
|
||||
{
|
||||
const Setting& root = cfg.getRoot();
|
||||
const Setting &ximeadll = root["ximeadll"];
|
||||
|
||||
try
|
||||
{
|
||||
if(!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
|
||||
))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(const SettingNotFoundException &nfex)
|
||||
{
|
||||
cerr << "No 'spectralBin' setting in configuration file." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configfile::createConfigFile()
|
||||
{
|
||||
using namespace std;
|
||||
@ -279,6 +374,11 @@ bool Configfile::createConfigFile()
|
||||
gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
|
||||
|
||||
|
||||
Setting &ximeadll = root.add("ximeadll", Setting::TypeGroup);
|
||||
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
|
||||
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
|
||||
|
||||
|
||||
// Write out the new configuration.
|
||||
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
|
||||
try
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::cout<<"ximeaAirborneSystem 版本:"<< "35." <<std::endl;
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
//UdpServer* x=new UdpServer();
|
||||
|
@ -8,16 +8,16 @@ UdpServer::UdpServer()
|
||||
m_udpSocket->bind(45454, QUdpSocket::ShareAddress);
|
||||
connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));
|
||||
|
||||
m_RecordSbgThread=new QThread();
|
||||
m_sbgRecorder=new sbgtc::SbgRecorder();
|
||||
m_sbgRecorder->moveToThread(m_RecordSbgThread);
|
||||
m_RecordSbgThread->start();
|
||||
|
||||
m_RecordThread=new QThread();
|
||||
m_imager=new XimeaImager();
|
||||
m_imager->moveToThread(m_RecordThread);
|
||||
m_RecordThread->start(QThread::HighestPriority);
|
||||
|
||||
m_RecordSbgThread=new QThread();
|
||||
m_sbgRecorder=new sbgtc::SbgRecorder();
|
||||
m_sbgRecorder->moveToThread(m_RecordSbgThread);
|
||||
m_RecordSbgThread->start();
|
||||
|
||||
m_CopyFileThread=new QThread();
|
||||
m_copyFile=new FileOperation();
|
||||
m_copyFile->moveToThread(m_CopyFileThread);
|
||||
@ -51,6 +51,7 @@ UdpServer::UdpServer()
|
||||
|
||||
connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int)));
|
||||
connect(m_imager, SIGNAL(autoExposeMaxValueOfOneFrame(int, double)),this, SLOT(sendXimeaAutoExposeMaxValueOfOneFrame(int, double)));
|
||||
connect(m_imager, SIGNAL(binSignal(int, int)),this, SLOT(sendXimeaBinState(int, int)));
|
||||
connect(m_imager, SIGNAL(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
|
||||
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
|
||||
|
||||
@ -59,10 +60,10 @@ UdpServer::UdpServer()
|
||||
//当软件不正常关闭并且重启后,通知其他psdk程序
|
||||
m_clientIpAddress=QHostAddress(QHostAddress::LocalHost);
|
||||
sendSerialPortStatus(0);
|
||||
sendXimeaImageStatus(0);
|
||||
sendXimeaImageStatus(100);
|
||||
sendCopyFileStatus(0);
|
||||
|
||||
|
||||
system("sudo gpio write 10 0");
|
||||
|
||||
|
||||
std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl;
|
||||
@ -309,6 +310,18 @@ void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOn
|
||||
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||
}
|
||||
|
||||
void UdpServer::sendXimeaBinState(int spatialBin, int spectralBin)
|
||||
{
|
||||
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
|
||||
|
||||
QByteArray datagram2send;
|
||||
|
||||
QString status = "bin," + QString::number(spatialBin) + "," + QString::number(spectralBin);
|
||||
|
||||
datagram2send.operator =(status.toStdString().c_str());
|
||||
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
|
||||
}
|
||||
|
||||
void UdpServer::sendXimeaImageFrameRate(double frameRate)
|
||||
{
|
||||
// std::cout<<"UdpServer::sendXimeaImageFrameRate---------------------:"<< ximeaImageStatus <<std::endl;
|
||||
|
@ -7,13 +7,27 @@ XimeaImager::XimeaImager()
|
||||
m_iFrameCounter=0;
|
||||
m_iImagerState=100;
|
||||
|
||||
//connect(this, SIGNAL(recordFinished()),this, SLOT());
|
||||
|
||||
QString ximeaCfgFile = "/media/nvme/300TC/config/ximea.cfg";
|
||||
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
|
||||
if(!m_configfile.isConfigfileExist())
|
||||
m_configfile.createConfigFile();
|
||||
m_configfile.parseConfigfile();
|
||||
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin1, m_iHeightOfSpectralBin1, "bin1");
|
||||
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin2, m_iHeightOfSpectralBin2, "bin2");
|
||||
//检查 ximea.cfg 是否满足要求
|
||||
if(m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2!"<<std::endl;
|
||||
}
|
||||
if(m_iOffsetyOfSpectralBin2 % 2 != 0)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:m_iOffsetyOfSpectralBin2 不是 2 的倍数,ximea相机不接受!"<<std::endl;
|
||||
}
|
||||
if(m_iHeightOfSpectralBin1 < m_iHeightOfSpectralBin2 * 2)
|
||||
{
|
||||
std::cout<<"ximea.cfg 错误:bin1 波段数小于 bin2 波段数的 2 倍!"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
m_recordTempThread=new QThread();
|
||||
m_ximeaTemperature = new RecordXimeaTemperature(&m_imager);
|
||||
@ -30,6 +44,7 @@ XimeaImager::XimeaImager()
|
||||
|
||||
m_pool = new MemoryPool<DataBuffer>;
|
||||
q = new queue<DataBuffer *>;
|
||||
m_qFrameCounter = new queue<int>;
|
||||
|
||||
m_rgbImage = new rgbImage();
|
||||
}
|
||||
@ -63,10 +78,14 @@ void XimeaImager::openImger()
|
||||
{
|
||||
bool haha = m_imager.setSpectralBin(spectralBin);
|
||||
bool haha2 = m_imager.setSpatialBin(spatialBin);
|
||||
|
||||
emit binSignal(spatialBin, spectralBin);
|
||||
std::cout<<"spectralBin:"<< spectralBin <<std::endl;
|
||||
std::cout<<"spatialBin:"<< spatialBin <<std::endl;
|
||||
}
|
||||
|
||||
float gain, offset;//用于生成头文件中的波长信息
|
||||
ret = m_configfile.getGainOffset(gain, offset);
|
||||
ret = m_configfile.getGainOffsetOfSpectralBin1(gain, offset);
|
||||
if (ret)
|
||||
{
|
||||
m_imager.setGainOffset(gain, offset);
|
||||
@ -80,6 +99,7 @@ void XimeaImager::openImger()
|
||||
m_rgbImage->SetRgbImageWidthAndHeight(height, width, 20);
|
||||
std::cout<<"height:"<< height <<std::endl;
|
||||
std::cout<<"width:"<< width <<std::endl;
|
||||
std::cout<<"每帧字节数:"<< width * height * 2 <<std::endl;
|
||||
}
|
||||
|
||||
// int width_roi = 0, offsetx_roi = 0;
|
||||
@ -89,6 +109,18 @@ void XimeaImager::openImger()
|
||||
// m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi);
|
||||
// }
|
||||
|
||||
int bufferPolicy, acqBufferSize;
|
||||
ret1 = m_configfile.getBufferPolicy(bufferPolicy);
|
||||
if (ret1)
|
||||
{
|
||||
m_imager.setBufferPolicy(bufferPolicy);
|
||||
}
|
||||
ret1 = m_configfile.getAcqBufferSize(acqBufferSize);
|
||||
if (ret1)
|
||||
{
|
||||
m_imager.setAcqBufferSize(acqBufferSize);
|
||||
}
|
||||
|
||||
setFramerate(100);
|
||||
|
||||
//经验证:frameSizeManual和frameSizeAuto相等
|
||||
@ -461,6 +493,34 @@ int XimeaImager::getImagerState() const
|
||||
return m_iImagerState;
|
||||
}
|
||||
|
||||
double XimeaImager::calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * image, double timeDifferenceBetweenSbgAndOS)
|
||||
{
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndOS: %f s\n", timeDifferenceBetweenSbgAndOS);
|
||||
|
||||
double ximeaTime=image->tsSec + image->tsUSec/1000000;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--ximeaTime: %f s\n", ximeaTime);
|
||||
|
||||
//获取系统时间(纳秒)
|
||||
struct timespec systemTime;
|
||||
clock_gettime(CLOCK_REALTIME,&systemTime);
|
||||
tm systemTime_rili;
|
||||
localtime_r(&systemTime.tv_sec, &systemTime_rili);
|
||||
|
||||
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
|
||||
double timeOS=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--osTime: %f s\n", timeOS);
|
||||
|
||||
|
||||
//计算系统时间和gps时间之间的差距
|
||||
double timeDifferenceBetweenSbgAndximea = timeOS - timeDifferenceBetweenSbgAndOS - ximeaTime;
|
||||
|
||||
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndximea: %f s\n", timeDifferenceBetweenSbgAndximea);
|
||||
|
||||
return timeDifferenceBetweenSbgAndximea;
|
||||
}
|
||||
|
||||
void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName)
|
||||
{
|
||||
m_ximeaTemperature->stopRecordTemperature();//开始采集影像前,停止获取相机的温度,以免降低帧率;
|
||||
@ -487,17 +547,24 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
|
||||
m_baseFileName=baseFileName;
|
||||
|
||||
|
||||
QString timesFileName=m_baseFileName+".times";
|
||||
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
||||
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
|
||||
|
||||
using namespace std;
|
||||
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
|
||||
|
||||
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, m_pool, m_rgbImage);
|
||||
int number_WriteDisk = 100;
|
||||
writeData2Disk->setParm(q, m_qFrameCounter,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
|
||||
emit startWriteDiskSignal();
|
||||
|
||||
int indexofbuff;
|
||||
DataBuffer * buffer;
|
||||
|
||||
QString timesFileName=m_baseFileName+".times";
|
||||
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
|
||||
// ofstream timesFile(timesFileName.toStdString());
|
||||
double timeDifferenceBetweenSbgAndXimea;
|
||||
double * sbgTimeBuffer = new double[number_WriteDisk];
|
||||
|
||||
m_imager.start();
|
||||
struct timeval timeStart, timeEnd;
|
||||
double runTime=0;
|
||||
@ -505,69 +572,89 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
|
||||
while (m_bRecordControl)
|
||||
{
|
||||
unsigned short *x=m_imager.get_frame(m_buffer);
|
||||
|
||||
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
|
||||
// fwrite(m_imager.m_image.bp,static_cast<int>(m_imager.m_image.bp_size),1,hFile);
|
||||
//fflush(hFile);//只保证了将IO缓冲写入系统缓冲中,使IO读操作能成功,但系统什么时候写入磁盘,由系统决定,一般是达到一定量时系统他就写入磁盘。
|
||||
//sync();//强制系统将系统文件缓冲的内容写入磁盘
|
||||
|
||||
|
||||
|
||||
r_qtx.lock();
|
||||
DataBuffer * buffer = m_pool->newElement();
|
||||
r_qtx.unlock();
|
||||
// m_pool->construct(buffer);
|
||||
|
||||
// memcpy(buffer->data,(unsigned short *)m_imager.m_image.bp,m_iFrameSizeInByte/2);
|
||||
memcpy((void *)buffer->data,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||
|
||||
r_qtx.lock();
|
||||
q->push(buffer);
|
||||
r_qtx.unlock();//
|
||||
|
||||
// std::cout<<"XimeaImager::startRecord,队列长度为:"<< q->size() <<std::endl;//
|
||||
|
||||
// fwrite(buffer,1,m_iFrameSizeInByte,hFile);
|
||||
|
||||
m_iFrameCounter+=1;
|
||||
|
||||
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
|
||||
if (m_iFrameCounter == 1)
|
||||
{
|
||||
timeDifferenceBetweenSbgAndXimea = calculateTimeDifferenceBetweenSbgAndximea(&m_imager.m_image, TimeDifferenceBetweensOSAndSbg);
|
||||
}
|
||||
|
||||
fprintf(hHimesFile,"%f\n",sbgTime);
|
||||
//fwrite(&sbgTime,sizeof(double),1,hHimesFile);
|
||||
indexofbuff = m_iFrameCounter % number_WriteDisk;
|
||||
|
||||
// timesFileHandle << sbgTime << "\n";
|
||||
// std::cout<<"XimeaImager::startRecord---std::cout: "<<sbgTime<<std::endl;
|
||||
if (indexofbuff == 1)
|
||||
{
|
||||
r_qtx.lock();
|
||||
buffer = m_pool->newElement();
|
||||
r_qtx.unlock();
|
||||
}
|
||||
|
||||
// unsigned char pixel = *(unsigned char*)image.bp;//Default value: XI_MONO8
|
||||
// unsigned short pixel =*(unsigned short*)image.bp;//XI_RAW16
|
||||
// printf("Image %d (%dx%d) received from camera. First pixel value: %d\n", m_iFrameCounter, (int)image.width, (int)image.height, pixel);
|
||||
if (indexofbuff == 0)
|
||||
{
|
||||
memcpy((void *)buffer->data + (number_WriteDisk - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||
sbgTimeBuffer[number_WriteDisk - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy((void *)buffer->data + (indexofbuff - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
|
||||
sbgTimeBuffer[indexofbuff - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
|
||||
}
|
||||
|
||||
if (indexofbuff == 0)
|
||||
{
|
||||
r_qtx.lock();
|
||||
q->push(buffer);
|
||||
m_qFrameCounter->push(number_WriteDisk);
|
||||
r_qtx.unlock();
|
||||
|
||||
for (int i = 0; i < number_WriteDisk; ++i)
|
||||
{
|
||||
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (indexofbuff != 0)
|
||||
{
|
||||
r_qtx.lock();
|
||||
q->push(buffer);
|
||||
m_qFrameCounter->push(indexofbuff);
|
||||
r_qtx.unlock();
|
||||
|
||||
for (int i = 0; i < indexofbuff; ++i)
|
||||
{
|
||||
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
|
||||
}
|
||||
|
||||
std::cout << "没凑满: " << indexofbuff <<std::endl;
|
||||
}
|
||||
gettimeofday(&timeEnd, NULL);
|
||||
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
|
||||
m_imager.stop();
|
||||
writeData2Disk->exitWriteData2Disk();
|
||||
writeHdr();
|
||||
|
||||
delete[] sbgTimeBuffer;
|
||||
|
||||
double frameInTheory=runTime * getFramerate();
|
||||
double frameLossed=frameInTheory - m_iFrameCounter;
|
||||
double frameLossRate=frameLossed / frameInTheory;
|
||||
|
||||
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
|
||||
double frameLossed = m_imager.m_image.acq_nframe - m_iFrameCounter;
|
||||
double frameLossRate = frameLossed / m_imager.m_image.acq_nframe;
|
||||
|
||||
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<< ".bil" <<std::endl;
|
||||
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
|
||||
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
|
||||
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
|
||||
std::cout<<"理论采集帧数为: "<<frameInTheory<<std::endl;
|
||||
std::cout<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe<<std::endl;
|
||||
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
|
||||
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
|
||||
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
|
||||
|
||||
fclose(hHimesFile);
|
||||
// timesFileHandle.close();
|
||||
// timesFile.close();
|
||||
|
||||
timeStr = formatTimeStr(timeFormat);
|
||||
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
|
||||
|
||||
writeHdr();
|
||||
|
||||
m_iImagerState=m_iImagerStateTemp;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
@ -613,6 +700,9 @@ void XimeaImager::writeHdr()
|
||||
hdrFileHandle << "wavelength units = nanometers\n";
|
||||
hdrFileHandle << "wavelength = {";
|
||||
//hdrFileHandle << std::setprecision(5);
|
||||
|
||||
if (m_imager.getSpectralBin() == 1)
|
||||
{
|
||||
for (int i = getWindowStartBand(); i < getWindowEndBand(); i++)
|
||||
{
|
||||
hdrFileHandle << geWavelengthAtBand(i);
|
||||
@ -623,6 +713,30 @@ void XimeaImager::writeHdr()
|
||||
printf("头文件中写入了多少个波段:%d\n",i-getWindowStartBand()+1);//???????????????
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_imager.getSpectralBin() == 2)
|
||||
{
|
||||
int counter = 0;
|
||||
for (int i = m_iOffsetyOfSpectralBin2; i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2; i++)
|
||||
{
|
||||
if (i*2 + 1 > m_iOffsetyOfSpectralBin1 + m_iHeightOfSpectralBin1)
|
||||
{
|
||||
printf("XimeaImager::writeHdr 出现错误:窗口中,光谱 bin1 波段数小于 bin2 的 2 倍。\n");
|
||||
break;
|
||||
}
|
||||
|
||||
hdrFileHandle << (geWavelengthAtBand(i*2) + geWavelengthAtBand(i*2 + 1)) / 2;
|
||||
counter++;
|
||||
if (i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 - 1)
|
||||
hdrFileHandle << ", ";
|
||||
else
|
||||
{
|
||||
printf("头文件中写入了多少个波段:%d\n", counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hdrFileHandle << "}\n";
|
||||
hdrFileHandle.close();
|
||||
}
|
||||
@ -701,6 +815,18 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
|
||||
m_iImagerState=xiApiErrorCodes;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
break;
|
||||
case 10:
|
||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Timeout!"<<std::endl;
|
||||
m_iImagerState=xiApiErrorCodes;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
break;
|
||||
case 11:
|
||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Invalid arguments supplied!"<<std::endl;
|
||||
m_iImagerState=xiApiErrorCodes;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
|
||||
break;
|
||||
case 12:
|
||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
|
||||
@ -727,20 +853,26 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
|
||||
|
||||
break;
|
||||
default:
|
||||
QString ximeaError="ximeaError.txt";
|
||||
ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app);
|
||||
|
||||
ximeaErrorFile<< xiApiErrorCodes << "\n";
|
||||
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:未处理ximea异常代码:"<< xiApiErrorCodes <<std::endl;
|
||||
|
||||
ximeaErrorFile.close();
|
||||
|
||||
|
||||
|
||||
m_iImagerState=99;
|
||||
emit ximeaImageStatus(m_iImagerState);
|
||||
break;
|
||||
}
|
||||
|
||||
writeXiApiErrorCodes("/media/nvme/300TC/ximeaError.txt", xiApiErrorCodes);
|
||||
}
|
||||
|
||||
void XimeaImager::writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes)
|
||||
{
|
||||
ofstream ximeaErrorFile(filePath.toStdString().c_str(),ios::app);
|
||||
|
||||
char * timeFormat="%Y%m%d_%H%M%S";
|
||||
QString timeStr = formatTimeStr(timeFormat);
|
||||
|
||||
ximeaErrorFile<< timeStr.toStdString().c_str() << ": " << xiApiErrorCodes << "\n";
|
||||
|
||||
std::cout<<"XimeaImager::writeXiApiErrorCodes-----------:xiApiErrorCodes: "<<timeStr.toStdString().c_str()<< ": " << xiApiErrorCodes<<std::endl;
|
||||
|
||||
ximeaErrorFile.close();
|
||||
}
|
||||
|
||||
void XimeaImager::stopRecord()
|
||||
@ -800,43 +932,63 @@ void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
|
||||
|
||||
WriteData2Disk::WriteData2Disk()
|
||||
{
|
||||
isExitWriteData2Disk = false;
|
||||
}
|
||||
|
||||
void WriteData2Disk::write2Disk()
|
||||
{
|
||||
QString imageFileName=m_QbaseFileName+".bil";
|
||||
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
||||
// FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
|
||||
|
||||
|
||||
int fd = open(imageFileName.toStdString().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
|
||||
size_t fileSize = m_iFrameSizeInByte*(size_t)100*(size_t)60*(size_t)5;
|
||||
size_t fileSizeIncrement = m_iFrameSizeInByte*(size_t)100*(size_t)60*(size_t)5;
|
||||
if (lseek(fd, fileSize - 1, SEEK_SET) == -1) {
|
||||
std::cerr << "Error calling lseek()\n";
|
||||
return;
|
||||
}
|
||||
if (write(fd, "", 1) == -1) {
|
||||
std::cerr << "Error writing last byte of the file\n";
|
||||
return;
|
||||
}
|
||||
void* addr = mmap(nullptr, fileSize, PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error mmapping the file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
size_t sizeWrited2disk = 0;
|
||||
|
||||
int sleepCounters=1;
|
||||
int frameCounter = 0;
|
||||
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2];
|
||||
int frameNumber;
|
||||
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2*m_iNumber_WriteDisk];
|
||||
isExitWriteData2Disk = false;
|
||||
while(true)
|
||||
{
|
||||
r_qtx.lock();
|
||||
bool bempty=m_q->empty();
|
||||
r_qtx.unlock();
|
||||
if(bempty)
|
||||
{
|
||||
QThread::msleep(sleepCounters * sleepCounters * 10);
|
||||
// std::cout<<"WriteData2Disk::write2Disk-----------------------队列第几次为空:" << sleepCounters <<std::endl;
|
||||
sleepCounters++;
|
||||
|
||||
if (sleepCounters == 10 && frameCounter != 0)//如果sleepCounters == 10时,队列还是空,就代表相机停止采集 → 退出此线程
|
||||
if(bempty && isExitWriteData2Disk)
|
||||
{
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------队列为空,采集线程已经退出!"<<std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
else if(bempty && !isExitWriteData2Disk)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sleepCounters = 1;
|
||||
|
||||
|
||||
r_qtx.lock();
|
||||
DataBuffer * buffer = m_q->front();
|
||||
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte);
|
||||
int frameNumber = m_qFrameCounter->front();
|
||||
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*frameNumber);
|
||||
// m_pool->destroy(m_q->front());
|
||||
m_pool->deleteElement(buffer);
|
||||
m_q->pop();
|
||||
m_qFrameCounter->pop();
|
||||
r_qtx.unlock();
|
||||
|
||||
//构造rgb图像,用于推流到m300遥控器
|
||||
@ -844,21 +996,87 @@ void WriteData2Disk::write2Disk()
|
||||
|
||||
|
||||
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
|
||||
fwrite(dataBuffer,1,m_iFrameSizeInByte, hFile);
|
||||
|
||||
|
||||
if (fileSize < sizeWrited2disk + m_iFrameSizeInByte*frameNumber)
|
||||
{
|
||||
// if (munmap(addr, fileSize) == -1) {
|
||||
// std::cerr << "Error un-mmapping the file\n";
|
||||
// }
|
||||
|
||||
// std::cout<<"老fileSize:" << fileSize <<std::endl;
|
||||
size_t new_size = fileSize + fileSizeIncrement;
|
||||
if (ftruncate(fd, new_size) == -1) {
|
||||
std::cerr << "Error calling ftruncate()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Remap the file with the new size
|
||||
addr = mremap(addr, fileSize, new_size, MREMAP_MAYMOVE);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error calling mremap()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
fileSize = new_size;
|
||||
// std::cout<<"新fileSize:" << fileSize <<std::endl;
|
||||
|
||||
}
|
||||
// fwrite(dataBuffer,1,m_iFrameSizeInByte*frameNumber, hFile);
|
||||
memcpy(addr + sizeWrited2disk, dataBuffer, m_iFrameSizeInByte*frameNumber);
|
||||
|
||||
sizeWrited2disk = sizeWrited2disk + m_iFrameSizeInByte*frameNumber;
|
||||
// std::cout<<"sizeWrited2disk:" << sizeWrited2disk <<std::endl;
|
||||
|
||||
frameCounter++;
|
||||
}
|
||||
m_rgbImage->m_VideoWriter.release();
|
||||
fclose(hFile);
|
||||
// fclose(hFile);
|
||||
delete[] dataBuffer;
|
||||
|
||||
|
||||
|
||||
|
||||
// if (munmap(addr, fileSize) == -1) {
|
||||
// std::cerr << "Error un-mmapping the file\n";
|
||||
// }
|
||||
|
||||
// Resize the file to 4096 bytes
|
||||
if (ftruncate(fd, sizeWrited2disk) == -1) {
|
||||
std::cerr << "Error calling ftruncate()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Remap the file with the new size
|
||||
addr = mremap(addr, fileSize, sizeWrited2disk, MREMAP_MAYMOVE);
|
||||
if (addr == MAP_FAILED) {
|
||||
std::cerr << "Error calling mremap()\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (munmap(addr, sizeWrited2disk) == -1) {
|
||||
std::cerr << "Error un-mmapping the file\n";
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter <<std::endl;
|
||||
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,fwrite 调用次数:" << frameCounter <<std::endl;
|
||||
}
|
||||
|
||||
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
||||
void WriteData2Disk::exitWriteData2Disk()
|
||||
{
|
||||
isExitWriteData2Disk = true;
|
||||
}
|
||||
|
||||
void WriteData2Disk::setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
|
||||
{
|
||||
m_q = q;
|
||||
m_qFrameCounter = qFrameCounter;
|
||||
m_QbaseFileName = baseFileName;
|
||||
m_iFrameSizeInByte = frameSizeInByte;
|
||||
m_iNumber_WriteDisk = number_WriteDisk;
|
||||
|
||||
m_pool = pool;
|
||||
|
||||
|
Reference in New Issue
Block a user