19 Commits
34 ... 41

Author SHA1 Message Date
061e1f83bd add:记录cpu温度; 2023-10-25 15:37:15 +08:00
d0b67b47c1 add:psdk重启后,通知本程序发送本程序的状态; 2023-10-25 15:33:52 +08:00
7fa3b70d10 Modify:去掉内存池; 2023-10-18 11:39:01 +08:00
781b33f577 add:添加温湿度传感器硬件,并解析温湿度/气压等数据; 2023-10-18 11:37:02 +08:00
f33103c970 fix:修复时间同步错误 2023-09-13 17:24:16 +08:00
a341e0b2c5 add:采集过程中同时记录相机温度,高于80度停止采集,高于90度系统关闭 2023-09-13 17:08:17 +08:00
19e2309be7 fix:返回的曝光时间都使用微秒; 2023-09-04 18:03:20 +08:00
a492baea18 fix:惯导进入full nav才开始采集高光谱; 2023-09-01 15:38:16 +08:00
096df8075c 修改:
记录上次设置的帧率和曝光时间,打开时,将上次的帧率和曝光时间设置为当前参数;
2023-08-29 13:46:40 +08:00
ba1b01bccc fix bug:解析sbg的sulution mode; 2023-08-18 16:01:22 +08:00
e4a7c4481b 打印版本号 2023-07-14 16:34:31 +08:00
1476c2bc15 内存映射mremap在320G时会失败,改为用fwrite,经测试980PRO 2个bin1 采集80分钟不会丢帧; 2023-07-14 16:33:37 +08:00
6d6b662cec 输出调试信息 2023-07-14 09:21:58 +08:00
2e158431e7 输出版本号:35 2023-07-04 21:23:25 +08:00
6473a1f4ce 内存映射写磁盘 2023-07-04 21:22:38 +08:00
cc76d62ded 1. 使用相机时间来计算times文件;
2. times放弃每帧写一次的方法;
3. 不满100帧的内容不丢弃:添加一个队列来记录压入队列的帧数;
2023-06-30 15:21:23 +08:00
e620c87ecf 打印版本号 2023-06-28 13:32:59 +08:00
47002ad894 改变光谱bin2的波长计算方式为:通过bin1平均相邻波长获取; 2023-06-28 11:59:46 +08:00
5337a40837 更新:发送 bin 状态到遥控器 2023-06-27 14:01:19 +08:00
8 changed files with 974 additions and 154 deletions

View File

@ -34,7 +34,9 @@ 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);
@ -47,4 +49,55 @@ private:
string m_configfilePath;
Config cfg;
};
class ParameterConfigfile
{
public:
ParameterConfigfile();
void setConfigfilePath(string configfilePath);
bool isConfigfileExist();
bool parseConfigfile();
bool getFrameRate(int &frameRate);
bool setFrameRate(int frameRate);
bool getExposeTime(float &exposeTime);
bool setExposeTime(float exposeTime);
bool createConfigFile();
// bool updateConfigFile();
bool writeConfig2File();
string m_configfilePath;
Config cfg;
private:
};
class StateOf300tcConfigfile:public ParameterConfigfile
{
public:
StateOf300tcConfigfile();
bool getSwitchState(bool &switchState);
bool setSwitchState(bool switchState);
bool getSbgState(int &sbgState);
bool setSbgState(int sbgState);
bool getSbgSolutionMode(int &sbgSolutionMode);
bool setSbgSolutionMode(int sbgSolutionMode);
bool getXimeaState(int &ximeaState);
bool setXimeaState(int ximeaState);
bool getExposeMaxValueOfOneFrame(int &exposeMaxValueOfOneFrame);
bool setExposeMaxValueOfOneFrame(int exposeMaxValueOfOneFrame);
bool createConfigFile();
private:
bool getIntValue(int &value, string field);
bool setIntValue(int value, string field);
};
#endif //XIMEAIMAGERECORDER_CONFIGFILE_H

View File

@ -11,17 +11,43 @@
#include <QObject>
#include <QThread>
#include <QDir>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include "ximeaimager.h"
#include "sbgrecorder.h"
#include "fileoperation.h"
#include "configfile.h"
extern "C"
{
// #include <sbgEComLib.h>
#include <stdlib.h>
}
class Record300TcTemperature : public QObject
{
Q_OBJECT
public:
Record300TcTemperature();
void stopRecordTemperature();
private:
bool m_bIsRecord;
QSerialPort * m_serial;
float parseMessage(QByteArray * data);
public slots:
void recordTemperature(QString filePath);
signals:
};
class UdpServer:public QObject
{
Q_OBJECT
@ -48,6 +74,11 @@ class UdpServer:public QObject
void sender(int status);
QThread * m_recordTempThread;
Record300TcTemperature * m_300tcTemperature;
StateOf300tcConfigfile stateOf300tc;
signals:
void systemStart();
void systemStop();
@ -56,6 +87,7 @@ signals:
void startDeleteFileSignal();
void recordXimeaOnlySignal(double,QString);
void record300tcTemperatureSignal(QString);
public slots:
void onRecordFinished();
@ -67,6 +99,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);
};

View File

@ -70,12 +70,13 @@ private:
};
class XimeaImager;
class RecordXimeaTemperature : public QObject
{
Q_OBJECT
public:
RecordXimeaTemperature(Iris::IrisXimeaImager * imager);
RecordXimeaTemperature(Iris::IrisXimeaImager * imager, XimeaImager * ximeaImager);
void stopRecordTemperature();
@ -83,6 +84,7 @@ private:
Iris::IrisXimeaImager * m_imager;
bool m_bIsRecord;
XimeaImager * m_ximeaImager;
public slots:
void recordTemperature(QString filePath);
@ -100,10 +102,11 @@ Q_OBJECT
public:
WriteData2Disk();
void setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, 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;
@ -129,7 +132,7 @@ public:
void setFramerate(double framerate);
double getFramerate();
double setExposureTime(float exposureTime);
double setExposureTime(float exposureTime_in_us);
int wrapSetExposureTime(float exposureTime_in_us);
double getExposureTime();
double autoExposure();
@ -154,12 +157,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;
@ -176,26 +183,14 @@ 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;
ParameterConfigfile m_parameterConfigfile;
@ -203,6 +198,7 @@ public slots:
void openImger();
void closeImger();
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
signals:
@ -214,5 +210,6 @@ signals:
void autoExposeMaxValueOfOneFrame(int, double);
void frameRateSignal(double);
void binSignal(int, int);
};
#endif // XIMEAIMAGER_H

View File

@ -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
@ -417,3 +468,295 @@ bool Configfile::updateConfigFile()
return true;
}
ParameterConfigfile::ParameterConfigfile()
{
}
void ParameterConfigfile::setConfigfilePath(string configfilePath)
{
m_configfilePath = configfilePath;
}
bool ParameterConfigfile::isConfigfileExist()
{
QFileInfo info(QString::fromStdString(m_configfilePath));
return info.exists();
}
bool ParameterConfigfile::parseConfigfile()
{
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile(m_configfilePath);
return true;
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
}
bool ParameterConfigfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting &root = cfg.getRoot();
// Add some settings to the configuration.
// Setting &SN = root.add("SN", Setting::TypeString) = "0098";
// Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
// Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &ximeaParam = root.add("ximeaParam", Setting::TypeGroup);
ximeaParam.add("frameRate", Setting::TypeInt) = 100;
ximeaParam.add("exposeTime", Setting::TypeFloat) = 10.0;
// Write out the new configuration.
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool ParameterConfigfile::getFrameRate(int &frameRate)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
frameRate = ximeaParam.lookup("frameRate");
// std::cout << "ParameterConfigfile::getFrameRate"<< frameRate<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'frameRate' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::setFrameRate(int frameRate)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"]["frameRate"];
frameRate2 = frameRate;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'frameRate' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::getExposeTime(float &exposeTime)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
exposeTime = ximeaParam.lookup("exposeTime");
// std::cout << "ParameterConfigfile::getExposeTime"<< exposeTime<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'exposeTime' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::setExposeTime(float exposeTime)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"]["exposeTime"];
frameRate2 = exposeTime;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'exposeTime' setting in configuration file." << endl;
return false;
}
}
bool ParameterConfigfile::writeConfig2File()
{
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
// cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return false;
}
return true;
}
StateOf300tcConfigfile::StateOf300tcConfigfile()
{
}
bool StateOf300tcConfigfile::getIntValue(int &value, string field)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &ximeaParam = root["ximeaParam"];
value = ximeaParam.lookup(field);
// std::cout << "StateOf300tcConfigfile::getIntValue"<< value<<std::endl;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No setting in configuration file." << endl;
return false;
}
}
bool StateOf300tcConfigfile::setIntValue(int value, string field)
{
const Setting& root = cfg.getRoot();
try
{
Setting &frameRate2 = root["ximeaParam"][field];
frameRate2 = value;
writeConfig2File();
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No setting in configuration file." << endl;
return false;
}
}
bool StateOf300tcConfigfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting &root = cfg.getRoot();
// Add some settings to the configuration.
// Setting &SN = root.add("SN", Setting::TypeString) = "0098";
// Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
// Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &ximeaParam = root.add("ximeaParam", Setting::TypeGroup);
ximeaParam.add("sbgState", Setting::TypeInt) = 0;
ximeaParam.add("sbgSolutionMode", Setting::TypeInt) = 0;
ximeaParam.add("ximeaState", Setting::TypeInt) = 100;
ximeaParam.add("frameRate", Setting::TypeInt) = 0;
ximeaParam.add("exposeTime", Setting::TypeFloat) = 0.0;
ximeaParam.add("exposeMaxValueOfOneFrame", Setting::TypeInt) = 0;
// Write out the new configuration.
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool StateOf300tcConfigfile::getSbgState(int &sbgState)
{
return getIntValue(sbgState,"sbgState");
}
bool StateOf300tcConfigfile::setSbgState(int sbgState)
{
return setIntValue(sbgState,"sbgState");
}
bool StateOf300tcConfigfile::getSbgSolutionMode(int &sbgSolutionMode)
{
return getIntValue(sbgSolutionMode,"sbgSolutionMode");
}
bool StateOf300tcConfigfile::setSbgSolutionMode(int sbgSolutionMode)
{
return setIntValue(sbgSolutionMode,"sbgSolutionMode");
}
bool StateOf300tcConfigfile::getXimeaState(int &ximeaState)
{
return getIntValue(ximeaState,"ximeaState");
}
bool StateOf300tcConfigfile::setXimeaState(int ximeaState)
{
return setIntValue(ximeaState,"ximeaState");
}
bool StateOf300tcConfigfile::getExposeMaxValueOfOneFrame(int &exposeMaxValueOfOneFrame)
{
return getIntValue(exposeMaxValueOfOneFrame,"exposeMaxValueOfOneFrame");
}
bool StateOf300tcConfigfile::setExposeMaxValueOfOneFrame(int exposeMaxValueOfOneFrame)
{
return setIntValue(exposeMaxValueOfOneFrame,"exposeMaxValueOfOneFrame");
}

View File

@ -3,6 +3,7 @@
int main(int argc, char *argv[])
{
std::cout<<"ximeaAirborneSystem 版本:"<< "41." <<std::endl;
QCoreApplication a(argc, argv);
//UdpServer* x=new UdpServer();

View File

@ -608,66 +608,43 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
//判断模式是否为: NAV_POSITION
if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_EULER)
{
m_iSolutionModeCounter++;//
m_iSolutionModeCounter++;
uint32_t status=logData.ekfEulerData.status;
uint32_t mode=status>>24;//?????????????????????????????????????
// uint32_t mode=status;//这是错的
uint32_t mode=status & 0xf;
//一秒钟发射一次mode
if(m_iSolutionModeCounter%200 == 0)
{
emit sbgSolutionModeSignal(mode);
// std::cout << "logData.ekfEulerData.status: " << status << std::endl;
switch (mode)
{
case SBG_ECOM_SOL_MODE_UNINITIALIZED:
// std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
// std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_AHRS:
// std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
// std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
// std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
switch (mode) {
case SBG_ECOM_SOL_MODE_UNINITIALIZED:
// std::cout << "此刻模式为: " << "UNINITIALIZED" << std::endl;
m_bIsNAV_POSITION_MODE = false;
break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
// std::cout << "此刻模式为: " << "VERTICAL_GYRO" << std::endl;
m_bIsNAV_POSITION_MODE = false;
break;
case SBG_ECOM_SOL_MODE_AHRS:
// std::cout << "此刻模式为: " << "AHRS" << std::endl;
m_bIsNAV_POSITION_MODE = false;
break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
// std::cout << "此刻模式为: " << "NAV_VELOCITY" << std::endl;
m_bIsNAV_POSITION_MODE = false;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
// std::cout << "此刻模式为: " << "NAV_POSITION" << std::endl;
m_bIsNAV_POSITION_MODE = true;
break;
default:
break;
break;
default:
break;
}
}
switch (mode)
{
case SBG_ECOM_SOL_MODE_UNINITIALIZED:
// std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
// std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_AHRS:
// std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
// std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
m_bIsNAV_POSITION_MODE=false;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
// std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
m_bIsNAV_POSITION_MODE=true;
break;
default:
break;
}
}
else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_GPS1_POS)
{
@ -687,6 +664,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
// std::cout<<"纬度精度为:"<<maximal<<std::endl;
// std::cout<<"numSvUsed"<<satelliteCounter<<std::endl;
//
// std::cout<<"latitude"<<logData.gpsPosData.latitude<<std::endl;
// std::cout<<"longitude"<<logData.gpsPosData.longitude<<std::endl;
// std::cout<<"altitude"<<logData.gpsPosData.altitude<<std::endl;
emit sbgAccuracySignal(static_cast<int>(maximal), satelliteCounter);
@ -727,7 +708,7 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
//控制开始采集高光谱影像,m_bIsNAV_POSITION_MODE &&
if(m_bIsRecordHyperspecatralImage && m_bIsSyncSystemTimeBaseGpstime && receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_UTC_TIME)
if(m_bIsRecordHyperspecatralImage && m_bIsSyncSystemTimeBaseGpstime && m_bIsNAV_POSITION_MODE && receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_UTC_TIME)
{
m_baseFileName=getFileNameBaseOnTime();
emit sbgReady(calculateTimeDifferenceBetweenSystemAndSbg(logData),m_baseFileName);

View File

@ -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,19 +51,41 @@ 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)));
QString ximeaParamCfgFile = "/media/nvme/300TC/config/StateOf300tc.cfg";
stateOf300tc.setConfigfilePath(ximeaParamCfgFile.toStdString());
if(!stateOf300tc.isConfigfileExist())
stateOf300tc.createConfigFile();
stateOf300tc.parseConfigfile();
stateOf300tc.setSbgState(0);
stateOf300tc.setSbgSolutionMode(0);
stateOf300tc.setXimeaState(100);
stateOf300tc.setFrameRate(0);
stateOf300tc.setExposeTime(0);
stateOf300tc.setExposeMaxValueOfOneFrame(0);
//当软件不正常关闭并且重启后通知其他psdk程序
m_clientIpAddress=QHostAddress(QHostAddress::LocalHost);
sendSerialPortStatus(0);
sendXimeaImageStatus(0);
sendXimeaImageStatus(100);
sendCopyFileStatus(0);
system("sudo gpio write 10 0");
m_recordTempThread=new QThread();
m_300tcTemperature = new Record300TcTemperature();
m_300tcTemperature->moveToThread(m_recordTempThread);
m_recordTempThread->start();
connect(this, SIGNAL(record300tcTemperatureSignal(QString)),m_300tcTemperature, SLOT(recordTemperature(QString)));
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
QString Temperature300tcCSVPath = QDir::cleanPath(QString::fromStdString("/media/nvme/300TC/programRunLog/300tcTemperature") + QDir::separator() + "300tcTemperature_" + currentTime + ".csv");
emit record300tcTemperatureSignal(Temperature300tcCSVPath);
std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl;
}
@ -101,7 +123,7 @@ void UdpServer::processPendingDatagrams()
case 2://关闭系统:关闭相机和sbg串口,关闭软件
{
std::cout<<"2代表关闭系统!"<<std::endl;
m_300tcTemperature->stopRecordTemperature();
if(m_sbgRecorder->getSbgState()>=1)
{
@ -166,8 +188,8 @@ void UdpServer::processPendingDatagrams()
{
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{
float time = datagramList[1].toFloat();//ms
m_imager->wrapSetExposureTime(time*1000);
float time = datagramList[1].toFloat();//μs
m_imager->wrapSetExposureTime(time);
std::cout<<"7手动设置曝光时间为" << time <<std::endl;
}
@ -196,8 +218,30 @@ void UdpServer::processPendingDatagrams()
break;
}
case 10:
{
std::cout<<"10代表!"<<std::endl;
int sbgState,sbgSolutionMode,ximeaState,frameRate,exposeMaxValueOfOneFrame;
float exposeTime;
stateOf300tc.getSbgState(sbgState);
stateOf300tc.getSbgSolutionMode(sbgSolutionMode);
stateOf300tc.getXimeaState(ximeaState);
stateOf300tc.getFrameRate(frameRate);
stateOf300tc.getExposeTime(exposeTime);
stateOf300tc.getExposeMaxValueOfOneFrame(exposeMaxValueOfOneFrame);
sendSerialPortStatus(sbgState);
sendSbgSolutionModeState(sbgSolutionMode);
sendXimeaImageStatus(ximeaState);
sendXimeaAutoExposeMaxValueOfOneFrame(exposeMaxValueOfOneFrame, exposeTime);
sendXimeaImageFrameRate(frameRate);
break;
}
default:
std::cout<<">=9没有意义!"<<std::endl;
std::cout<<">=11没有意义!"<<std::endl;
break;
}
@ -259,6 +303,8 @@ void UdpServer::sendSerialPortStatus(int serialPortStatus)
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setSbgState(serialPortStatus);
}
void UdpServer::sendSbgSolutionModeState(int SolutionMode)
@ -271,6 +317,8 @@ void UdpServer::sendSbgSolutionModeState(int SolutionMode)
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setSbgSolutionMode(SolutionMode);
}
void UdpServer::sendSbgAccuracyState(int Accuracy,int SatelliteCounter)
@ -295,15 +343,32 @@ void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setXimeaState(ximeaImageStatus);
}
void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< exposeTime << " " << autoExposeMaxValueOfOneFrame <<std::endl;
QByteArray datagram2send;
QString status = "XimeaAutoExpose," + QString::number(autoExposeMaxValueOfOneFrame) + "," + QString::number(exposeTime, 'f', 2);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setExposeTime(exposeTime);
stateOf300tc.setExposeMaxValueOfOneFrame(autoExposeMaxValueOfOneFrame);
}
void UdpServer::sendXimeaBinState(int spatialBin, int spectralBin)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "XimeaAutoExpose," + QString::number(autoExposeMaxValueOfOneFrame) + "," + QString::number(exposeTime, 'f', 2);
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);
@ -319,6 +384,8 @@ void UdpServer::sendXimeaImageFrameRate(double frameRate)
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
stateOf300tc.setFrameRate(frameRate);
}
void UdpServer::sendCopyFileStatus(int fileStatus)
@ -337,3 +404,199 @@ void UdpServer::onRecordFinished()
{
std::cout<<"UdpServer::onRecordFinished----------------:影像停止采集"<<std::endl;
}
Record300TcTemperature::Record300TcTemperature()
{
m_bIsRecord = true;
}
void Record300TcTemperature::stopRecordTemperature()
{
m_bIsRecord = false;
}
void Record300TcTemperature::recordTemperature(QString filePath= nullptr)
{
if(filePath== nullptr)
filePath="300tcTemperature.csv";
QList<QString> fileInfo = getFileInfo(filePath);
bool ret = createDir(fileInfo[0]);
ofstream temperatureFile300Tc(filePath.toStdString().c_str(),ios::app);
int counter = 0;
m_serial=new QSerialPort();
if(m_serial->isOpen())//如果串口已经打开了 先给他关闭了
{
m_serial->clear();
m_serial->close();
}
QString portname = "ttyUSB2";
m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite);
bool x=m_serial->setBaudRate(9600);
QByteArray requestData;
while (m_bIsRecord)
{
counter++;
if(m_serial->waitForReadyRead(30000))
{
requestData = m_serial->readAll();
float temp = parseMessage(&requestData);
if (temp == -10000)
{
continue;
}
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy/MM/dd hh:mm:ss");
temperatureFile300Tc << currentTime.toStdString() << "," << temp << "\n";
// if(temp > 80)
// {
// system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 9,0");
// }
// if(temp > 90)
// {
// system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 2");
// }
//
if (counter % 60 == 0)
{
temperatureFile300Tc.flush();
}
sleep(1);
}
else
{
// std::cout<<"Record300TcTemperature::recordTemperature--Wait response timeout."<<std::endl;
}
}
m_bIsRecord = true;
temperatureFile300Tc.close();
}
float Record300TcTemperature::parseMessage(QByteArray * data)
{
float Lux;
float T;
float P;
float Hum;
float H;
bool hasTemperature = false;
// qDebug() << "Received data(hex): " << data->toHex();
// for (int i = 0; i < data->length(); ++i)
// {
// qDebug() << i << ":" << (int)data->at(i);
// }
QByteArray target = QByteArray::fromHex("5a5a"); // The pattern to search for
int offset_tmp = data->indexOf(target);
QList<int> offsets;
while (offset_tmp != -1)
{
offsets.append(offset_tmp);
offset_tmp = data->indexOf(target, offset_tmp + target.size());
}
if (offsets.isEmpty())
{
// qDebug() << "5A5A not found in the data.";
return -10000;
}
// qDebug() << "5A5A found at offsets:" << offsets;
for (int i = 0; i < offsets.length(); ++i)
{
int offset = offsets.at(i);
int messageClass = data->at(offset + 2);
int messageCount = data->at(offset + 3) + 5;
// qDebug() << "messageCount:" << messageCount;
if (offset + messageCount - 1 > data->length() - 1)
{
qDebug() << i << ": Some data of this frame is missing! Discarding the frame.";
continue;
}
int checksum = 0;
QList<int> numbers;
for (int j = 0; j < messageCount - 1; ++j)
{
if (i==offsets.length()-1 && j== messageCount-1)
{
int sdf=1;
}
int index = offset + j;
if (index >= data->length())//Some data of this frame is missing! Discarding the frame.
{
checksum = -1;
break;
}
int tmp = static_cast<int>(data->at(index));
numbers.append(tmp);
checksum += tmp;
}
// qDebug() << "jiaqilai:" << numbers;
if (checksum == -1)
{
qDebug() << "Some data of this frame is missing! Discarding the frame.";
continue;
}
if ((checksum & 0xFF) != data->at(offset + messageCount - 1))
{
qDebug() << "Checksum mismatch! Discarding the frame.";
continue;
}
//parse data
switch (messageClass)
{
case 0x15:
Lux = (float)((data->at(offset + 4)<<24)|(data->at(offset + 5)<<16)|(data->at(offset + 6)<<8)|data->at(offset + 7)) / 100;
// qDebug() << "lux: " << Lux;
break;
case 0x45:
T = (float)((data->at(offset + 4)<<8)|data->at(offset + 5)) / 100;
P = (float)((data->at(offset + 6)<<24)|(data->at(offset + 7)<<16)|(data->at(offset + 8)<<8)|data->at(offset + 9)) / 100;
Hum = (float)((data->at(offset + 10)<<8) | data->at(offset + 11)) / 100;
H = (float)((data->at(offset + 12)<<8)|data->at(offset + 13));
hasTemperature = true;
// qDebug() << "T: " << T;
// qDebug() << "P: " << P;
// qDebug() << "Hum: " << Hum;
// qDebug() << "H: " << H;
break;
default : // 可选的
;
}
}
if (hasTemperature)
{
return T;
}
else
{
return -10000;
}
}

View File

@ -12,9 +12,30 @@ XimeaImager::XimeaImager()
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;
}
QString ximeaParamCfgFile = "/media/nvme/300TC/config/ximeaParam.cfg";
m_parameterConfigfile.setConfigfilePath(ximeaParamCfgFile.toStdString());
if(!m_parameterConfigfile.isConfigfileExist())
m_parameterConfigfile.createConfigFile();
m_parameterConfigfile.parseConfigfile();
m_recordTempThread=new QThread();
m_ximeaTemperature = new RecordXimeaTemperature(&m_imager);
m_ximeaTemperature = new RecordXimeaTemperature(&m_imager, this);
m_ximeaTemperature->moveToThread(m_recordTempThread);
m_recordTempThread->start();
@ -28,6 +49,7 @@ XimeaImager::XimeaImager()
m_pool = new MemoryPool<DataBuffer>;
q = new queue<DataBuffer *>;
m_qFrameCounter = new queue<int>;
m_rgbImage = new rgbImage();
}
@ -61,10 +83,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);
@ -78,6 +104,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;
@ -99,7 +126,20 @@ void XimeaImager::openImger()
m_imager.setAcqBufferSize(acqBufferSize);
}
setFramerate(100);
if (m_parameterConfigfile.isConfigfileExist())
{
int frameRate;
m_parameterConfigfile.getFrameRate(frameRate);
setFramerate(frameRate);
float exposeTime;
m_parameterConfigfile.getExposeTime(exposeTime);
wrapSetExposureTime(exposeTime);
}
else
{
setFramerate(100);
}
//经验证frameSizeManual和frameSizeAuto相等
int frameSizeManual = m_imager.get_band_count()*m_imager.get_sample_count()*2;
@ -115,7 +155,7 @@ void XimeaImager::openImger()
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
m_ximeaTemperatureCSVPath = QDir::cleanPath(QString::fromStdString("/home/programRunLog/hyperspectralLog") + QDir::separator() + "ximeaTemperature_" + currentTime + ".csv");
m_ximeaTemperatureCSVPath = QDir::cleanPath(QString::fromStdString("/media/nvme/300TC/programRunLog/ximeaTemperature") + QDir::separator() + "ximeaTemperature_" + currentTime + ".csv");
// m_ximeaTemperatureCSVPath = "/home/ximeaTemperature.csv";
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);
}
@ -164,14 +204,21 @@ void XimeaImager::setFramerate(double framerate)
{
m_imager.set_framerate(framerate);
int maxExposureTimeInUs=1/framerate*1000000*0.01;
setExposureTime(maxExposureTimeInUs);
// setExposureTime(1000);
int exposureTimeInUs = getExposureTime();
int maxExposureTimeInUs=1/framerate*1000000;
if (exposureTimeInUs > maxExposureTimeInUs)
{
wrapSetExposureTime(maxExposureTimeInUs);
}
m_iImagerState=102;
emit ximeaImageStatus(m_iImagerState);
emit frameRateSignal(framerate);
m_parameterConfigfile.setFrameRate(framerate);
}
catch(int xiApiErrorCodes)
{
@ -207,9 +254,7 @@ double XimeaImager::setExposureTime(float exposureTime_in_us)
//确保设置的积分时间比最大积分时间小
if(exposureTime_in_us<maxExposureTime_in_us)
{
m_imager.set_integration_time(exposureTime_in_us);
}
else
{
@ -218,6 +263,7 @@ double XimeaImager::setExposureTime(float exposureTime_in_us)
//返回设置的积分时间
integrationTime2Return=m_imager.get_integration_time();
m_parameterConfigfile.setExposeTime(integrationTime2Return);
return integrationTime2Return;
}
@ -241,7 +287,7 @@ int XimeaImager::wrapSetExposureTime(float exposureTime_in_us)
m_iImagerState=103;
emit ximeaImageStatus(m_iImagerState);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime);
return maxValueOfOneFrame;
}
@ -304,7 +350,7 @@ double XimeaImager::autoExposure()
m_iImagerState=103;
emit ximeaImageStatus(m_iImagerState);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime);
std::cout<<"自动曝光完成!"<<std::endl;
return exposureTime;
@ -471,15 +517,41 @@ 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();//开始采集影像前,停止获取相机的温度,以免降低帧率;
try
{
if(m_iImagerState <= 99 || m_iImagerState==100 || m_iImagerState==104)
{
emit ximeaImageStatus(m_iImagerState);
printf("已经开始采集----------------------------!\n");
return;
}
@ -497,23 +569,29 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
m_baseFileName=baseFileName;
QString timesFileName=m_baseFileName+".times";
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
// ofstream timesFile(timesFileName.toStdString());
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
std::cout << "帧率为:" << getFramerate() << "hz" <<std::endl;
std::cout << "曝光时间为:" << getExposureTime() << "μs" <<std::endl;
using namespace std;
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
int number_WriteDisk = 100;
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
emit startWriteDiskSignal();
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];
QString imageFileName=m_baseFileName+".bil";
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
double * imageBuffer = new double[number_WriteDisk];
m_imager.start();
struct timeval timeStart, timeEnd;
double runTime=0;
@ -523,85 +601,74 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
unsigned short *x=m_imager.get_frame(m_buffer);
m_iFrameCounter+=1;
//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();//强制系统将系统文件缓冲的内容写入磁盘
if (m_iFrameCounter == 1)
{
timeDifferenceBetweenSbgAndXimea = calculateTimeDifferenceBetweenSbgAndximea(&m_imager.m_image, TimeDifferenceBetweensOSAndSbg);
}
fwrite(m_imager.m_image.bp,1,m_iFrameSizeInByte, hFile);
indexofbuff = m_iFrameCounter % number_WriteDisk;
if (indexofbuff == 1)
{
r_qtx.lock();
buffer = m_pool->newElement();
r_qtx.unlock();
}
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);
r_qtx.unlock();
for (int i = 0; i < number_WriteDisk; ++i)
{
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
}
}
}
if (indexofbuff != 0)
{
for (int i = 0; i < indexofbuff; ++i)
{
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
}
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
fprintf(hHimesFile,"%f\n",sbgTime);
// fwrite(&sbgTime,sizeof(double),1,hHimesFile);
// timesFile<<sbgTime<< "\n";
// timesFileHandle << sbgTime << "\n";
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();
m_iFrameCounter = m_iFrameCounter - indexofbuff;
if (indexofbuff != 0)
{
m_pool->deleteElement(buffer);
}
delete[] sbgTimeBuffer;
double frameInTheory=runTime * getFramerate() - indexofbuff;
double frameInTheory=runTime * getFramerate();
double frameLossed=m_imager.m_image.acq_nframe - indexofbuff - m_iFrameCounter;
double frameLossRate=frameLossed / (m_imager.m_image.acq_nframe - indexofbuff);
double frameLossed = m_imager.m_image.acq_nframe - m_iFrameCounter;
double frameLossRate = frameLossed / m_imager.m_image.acq_nframe;
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<< ".bil" <<std::endl;
std::cout<<"采集时间为: "<<runTime/60<< " min" <<std::endl;
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
std::cout<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe - indexofbuff<<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);
fclose(hFile);
// timesFileHandle.close();
// timesFile.close();
timeStr = formatTimeStr(timeFormat);
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
writeHdr();
m_iImagerState=m_iImagerStateTemp;
emit ximeaImageStatus(m_iImagerState);
emit recordFinished();
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);//停止采集影像后,继续获取传感器温度;
}
catch(int xiApiErrorCodes)
{
@ -641,16 +708,43 @@ void XimeaImager::writeHdr()
hdrFileHandle << "wavelength units = nanometers\n";
hdrFileHandle << "wavelength = {";
//hdrFileHandle << std::setprecision(5);
for (int i = getWindowStartBand(); i < getWindowEndBand(); i++)
if (m_imager.getSpectralBin() == 1)
{
hdrFileHandle << geWavelengthAtBand(i);
if (i < getWindowEndBand() - 1)
hdrFileHandle << ", ";
else
for (int i = getWindowStartBand(); i < getWindowEndBand(); i++)
{
printf("头文件中写入了多少个波段:%d\n",i-getWindowStartBand()+1);//???????????????
hdrFileHandle << geWavelengthAtBand(i);
if (i < getWindowEndBand() - 1)
hdrFileHandle << ", ";
else
{
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();
}
@ -808,10 +902,12 @@ DataBuffer::~DataBuffer()
{
}
RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager)
RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager, XimeaImager * ximeaImager)
{
m_imager = imager;
m_bIsRecord = true;
m_ximeaImager = ximeaImager;
}
void RecordXimeaTemperature::stopRecordTemperature()
@ -823,19 +919,56 @@ void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
{
if(filePath== nullptr)
filePath="ximeaTemperature.csv";
ofstream ximeaTemperatureFile(filePath.toStdString().c_str(),ios::app);
QList<QString> fileInfo = getFileInfo(filePath);
bool ret = createDir(fileInfo[0]);
ofstream ximeaTemperatureFile(filePath.toStdString().c_str(),ios::app);
int counter = 0;
while(m_bIsRecord)
{
counter++;
float temp = m_imager->getTemperature();
if(temp > 80 && m_ximeaImager->getImagerState() == 104)
{
ximeaTemperatureFile.flush();
system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 9,0");
}
if(temp > 90)
{
ximeaTemperatureFile.flush();
system("/home/300tc/projects/udpClient/udpClient 127.0.0.1 2");
}
// 获取剩余硬盘空间和剩余采集时间
FILE *fp;
char buffer[128];
fp = popen("cat /sys/devices/virtual/thermal/thermal_zone1/temp", "r");
if (fp == NULL) {
perror("popen");
}
// 读取输出并处理
unsigned long long temper;
if (fgets(buffer, sizeof(buffer), fp) != NULL)
{
temper = strtoull(buffer, NULL, 10);
// printf("CPU温度: %.2f;\n", (float)temper/1000);
}
pclose(fp);
QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy/MM/dd hh:mm:ss");
ximeaTemperatureFile << currentTime.toStdString() << "," << temp << "\n";
ximeaTemperatureFile << currentTime.toStdString() << "," << temp << "," << (float)temper/1000 << "\n";
// std::cout<<"RecordXimeaTemperature::recordTemperature----------------:ximea Temperature is "<< temp <<std::endl;
// std::cout<<"RecordXimeaTemperature::recordTemperature----------------:ximea state is "<< m_ximeaImager->getImagerState() <<std::endl;
if (counter % 60 == 0)
{
ximeaTemperatureFile.flush();
}
sleep(1);
}
@ -854,7 +987,9 @@ void WriteData2Disk::write2Disk()
QString imageFileName=m_QbaseFileName+".bil";
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
int frameCounter = 0;
int frameNumber;
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2*m_iNumber_WriteDisk];
isExitWriteData2Disk = false;
while(true)
@ -867,18 +1002,26 @@ void WriteData2Disk::write2Disk()
std::cout<<"WriteData2Disk::write2Disk-----------------------队列为空,采集线程已经退出!"<<std::endl;
break;
}
else if(isExitWriteData2Disk)
{
std::cout<<"WriteData2Disk::write2Disk-----------------------isExitWriteData2Disktrue"<<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------队列大小"<<m_q->size()<<std::endl;
}
else if(bempty && !isExitWriteData2Disk)
{
continue;
}
r_qtx.lock();
DataBuffer * buffer = m_q->front();
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*m_iNumber_WriteDisk);
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遥控器
@ -886,24 +1029,30 @@ void WriteData2Disk::write2Disk()
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
fwrite(dataBuffer,1,m_iFrameSizeInByte*m_iNumber_WriteDisk, hFile);
fwrite(dataBuffer,1,m_iFrameSizeInByte*frameNumber, hFile);
frameCounter++;
}
m_rgbImage->m_VideoWriter.release();
fclose(hFile);
delete[] dataBuffer;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter*m_iNumber_WriteDisk <<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,fwrite 调用次数:" << frameCounter <<std::endl;
}
void WriteData2Disk::exitWriteData2Disk()
{
std::cout<< "执行函数WriteData2Disk::exitWriteData2Disk" <<std::endl;
isExitWriteData2Disk = true;
}
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
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;