From 18dcefb2272c992f596c2198cba04029b8ba8706 Mon Sep 17 00:00:00 2001 From: Jackey Lea <1768478912@qq.com> Date: Fri, 1 Nov 2024 17:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=95=8C=E9=9D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindViewer/dataparser.cpp | 31 +++++++++++++++++++++++++++++++ MindViewer/dataparser.h | 6 ++++++ MindViewer/mainwidget.cpp | 24 ++++++++++++++++++++++++ MindViewer/mainwidget.ui | 12 ++++++++++++ 4 files changed, 73 insertions(+) diff --git a/MindViewer/dataparser.cpp b/MindViewer/dataparser.cpp index 4812e1f..d7da175 100644 --- a/MindViewer/dataparser.cpp +++ b/MindViewer/dataparser.cpp @@ -9,6 +9,8 @@ DataParser::DataParser() ,m_total(0) ,m_loss(0) ,m_rawCnt(0) + ,m_eType(None) + ,m_bSave(false) { //初始化数据 mBuff.clear(); @@ -18,6 +20,13 @@ DataParser::DataParser() DataParser::~DataParser() { + if(!m_bSave){ + if(file.isOpen()){ + file.remove(); + } + } + file.close(); + if(m_comRetriver){ m_comRetriver->stopCOM(); m_comRetriver->deleteLater(); @@ -29,6 +38,12 @@ DataParser::~DataParser() } } +void DataParser::saveLocalFile() +{ + file.close(); + m_bSave = true; +} + void DataParser::setFilePath(QString path) { m_filePath = path; @@ -36,10 +51,12 @@ void DataParser::setFilePath(QString path) void DataParser::setSource(DataSourceType type) { + m_eType = type; switch(type){ case None: break; case COM: + { if(!m_comRetriver){ m_comRetriver = new Retriver(NULL); } @@ -52,8 +69,16 @@ void DataParser::setSource(DataSourceType type) if(m_lf){ m_lf->disconnect(); } + //本地文件 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss")+".txt"; + QFile file(fileName); + if(!file.open(QFile::WriteOnly)){ + qDebug()<<"Cannot open local file."; + } break; + } case Sim: + { if(!m_sim){ m_sim = new Simulator(); } @@ -66,7 +91,9 @@ void DataParser::setSource(DataSourceType type) m_comRetriver->disconnect(); } break; + } case Local: + { if(!m_lf){ m_lf = new LocalFile(m_filePath); } @@ -81,6 +108,7 @@ void DataParser::setSource(DataSourceType type) } break; } + } } void DataParser::clearBuff() @@ -377,6 +405,9 @@ void DataParser::run() //收到数据后填充至缓存区等待解析 void DataParser::sltRcvData(QByteArray ba) { + if(file.isOpen()){ + file.write(ba); + } m_mutex.lock(); mBuff.append(ba); m_mutex.unlock(); diff --git a/MindViewer/dataparser.h b/MindViewer/dataparser.h index a9a8c91..93d5288 100644 --- a/MindViewer/dataparser.h +++ b/MindViewer/dataparser.h @@ -23,6 +23,8 @@ class DataParser : public QThread DataParser(); ~DataParser(); + void saveLocalFile(); + void setFilePath(QString path); void setSource(DataSourceType type); @@ -70,6 +72,10 @@ private slots: QMutex m_mutex; QString m_filePath; + + DataSourceType m_eType;//当前数据源类型 + QFile file; + bool m_bSave; }; #endif // DATAPARSER_H diff --git a/MindViewer/mainwidget.cpp b/MindViewer/mainwidget.cpp index 9e50148..6488862 100644 --- a/MindViewer/mainwidget.cpp +++ b/MindViewer/mainwidget.cpp @@ -81,6 +81,14 @@ void MainWidget::sltBtnLocal() void MainWidget::sltBtnPlay() { + if(m_eType == None){ + QMessageBox::warning(this,tr("警告"),tr("请先选择数据源")); + return; + } + if(m_bStatus){ + QMessageBox::warning(this,tr("警告"),tr("当前处于运行状态")); + return; + } m_bStatus = true; ui->labelStatusValue->setText("运行"); sltBtnClear(); @@ -88,12 +96,24 @@ void MainWidget::sltBtnPlay() void MainWidget::sltBtnPause() { + if(m_eType == None){ + QMessageBox::warning(this,tr("警告"),tr("请先选择数据源")); + return; + } + if(!m_bStatus){ + QMessageBox::warning(this,tr("警告"),tr("当前处于暂停状态")); + return; + } m_bStatus = false; ui->labelStatusValue->setText("暂停"); } void MainWidget::sltBtnClear() { + if(m_eType == None){ + QMessageBox::warning(this,tr("警告"),tr("当前无数据可清理")); + return; + } //清空界面 ui->labelPowerValue->setText("0"); ui->labelSignalValue->setText("0"); @@ -108,6 +128,10 @@ void MainWidget::sltBtnClear() void MainWidget::sltBtnSave() { + if(m_eType == None){ + QMessageBox::warning(this,tr("警告"),tr("当前无数据可保存")); + return; + } switch(m_eType){ case COM: break; diff --git a/MindViewer/mainwidget.ui b/MindViewer/mainwidget.ui index d303321..14b9749 100644 --- a/MindViewer/mainwidget.ui +++ b/MindViewer/mainwidget.ui @@ -128,6 +128,9 @@ QFrame#frameCurve{ 64 + + 运行 + @@ -151,6 +154,9 @@ QFrame#frameCurve{ 64 + + 暂停 + @@ -184,6 +190,9 @@ QFrame#frameCurve{ 清空数据 + + 清空缓存 + @@ -210,6 +219,9 @@ QFrame#frameCurve{ 保存数据 + + 保存数据 +