2025-03-19T15:19:44
This commit is contained in:
parent
6cc70a2327
commit
d985a8b39e
5585
experiment_data/analysis_state/sampleName_20250319_131239.txt
Normal file
5585
experiment_data/analysis_state/sampleName_20250319_131239.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -67,4 +67,39 @@ void fileClose()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void readExperimentFile(const QString fileName, QVector<ExperimentData> &dataVtr)
|
||||||
|
{
|
||||||
|
if(fileName.isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_expeFile.isOpen()){
|
||||||
|
_expeFile.close();
|
||||||
|
}
|
||||||
|
_expeFile.setFileName(fileName);
|
||||||
|
// 尝试以写入文本模式打开文件,如果文件不存在则创建它
|
||||||
|
if (!_expeFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
qDebug() << "FileManager file open failed.";
|
||||||
|
} else {
|
||||||
|
qDebug() << "FileManager file open succ.";
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextStream in(&_expeFile);
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
QString line = in.readLine();
|
||||||
|
QStringList values = line.split(" ");
|
||||||
|
if (values.size() == 2) {
|
||||||
|
ExperimentData data;
|
||||||
|
data.sampleTemp = values[0].toFloat();
|
||||||
|
data.dsc = values[1].toFloat();
|
||||||
|
// dataVtr.append(data);
|
||||||
|
dataVtr.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_expeFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,20 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <qdir.h>
|
||||||
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
namespace FileManager{
|
namespace FileManager{
|
||||||
|
const QString ExperimentDirPath = QDir::currentPath()+"/../experiment_data";
|
||||||
|
const QString SampleDataFloder = ExperimentDirPath + "/sample_data";
|
||||||
|
const QString BaseLineFolder = ExperimentDirPath + "/base_line";
|
||||||
|
const QString AnalysisStateFolder = ExperimentDirPath + "/analysis_state";
|
||||||
|
|
||||||
|
struct ExperimentData {
|
||||||
|
float sampleTemp;
|
||||||
|
float dsc;
|
||||||
|
};
|
||||||
struct ExpeInfo
|
struct ExpeInfo
|
||||||
{
|
{
|
||||||
QString sampleName;
|
QString sampleName;
|
||||||
@ -21,6 +31,8 @@ void createExperimentFile();
|
|||||||
void writeExperimentFile(const CommonData&);
|
void writeExperimentFile(const CommonData&);
|
||||||
void fileClose();
|
void fileClose();
|
||||||
|
|
||||||
|
void readExperimentFile(const QString fileName,QVector<ExperimentData>&);
|
||||||
|
|
||||||
void test();
|
void test();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <qdir.h>
|
||||||
|
#include <qdebug.h>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "centralwidget.h"
|
#include "centralwidget.h"
|
||||||
|
|||||||
@ -43,7 +43,7 @@ void MainWindow::connections()
|
|||||||
#if 1
|
#if 1
|
||||||
// dynamic data
|
// dynamic data
|
||||||
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
||||||
_centralWidget, &CentralWidget::slotRevCommonData);
|
_centralWidget, &CentralWidget::slotRecvCommonData);
|
||||||
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
||||||
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
||||||
|
|
||||||
@ -58,6 +58,9 @@ void MainWindow::connections()
|
|||||||
// mode
|
// mode
|
||||||
connect(Global::instance(), &Global::sigModeModify,
|
connect(Global::instance(), &Global::sigModeModify,
|
||||||
_centralWidget, &CentralWidget::slotModeModify);
|
_centralWidget, &CentralWidget::slotModeModify);
|
||||||
|
//analysis
|
||||||
|
connect(_leftWidget,&LeftWidget::sigSendAnalysisFileName,
|
||||||
|
_centralWidget,&CentralWidget::slotRecvAnalysisFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setActionEnable(const bool flag)
|
void MainWindow::setActionEnable(const bool flag)
|
||||||
|
|||||||
@ -36,37 +36,7 @@ namespace DataParser
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
bool DataParser::slotDataParser(const QByteArray &ba)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
SerialPortProtocol spp;
|
|
||||||
memcpy(&spp,ba.data(),ba.size());
|
|
||||||
#endif
|
|
||||||
SerialPortProtocol *spp = (SerialPortProtocol *)ba.data();
|
|
||||||
int length = spp->len - 5;
|
|
||||||
|
|
||||||
CommonData cd;
|
|
||||||
u8* cdPtr = (u8*)&cd;
|
|
||||||
|
|
||||||
memcpy(cdPtr + spp->addr,spp->data_buf,length);
|
|
||||||
|
|
||||||
qDebug()<<"revDataParser run_type:"<<cd.run_mode;
|
|
||||||
|
|
||||||
while(length){
|
|
||||||
switch(spp->addr){
|
|
||||||
case offsetof(CommonData,run_mode):
|
|
||||||
Global::Mode mode = (Global::Mode)cd.run_mode;
|
|
||||||
length--;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void writeData(const QByteArray &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray connectToDevice(const QVector<Phase> &vtr)
|
QByteArray connectToDevice(const QVector<Phase> &vtr)
|
||||||
{
|
{
|
||||||
@ -206,4 +176,18 @@ bool DataParser::slotDataParser(const QByteArray &ba)
|
|||||||
return QByteArray((char *)&spp, sppValidLength) +
|
return QByteArray((char *)&spp, sppValidLength) +
|
||||||
QByteArray((char *)&crc, 2);
|
QByteArray((char *)&crc, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isDevExperimentEnded(const CommonData &cd)
|
||||||
|
{
|
||||||
|
switch(cd.run_type){
|
||||||
|
case DeviceRunStatus::Idle:
|
||||||
|
case DeviceRunStatus::Cooling:
|
||||||
|
Global::instance()->setMode(Global::Mode::Analysis);
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,8 +13,8 @@ QByteArray connectToDevice(const QVector<Phase>&);
|
|||||||
QByteArray inquirePhaseInfo();
|
QByteArray inquirePhaseInfo();
|
||||||
QByteArray setDeviceStartStop(const DeviceStartMode);
|
QByteArray setDeviceStartStop(const DeviceStartMode);
|
||||||
|
|
||||||
|
bool isDevExperimentEnded(const CommonData&cd);
|
||||||
bool commonDataParser(const QByteArray&ba,CommonData &cd);
|
bool commonDataParser(const QByteArray&ba,CommonData &cd);
|
||||||
void writeData(const QByteArray&);
|
|
||||||
|
|
||||||
unsigned short modbusCRC16(unsigned char *data,unsigned short length);
|
unsigned short modbusCRC16(unsigned char *data,unsigned short length);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,7 +101,6 @@ void SerialPort::slotReadData()
|
|||||||
#if 1
|
#if 1
|
||||||
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
||||||
qDebug() << "receive info (hex):" << hexData;
|
qDebug() << "receive info (hex):" << hexData;
|
||||||
return;
|
|
||||||
#endif
|
#endif
|
||||||
SerialPortProtocol *spp = (SerialPortProtocol *)ba.data();
|
SerialPortProtocol *spp = (SerialPortProtocol *)ba.data();
|
||||||
if (FRANE_HEAD != spp->head)
|
if (FRANE_HEAD != spp->head)
|
||||||
@ -129,7 +128,7 @@ void SerialPort::slotReadData()
|
|||||||
else if (READ_CMD == spp->cmd)
|
else if (READ_CMD == spp->cmd)
|
||||||
{
|
{
|
||||||
// judge the device status.
|
// judge the device status.
|
||||||
commonDataParser(dataLength, spp->addr, cd);
|
DataParser::isDevExperimentEnded(cd);
|
||||||
// read data
|
// read data
|
||||||
if (spp->addr == 0)
|
if (spp->addr == 0)
|
||||||
{
|
{
|
||||||
@ -166,6 +165,7 @@ void SerialPort::commonDataParser(const int dataLength, const u16 addr,
|
|||||||
|
|
||||||
while (localLength)
|
while (localLength)
|
||||||
{
|
{
|
||||||
|
qDebug()<<"localLength:"<<localLength;
|
||||||
switch (localAddr)
|
switch (localAddr)
|
||||||
{
|
{
|
||||||
case offsetof(CommonData, run_type): // 运行状态
|
case offsetof(CommonData, run_type): // 运行状态
|
||||||
|
|||||||
@ -61,7 +61,7 @@ void CentralWidget::slotModeModify(const Global::Mode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CentralWidget::slotRevCommonData(const CommonData &cd)
|
void CentralWidget::slotRecvCommonData(const CommonData &cd)
|
||||||
{
|
{
|
||||||
qDebug()<<"slotRevCommonData";
|
qDebug()<<"slotRevCommonData";
|
||||||
_customPlot->graph(0)->addData(cd.sample_temp, cd.dsc); // 添加数据到曲线
|
_customPlot->graph(0)->addData(cd.sample_temp, cd.dsc); // 添加数据到曲线
|
||||||
@ -70,6 +70,39 @@ void CentralWidget::slotRevCommonData(const CommonData &cd)
|
|||||||
FileManager::writeExperimentFile(cd);
|
FileManager::writeExperimentFile(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
|
||||||
|
{
|
||||||
|
qDebug()<<"slotRecvAnalysisFileName"<<fileName;
|
||||||
|
|
||||||
|
QVector<FileManager::ExperimentData> dataVtr;
|
||||||
|
FileManager::readExperimentFile(fileName,dataVtr);
|
||||||
|
|
||||||
|
if(dataVtr.size() < 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//判断界面上是不是有曲线,有的话先删除。
|
||||||
|
_customPlot->clearGraphs();
|
||||||
|
|
||||||
|
// 创建画布,设置画布上的点数据
|
||||||
|
_customPlot->addGraph();
|
||||||
|
|
||||||
|
// 设置坐标轴标签
|
||||||
|
_customPlot->yAxis->setLabel("DSC/mW");
|
||||||
|
_customPlot->xAxis->setLabel("Temp/℃");
|
||||||
|
// 设置坐标轴范围,以便我们可以看到全部数据
|
||||||
|
_customPlot->xAxis->setRange(0, 400);
|
||||||
|
_customPlot->yAxis->setRange(-20, 20);
|
||||||
|
|
||||||
|
QVector<double> xVtr,yVtr;
|
||||||
|
for(FileManager::ExperimentData &ed:dataVtr){
|
||||||
|
xVtr.push_back(ed.sampleTemp);
|
||||||
|
yVtr.push_back(ed.dsc);
|
||||||
|
}
|
||||||
|
|
||||||
|
_customPlot->graph(0)->addData(xVtr,yVtr);
|
||||||
|
_customPlot->replot();
|
||||||
|
}
|
||||||
|
|
||||||
void CentralWidget::timerEvent(QTimerEvent *event)
|
void CentralWidget::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
// key的单位是秒
|
// key的单位是秒
|
||||||
|
|||||||
@ -15,7 +15,8 @@ public:
|
|||||||
~CentralWidget();
|
~CentralWidget();
|
||||||
public slots:
|
public slots:
|
||||||
void slotModeModify(const Global::Mode);
|
void slotModeModify(const Global::Mode);
|
||||||
void slotRevCommonData(const CommonData&);
|
void slotRecvCommonData(const CommonData&);
|
||||||
|
void slotRecvAnalysisFileName(const QString&);
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent* event);
|
void timerEvent(QTimerEvent* event);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -3,10 +3,8 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
#include "leftwidget.h"
|
#include "leftwidget.h"
|
||||||
|
#include "filemanager.h"
|
||||||
const QString sampleDataFloder = QDir::currentPath()+"/../experiment_data/sample_data";
|
#include "global.h"
|
||||||
const QString baseLineFolder = QDir::currentPath()+"/../experiment_data/base_line";
|
|
||||||
const QString analysisStateFolder = QDir::currentPath()+"/../experiment_data/analysis_state";
|
|
||||||
|
|
||||||
LeftWidget::LeftWidget()
|
LeftWidget::LeftWidget()
|
||||||
{
|
{
|
||||||
@ -23,36 +21,25 @@ LeftWidget::LeftWidget()
|
|||||||
_sampleDataItem->setText(0,"样品数据");
|
_sampleDataItem->setText(0,"样品数据");
|
||||||
|
|
||||||
_treeWidget->setSortingEnabled(false);
|
_treeWidget->setSortingEnabled(false);
|
||||||
// _treeWidget->insertTopLevelItem(0,_sampleDataItem);
|
|
||||||
// _treeWidget->insertTopLevelItem(1,_baseLineItem);
|
|
||||||
// _treeWidget->insertTopLevelItem(2,_analysisStateItem);
|
|
||||||
|
|
||||||
_treeWidget->addTopLevelItem(_sampleDataItem);
|
_treeWidget->addTopLevelItem(_sampleDataItem);
|
||||||
_treeWidget->addTopLevelItem(_baseLineItem);
|
_treeWidget->addTopLevelItem(_baseLineItem);
|
||||||
_treeWidget->addTopLevelItem(_analysisStateItem);
|
_treeWidget->addTopLevelItem(_analysisStateItem);
|
||||||
|
|
||||||
|
setWidget(_treeWidget);
|
||||||
#if 0
|
|
||||||
qDebug()<<"current path:"<<QDir::currentPath();
|
|
||||||
QString folderPath = QDir::currentPath()+"/../experiment_data";
|
|
||||||
qDebug()<<"experit dir:"<<folderPath;
|
|
||||||
|
|
||||||
QDir dir(folderPath);
|
|
||||||
|
|
||||||
qDebug()<<"folderPath exist:"<< dir.exists();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//init file name.
|
//init file name.
|
||||||
initFileName(_sampleDataItem,sampleDataFloder);
|
initFileName(_sampleDataItem,FileManager::SampleDataFloder);
|
||||||
initFileName(_baseLineItem,baseLineFolder);
|
initFileName(_baseLineItem,FileManager::BaseLineFolder);
|
||||||
initFileName(_analysisStateItem,analysisStateFolder);
|
initFileName(_analysisStateItem,FileManager::AnalysisStateFolder);
|
||||||
|
|
||||||
expandAll(_sampleDataItem);
|
expandAll(_sampleDataItem);
|
||||||
expandAll(_baseLineItem);
|
expandAll(_baseLineItem);
|
||||||
expandAll(_analysisStateItem);
|
expandAll(_analysisStateItem);
|
||||||
|
|
||||||
setWidget(_treeWidget);
|
//connections
|
||||||
|
connect(_treeWidget,&QTreeWidget::itemClicked,
|
||||||
|
this,&LeftWidget::slotTreeWidgetItemClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeftWidget::initData()
|
void LeftWidget::initData()
|
||||||
@ -87,9 +74,33 @@ void LeftWidget::initData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
void LeftWidget::slotTreeWidgetItemClicked(QTreeWidgetItem *item, int column){
|
||||||
|
qDebug()<<"item clicked:"<<item->text(0)<<column;
|
||||||
|
|
||||||
|
if(Global::Mode::Analysis != Global::instance()->getMode()){
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString fileName;
|
||||||
|
// 获取父节点
|
||||||
|
QTreeWidgetItem *parentItem = item->parent();
|
||||||
|
if (parentItem) {
|
||||||
|
qDebug() << "parent item text:" << parentItem->text(0);
|
||||||
|
if(parentItem == _sampleDataItem){
|
||||||
|
fileName =FileManager::SampleDataFloder + "/" + item->text(0);
|
||||||
|
}else if(parentItem == _baseLineItem){
|
||||||
|
fileName =FileManager::BaseLineFolder + "/" +item->text(0);
|
||||||
|
}else if(parentItem == _analysisStateItem){
|
||||||
|
fileName =FileManager::AnalysisStateFolder + "/" +item->text(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "item has no parent (it is a top-level item)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit sigSendAnalysisFileName(fileName);
|
||||||
|
}
|
||||||
void LeftWidget::initFileName(QTreeWidgetItem* parentItem,const QString &folderPath)
|
void LeftWidget::initFileName(QTreeWidgetItem* parentItem,const QString &folderPath)
|
||||||
{
|
{
|
||||||
QDir dir(folderPath);
|
QDir dir(folderPath);
|
||||||
|
|||||||
@ -15,6 +15,11 @@ private:
|
|||||||
void initData();
|
void initData();
|
||||||
void initFileName(QTreeWidgetItem*,const QString &folderPath);
|
void initFileName(QTreeWidgetItem*,const QString &folderPath);
|
||||||
void expandAll(QTreeWidgetItem* item);
|
void expandAll(QTreeWidgetItem* item);
|
||||||
|
signals:
|
||||||
|
void sigSendAnalysisFileName(const QString&);
|
||||||
|
protected:
|
||||||
|
private slots:
|
||||||
|
void slotTreeWidgetItemClicked(QTreeWidgetItem *item, int column);
|
||||||
private:
|
private:
|
||||||
QTreeWidget *_treeWidget;
|
QTreeWidget *_treeWidget;
|
||||||
QTreeWidgetItem *_analysisStateItem,
|
QTreeWidgetItem *_analysisStateItem,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user