diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/conf/config.ini b/conf/config.ini index 377091c..d840662 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,20 +1,20 @@ -[net] -type="serial" -deviceHost="192.168.1.20" +[net] +deviceHost=192.168.1.20 devicePort=233 -listenPort=243 +listenPort=24331 [com] -portName="COM1" +portName=COM3 baudRate=115200 [dev] +type=0 channelCount=16 skipHeader=5 maxCount=86400 [log] -basePath="/home/admin/Qt/ZXSSCJ-Release/PhaseCompAcq/logs/" +basePath=C:/casic/logs/ [delay] -delayArr="0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00" +delayArr="178,200,0.00,0.00,0.00,0.00,0.00,0.00,-26,0.00,0.00,0.00,0.00,0.00,0.00,0.00" diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/conf/config.ini b/conf/config.ini index 377091c..d840662 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,20 +1,20 @@ -[net] -type="serial" -deviceHost="192.168.1.20" +[net] +deviceHost=192.168.1.20 devicePort=233 -listenPort=243 +listenPort=24331 [com] -portName="COM1" +portName=COM3 baudRate=115200 [dev] +type=0 channelCount=16 skipHeader=5 maxCount=86400 [log] -basePath="/home/admin/Qt/ZXSSCJ-Release/PhaseCompAcq/logs/" +basePath=C:/casic/logs/ [delay] -delayArr="0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00" +delayArr="178,200,0.00,0.00,0.00,0.00,0.00,0.00,-26,0.00,0.00,0.00,0.00,0.00,0.00,0.00" diff --git a/images/phaseMeasure.png b/images/phaseMeasure.png index 184237b..18b96ff 100644 --- a/images/phaseMeasure.png +++ b/images/phaseMeasure.png Binary files differ diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/conf/config.ini b/conf/config.ini index 377091c..d840662 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,20 +1,20 @@ -[net] -type="serial" -deviceHost="192.168.1.20" +[net] +deviceHost=192.168.1.20 devicePort=233 -listenPort=243 +listenPort=24331 [com] -portName="COM1" +portName=COM3 baudRate=115200 [dev] +type=0 channelCount=16 skipHeader=5 maxCount=86400 [log] -basePath="/home/admin/Qt/ZXSSCJ-Release/PhaseCompAcq/logs/" +basePath=C:/casic/logs/ [delay] -delayArr="0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00" +delayArr="178,200,0.00,0.00,0.00,0.00,0.00,0.00,-26,0.00,0.00,0.00,0.00,0.00,0.00,0.00" diff --git a/images/phaseMeasure.png b/images/phaseMeasure.png index 184237b..18b96ff 100644 --- a/images/phaseMeasure.png +++ b/images/phaseMeasure.png Binary files differ diff --git a/protocol/PhaseProtocolBM.cpp b/protocol/PhaseProtocolBM.cpp index 0518f5a..93a2187 100644 --- a/protocol/PhaseProtocolBM.cpp +++ b/protocol/PhaseProtocolBM.cpp @@ -1,5 +1,4 @@ #include "PhaseProtocolBM.h" -#include PhaseProtocolBM::PhaseProtocolBM(QObject *parent) : QObject(parent) { diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/conf/config.ini b/conf/config.ini index 377091c..d840662 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,20 +1,20 @@ -[net] -type="serial" -deviceHost="192.168.1.20" +[net] +deviceHost=192.168.1.20 devicePort=233 -listenPort=243 +listenPort=24331 [com] -portName="COM1" +portName=COM3 baudRate=115200 [dev] +type=0 channelCount=16 skipHeader=5 maxCount=86400 [log] -basePath="/home/admin/Qt/ZXSSCJ-Release/PhaseCompAcq/logs/" +basePath=C:/casic/logs/ [delay] -delayArr="0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00" +delayArr="178,200,0.00,0.00,0.00,0.00,0.00,0.00,-26,0.00,0.00,0.00,0.00,0.00,0.00,0.00" diff --git a/images/phaseMeasure.png b/images/phaseMeasure.png index 184237b..18b96ff 100644 --- a/images/phaseMeasure.png +++ b/images/phaseMeasure.png Binary files differ diff --git a/protocol/PhaseProtocolBM.cpp b/protocol/PhaseProtocolBM.cpp index 0518f5a..93a2187 100644 --- a/protocol/PhaseProtocolBM.cpp +++ b/protocol/PhaseProtocolBM.cpp @@ -1,5 +1,4 @@ #include "PhaseProtocolBM.h" -#include PhaseProtocolBM::PhaseProtocolBM(QObject *parent) : QObject(parent) { diff --git a/qss/dlgdark.css b/qss/dlgdark.css index c28364f..4e8e406 100644 --- a/qss/dlgdark.css +++ b/qss/dlgdark.css @@ -4,13 +4,54 @@ border-radius: 0px; } -QWidget#inputWgt QLineEdit { +QWidget#configItemWgt QLineEdit { background: #2f3542; color: #e8eaee; border:1px solid #57606f; - border-radius: 4px; + border-radius: 8px; } QDialogButtonBox#buttonBox { background: #2f3542; -} \ No newline at end of file +} + +QDialogButtonBox#buttonBox QPushButton { + font-size: 16px; + min-height: 30px; + min-width: 100px; +} + +QComboBox { + background: #2f3542; + color: #e8eaee; + border:1px solid #57606f; + border-radius: 8px; + + font-size: 16px; + font-family: "Microsoft YaHei"; + padding: 6px; +} + +QComboBox::down-arrow { + image: url(":/css/images/add_bottom.png"); +} + +QComboBox::down-arrow::on { + image: url(":/css/images/add_top.png"); +} + +QComboBox::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 20px; + border: 0px; + padding-right: 15px; +} + +QComboBox QAbstractItemView { + color: #6868A6; + background-color: #E1E1ED; + selection-background-color: #A4A4CA; + selection-color: #FFFFFF; + font-family: "Microsoft YaHei"; +} diff --git a/AppConstant.h b/AppConstant.h new file mode 100644 index 0000000..53d7a33 --- /dev/null +++ b/AppConstant.h @@ -0,0 +1,12 @@ +#ifndef APPCONSTANT_H +#define APPCONSTANT_H + +enum ENUM_NET_TYPE { + SERIAL, + UDPServer, + UDPClient, + TCPServer, + TCPClient +}; + +#endif // APPCONSTANT_H diff --git a/AppInit.cpp b/AppInit.cpp index a267f77..e4e88b5 100644 --- a/AppInit.cpp +++ b/AppInit.cpp @@ -1,4 +1,4 @@ -#include "appinit.h" +#include "AppInit.h" #include "qmutex.h" #include "qapplication.h" #include "qevent.h" diff --git a/ChannelCharts.cpp b/ChannelCharts.cpp index 5b709f6..9ec79ad 100644 --- a/ChannelCharts.cpp +++ b/ChannelCharts.cpp @@ -1,7 +1,6 @@ #include "ChannelCharts.h" #include "ui_ChannelCharts.h" -#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" @@ -78,38 +77,39 @@ ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); - double minTm = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(0).toLongLong() / 1000; - double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; - double minValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - double maxValue = phaseVector[index].at(SettingConfig::getInstance().SKIP_HEADER).at(1).toDouble(); - QVector vecPoints; + if (phaseVector[index].isEmpty() == false) { + double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; + double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; + double minValue = phaseVector[index].first().at(1).toDouble(); + double maxValue = phaseVector[index].first().at(1).toDouble(); + QVector vecPoints; - for (int i = SettingConfig::getInstance().SKIP_HEADER; i < phaseVector[index].size(); i++) - { - // 新的数据点 - QCPGraphData onePoint; - - QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 - onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); - onePoint.value = phaseVector[index].at(i).at(1).toDouble(); - - vecPoints.append(onePoint); - - if (phaseVector[index].at(i).at(1).toDouble() < minValue) + for (int i = 0; i < phaseVector[index].size(); i++) { - minValue = phaseVector[index][i].at(1).toDouble(); - } + // 新的数据点 + QCPGraphData onePoint; - if (phaseVector[index].at(i).at(1).toDouble() > maxValue) - { - maxValue = phaseVector[index][i].at(1).toDouble(); + QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 + onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); + onePoint.value = phaseVector[index].at(i).at(1).toDouble(); + + vecPoints.append(onePoint); + + if (phaseVector[index].at(i).at(1).toDouble() < minValue) + { + minValue = phaseVector[index][i].at(1).toDouble(); + } + + if (phaseVector[index].at(i).at(1).toDouble() > maxValue) + { + maxValue = phaseVector[index][i].at(1).toDouble(); + } } + graph->data()->clear(); + graph->data()->set(vecPoints, true); + ui->dataPlot->xAxis->setRange(minTm, maxTm); + ui->dataPlot->yAxis->setRange(minValue, maxValue); } - graph->data()->clear(); - graph->data()->set(vecPoints, true); - ui->dataPlot->xAxis->setRange(minTm, maxTm); - ui->dataPlot->yAxis->setRange(minValue, maxValue); - ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index f6cede4..5cca632 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -47,11 +47,11 @@ ui->samplingThou->setText(QString::number((int)size/1000)); ui->samplingTT->setText(QString::number((int)size/10000)); - ui->stabilityOne->setText(QString::number(channelAllan.at(index).at(0), 'e', 4)); // 科学计数法显示 - ui->stabilityTen->setText(QString::number(channelAllan.at(index).at(1), 'e', 4)); - ui->stabilityHund->setText(QString::number(channelAllan.at(index).at(2), 'e', 4)); - ui->stabilityThou->setText(QString::number(channelAllan.at(index).at(3), 'e', 4)); - ui->stabilityTT->setText(QString::number(channelAllan.at(index).at(4), 'e', 4)); + ui->stabilityOne->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(0), 'e', 4) : "0.0000"); // 科学计数法显示 + ui->stabilityTen->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(1), 'e', 4) : "0.0000"); + ui->stabilityHund->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(2), 'e', 4) : "0.0000"); + ui->stabilityThou->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(3), 'e', 4) : "0.0000"); + ui->stabilityTT->setText(channelAllan.at(index).isEmpty() == false ? QString::number(channelAllan.at(index).at(4), 'e', 4) : "0.0000"); } void ChannelItem::on_delay_valueChanged(int value) diff --git a/DoubleClickInput.cpp b/DoubleClickInput.cpp new file mode 100644 index 0000000..86efdc8 --- /dev/null +++ b/DoubleClickInput.cpp @@ -0,0 +1,16 @@ +#include "DoubleClickInput.h" + +DoubleClickInput::DoubleClickInput(QWidget * parent) : QLineEdit(parent) +{ + +} + +DoubleClickInput::~DoubleClickInput() +{ + +} + +void DoubleClickInput::mouseDoubleClickEvent(QMouseEvent *event) +{ + emit doubleClicked(); +} diff --git a/DoubleClickInput.h b/DoubleClickInput.h new file mode 100644 index 0000000..b5bcf1d --- /dev/null +++ b/DoubleClickInput.h @@ -0,0 +1,20 @@ +#ifndef DOUBLECLICKINPUT_H +#define DOUBLECLICKINPUT_H + +#include +#include + +class DoubleClickInput : public QLineEdit +{ + Q_OBJECT +public: + DoubleClickInput(QWidget * parent = 0); + ~DoubleClickInput(); + + void mouseDoubleClickEvent(QMouseEvent * event); + +signals: + void doubleClicked(); +}; + +#endif // DOUBLECLICKINPUT_H diff --git a/IconHelper.cpp b/IconHelper.cpp index e548117..9e69545 100644 --- a/IconHelper.cpp +++ b/IconHelper.cpp @@ -1,4 +1,4 @@ -#include "iconhelper.h" +#include "IconHelper.h" IconHelper *IconHelper::self = 0; IconHelper *IconHelper::Instance() diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index e2f04a5..6868bc9 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -1,7 +1,6 @@ #include "PhaseDevice.h" #include "common/utils/QLogUtil.h" -#include #include #include #include @@ -13,48 +12,68 @@ QVector> channelAllan(PHASE_MESSURE_CHANNEL, QVector(0, 0)); QVector> channelAllenSigma(PHASE_MESSURE_CHANNEL, QVector(5, 0.0)); -int frameCount = 0; - PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil = new UDPClientUtil(this); - connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { - serialUtil = new QSerialPortUtil(this); - serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); - connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } + } PhaseDevice::~PhaseDevice() { - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } } -void PhaseDevice::startWork() +bool PhaseDevice::startWork() { QString startCmd = PhaseProtocolBM::startMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(startCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: + serialUtil = new QSerialPortUtil(this); + + connect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + serialUtil->openSerialPort(SettingConfig::getInstance().PORT_NAME, SettingConfig::getInstance().BAUD_RATE); serialUtil->sendData(startCmd.toLocal8Bit()); + + return serialUtil->isOpen(); + case 1: + clientUtil = new UDPClientUtil(this); + connect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + clientUtil->sendData(startCmd.toLocal8Bit()); + break; + default: + break; } + return false; } void PhaseDevice::stopWork() { QString stopCmd = PhaseProtocolBM::stopMessure(); - if (SettingConfig::getInstance().NET_TYPE.toUpper() == "UDP") { - clientUtil->sendData(stopCmd.toLocal8Bit()); - } else if (SettingConfig::getInstance().NET_TYPE.toUpper() == "SERIAL") { + + switch (SettingConfig::getInstance().NET_TYPE) { + case 0: serialUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(serialUtil, &QSerialPortUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + case 1: + clientUtil->sendData(stopCmd.toLocal8Bit()); + disconnect(clientUtil, &UDPClientUtil::dataRecieved, this, &PhaseDevice::dataReceivedHandler); + break; + default: + break; } + + frameCount = 0; } void PhaseDevice::dataReceivedHandler(QByteArray data) @@ -72,6 +91,13 @@ // 解析成功 if (parse == true) { + // 过滤前面几帧数据 + frameCount++; + if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) + { + return ; + } + QDateTime now = QDateTime::currentDateTime(); phaseData->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); phaseData->milisecond = now.toMSecsSinceEpoch(); @@ -79,7 +105,7 @@ } } else if (this->dataBuff.size() > PHASE_FRAM_LENGTH) { - std::cout << QString("%1").arg(this->dataBuff.size()).toStdString() << std::endl; + qDebug() << QString("%1").arg(this->dataBuff.size()); this->dataBuff.clear(); } @@ -102,13 +128,6 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); - // 过滤前面几帧数据 - frameCount++; - if (frameCount <= SettingConfig::getInstance().SKIP_HEADER) - { - return ; - } - QVector vectorZero(5); QVector vector(5); diff --git a/PhaseDevice.h b/PhaseDevice.h index 3e53fd0..18dd5ec 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -15,7 +15,7 @@ explicit PhaseDevice(QObject *parent = nullptr); ~PhaseDevice(); - void startWork(); + bool startWork(); void stopWork(); void afterFramePhase(PhaseDataDto * phaseData); @@ -25,6 +25,8 @@ QByteArray dataBuff; + int frameCount = 0; + signals: void sendDataToDraw(PhaseDataDto * phaseData); diff --git a/PhaseMeasure.pro b/PhaseMeasure.pro index 8aa03da..76061d0 100644 --- a/PhaseMeasure.pro +++ b/PhaseMeasure.pro @@ -13,6 +13,7 @@ include(protocol/protocol.pri) include(QCustomPlot/QCustomPlot.pri) +HEADERS += AppConstant.h HEADERS += AppInit.h HEADERS += IconHelper.h HEADERS += PhaseDevice.h @@ -21,6 +22,7 @@ HEADERS += PhaseWindow.h HEADERS += SetConfig.h HEADERS += DataProcessAlgorithm.h +HEADERS += DoubleClickInput.h SOURCES += AppInit.cpp SOURCES += IconHelper.cpp @@ -30,6 +32,7 @@ SOURCES += PhaseWindow.cpp SOURCES += SetConfig.cpp SOURCES += DataProcessAlgorithm.cpp +SOURCES += DoubleClickInput.cpp SOURCES += main.cpp # Default rules for deployment. @@ -42,4 +45,4 @@ DISTFILES += qss/dlgdark.css RESOURCES += images.qrc -#RC_ICONS = PhaseMeasure.ico +RC_ICONS = PhaseMeasure.ico diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index b238709..04d5f35 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -1,7 +1,6 @@ #include "PhaseWindow.h" #include "ui_PhaseWindow.h" -#include #include #include #include @@ -14,14 +13,13 @@ #include #include #include +#include #include "IconHelper.h" #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" QString currentFileName = ""; -qint16 screenWidth = 0; -qint16 screenHeight = 0; boolean running = false; PhaseWindow::PhaseWindow(QWidget *parent) : @@ -30,12 +28,9 @@ { ui->setupUi(this); - QRect screenRect = QApplication::desktop()->availableGeometry(); - screenWidth = screenRect.width(); - screenHeight = screenRect.height(); + device = new PhaseDevice(this); this->initForm(); - this->initDeivce(); this->generateWidgetForDevice(); } @@ -52,6 +47,10 @@ ui->widgetTop->setProperty("nav", "top"); this->setWindowFlags(Qt::FramelessWindowHint); + QRect screenRect = QApplication::desktop()->availableGeometry(); + qint16 screenWidth = screenRect.width(); + qint16 screenHeight = screenRect.height(); + // 设置窗口位置和大小 move(0, 0); resize(screenWidth, screenHeight); @@ -72,7 +71,7 @@ QFont tmFont("Arial"); tmFont.setPixelSize(16); tmFont.setBold(true); - ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")); + ui->labTm->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd")); ui->labTm->setFont(tmFont); // 设置标题logo @@ -107,7 +106,6 @@ void PhaseWindow::initDeivce() { - device = new PhaseDevice(this); connect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); } @@ -135,6 +133,10 @@ QRect screenRect = QApplication::desktop()->screenGeometry(); + qDeleteAll(ui->scrollContents->children()); + channelGroupList.clear(); + channelItemList.clear(); + ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170); QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents); @@ -164,13 +166,18 @@ } } -void PhaseWindow::createFolder() +bool PhaseWindow::createFolder() { QDir *folder = new QDir; bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + bool ok = false; if(!exist) // 生成base文件夹 { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + if (ok == false) + { + return ok; + } } // 生成当前时间文件夹 @@ -178,12 +185,13 @@ exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(!exist) { - bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); + ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH + fileName); if(ok) { currentFileName = fileName; - QMessageBox::information(this, tr("开始"), tr("开始成功")); } } + + return ok; } @@ -242,28 +250,45 @@ void PhaseWindow::on_startButt_clicked() { - createFolder(); + this->initDeivce(); // 发送开始指令 - device->startWork(); - running = true; + bool succ = device->startWork(); + if (succ == false) { + QMessageBox::warning(this, "开始失败", "开始采集失败,请检查与设备的连接"); + return; + } else { + QMessageBox::information(this, "开始成功", "开始采集成功"); + running = true; + } + + succ = createFolder(); + if (succ == false) { + QMessageBox::warning(this, "记录日志失败", "创建日志文件错误,请检查日志路径配置"); + } } void PhaseWindow::on_endButt_clicked() { currentFileName = ""; + running = false; + + // 发送结束指令 + device->stopWork(); + + disconnect(device, &PhaseDevice::sendDataToDraw, this, &PhaseWindow::drawPhaseDataOnPage); + this->generateWidgetForDevice(); // 清空已经存储的数据 for (int i = 0; i < phaseVector.size(); i++) { phaseVector[i].clear(); - channelAllan[i].clear(); -// channelAllenSigma[i].clear(); + qDebug() << i << channelAllan[i].size() << channelAllenSigma[i].size(); + for (int j = 0; j < channelAllan[i].size(); j++) { + channelAllan[i][j] = 0; + channelAllenSigma[i][j] = 0; + } } - - // 发送结束指令 - device->stopWork(); - running = false; } void PhaseWindow::on_settingButt_clicked() diff --git a/PhaseWindow.h b/PhaseWindow.h index 6fc532c..1fcfeef 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -42,7 +42,7 @@ void initForm(); void initDeivce(); - void createFolder(); + bool createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); void swiftConntrollerButt(); diff --git a/SetConfig.cpp b/SetConfig.cpp index ff5edaf..2e5e9be 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -5,6 +5,10 @@ #include #include #include +#include +#include + +#include "AppConstant.h" extern bool running; @@ -23,7 +27,11 @@ } init(); + + connect(ui->logInput, &DoubleClickInput::doubleClicked, this, &SetConfig::onLogPathInputDoubleClicked); + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); } + void SetConfig::init() { setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 @@ -38,18 +46,39 @@ ui->buttonBox->button(QDialogButtonBox::Ok)->setText("确定"); ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); - ui->ipInput->setText(SettingConfig::getInstance().DEVICE_HOST); - ui->devInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); - ui->listenInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comTypeSelect->addItem("串口", ENUM_NET_TYPE::SERIAL); +// ui->comTypeSelect->addItem("UDP Server", ENUM_NET_TYPE::UDPServer); + + // 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->comTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 40 }); + + if (ui->comTypeSelect->itemData(i).toInt() == SettingConfig::getInstance().NET_TYPE) { + ui->comTypeSelect->setCurrentIndex(i); + } + } + ui->logInput->setText(SettingConfig::getInstance().BASE_LOG_PATH); + ui->netIpInput->setText(SettingConfig::getInstance().DEVICE_HOST); + ui->netDevPortInput->setText(QString::number(SettingConfig::getInstance().DEVICE_PORT)); + ui->netListenPortInput->setText(QString::number(SettingConfig::getInstance().LISTEN_PORT)); + ui->comNameInput->setText(SettingConfig::getInstance().PORT_NAME); + ui->comBaudInput->setText(QString::number(SettingConfig::getInstance().BAUD_RATE)); + if (running == true) { ui->logInput->setReadOnly(true); } else { ui->logInput->setReadOnly(false); } + + showConfigItemByComType(); } + SetConfig::~SetConfig() { delete ui; @@ -57,9 +86,85 @@ void SetConfig::on_buttonBox_accepted() { - SettingConfig::getInstance().setConProperty("net", "deviceHost", ui->ipInput->text()); - SettingConfig::getInstance().setConProperty("net", "devicePort", ui->devInput->text()); - SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); + SettingConfig::getInstance().setConProperty("dev", "type", ui->comTypeSelect->currentData().toString()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); + + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + SettingConfig::getInstance().setConProperty("com", "portName", ui->comNameInput->text()); + SettingConfig::getInstance().setConProperty("com", "baudRate", ui->comBaudInput->text()); + break; + case 1: + SettingConfig::getInstance().setConProperty("net", "listenPort", ui->netListenPortInput->text()); + break; + } + SettingConfig::getInstance().init(); } + +void SetConfig::on_comTypeSelect_currentIndexChanged(int index) +{ + showConfigItemByComType(); +} + +void SetConfig::onLogPathInputDoubleClicked() +{ + disconnect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); + + QString selectDir = QFileDialog::getExistingDirectory(this, "选择日志保存根目录", QDir::currentPath(), QFileDialog::ShowDirsOnly); + if (selectDir.isEmpty() == false) + { + ui->logInput->setText(selectDir + "/"); + } + + connect(ui->logInput, &DoubleClickInput::textChanged, this, &SetConfig::onLogPathInputDoubleClicked); +} + +void SetConfig::showConfigItemByComType() +{ + int currentIndx = ui->comTypeSelect->currentIndex(); + switch (currentIndx) { + case 0: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->hide(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->hide(); + ui->netListenPortInput->hide(); + ui->netDevPortInput->hide(); + break; + + case 1: + ui->labelComName->hide(); + ui->labelComBaud->hide(); + ui->labelNetIp->hide(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->hide(); + + ui->comNameInput->hide(); + ui->comBaudInput->hide(); + ui->netIpInput->hide(); + ui->netListenPortInput->show(); + ui->netDevPortInput->hide(); + break; + + default: + ui->labelComName->show(); + ui->labelComBaud->show(); + ui->labelNetIp->show(); + ui->labelNetListenPort->show(); + ui->labelNetDevPort->show(); + + ui->comNameInput->show(); + ui->comBaudInput->show(); + ui->netIpInput->show(); + ui->netListenPortInput->show(); + ui->netDevPortInput->show(); + break; + } +} diff --git a/SetConfig.h b/SetConfig.h index 2012b2e..64dbb60 100644 --- a/SetConfig.h +++ b/SetConfig.h @@ -14,12 +14,19 @@ public: explicit SetConfig(QWidget *parent = nullptr); ~SetConfig(); + void init(); private slots: void on_buttonBox_accepted(); + void on_comTypeSelect_currentIndexChanged(int index); + void onLogPathInputDoubleClicked(); + private: Ui::SetConfig *ui; + + void showConfigItemByComType(); + }; #endif // SETCONFIG_H diff --git a/SetConfig.ui b/SetConfig.ui index c17a73e..aeea875 100644 --- a/SetConfig.ui +++ b/SetConfig.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -17,16 +17,11 @@ 30 - 250 - 341 - 31 + 530 + 740 + 50 - - - 10 - - background-color: rgb(47, 53, 66); @@ -40,154 +35,387 @@ false - + - 20 - 50 - 101 - 181 + 30 + 60 + 740 + 470 + + + 0 + 0 + + + + 30 + + + 10 + + + 10 + + + 10 + + + 10 + - - - - 微软雅黑 - 12 - + + + 0 - - IP: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 传输方式: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 设备端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 日志地址: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 50 + + + + + 11 + + + + true + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 监听端口: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 串口号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - 微软雅黑 - 12 - + + + 0 - - 日志地址: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 波特率: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + - - - - - - 120 - 50 - 261 - 181 - - - - - + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备IP: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 设备端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 微软雅黑 + 12 + + + + 监听端口: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 50 + + + + + 11 + + + + + + + + + + Qt::Vertical + + - 0 - 35 + 20 + 40 - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - - - - - - 0 - 35 - - - - - 11 - - - - false - - + @@ -195,9 +423,9 @@ 20 - 5 + 0 80 - 30 + 50 @@ -214,8 +442,8 @@ 1 - 45 - 398 + 50 + 798 3 @@ -227,6 +455,13 @@ + + + DoubleClickInput + QLineEdit +
doubleclickinput.h
+
+
diff --git a/common/utils/QSerialPortUtil.cpp b/common/utils/QSerialPortUtil.cpp index 4285566..4faa3a1 100644 --- a/common/utils/QSerialPortUtil.cpp +++ b/common/utils/QSerialPortUtil.cpp @@ -1,7 +1,6 @@ #include "QSerialPortUtil.h" #include -#include #include #include #include "common/utils/QByteUtil.h" @@ -21,15 +20,16 @@ serial.setBaudRate(baudRate); // 波特率 open = serial.open(QIODevice::ReadWrite); - qDebug() << open; + qDebug() << portName << baudRate << open; if (open == true) { // 绑定信号与槽 connect(&serial, &QSerialPort::readyRead, this, &QSerialPortUtil::readData); - // mock data received per second +// // mock data received per second // QTimer * timer = new QTimer(this); +// lastValue = new double[16] {0.0}; // connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); // timer->start(1000); } @@ -39,7 +39,7 @@ { if (this->open == true) { - std::cout << data.toStdString() << std::endl; + qDebug() << data; serial.write(data); } } @@ -65,10 +65,16 @@ QByteArray buffer; buffer.append(QByteUtil::hexStringToBytes(frameId.mid(0, 8))); - for (int i = 1; i <= 16; i++) + for (int i = 1; i <= 4; i++) { - int value = qrand() % 10000; - buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value, 4)); + int value = qrand() % 100 - 30; + buffer.append(QByteUtil::hexStringToBytes("00800000")).append(QByteUtil::ULongToBytes(value + lastValue[i], 4)); + lastValue[i] += value; + } + + for (int i = 5; i <= 16; i++) + { + buffer.append(QByteUtil::hexStringToBytes("0080000000000000")); } buffer.append(QByteUtil::hexStringToBytes("EEEEEEEE")); diff --git a/common/utils/QSerialPortUtil.h b/common/utils/QSerialPortUtil.h index accf403..a1db0e4 100644 --- a/common/utils/QSerialPortUtil.h +++ b/common/utils/QSerialPortUtil.h @@ -19,6 +19,8 @@ private: QSerialPort serial; + double * lastValue; + bool open; void mockReceivData(); diff --git a/common/utils/SettingConfig.cpp b/common/utils/SettingConfig.cpp index 6170e0f..8d48bd7 100644 --- a/common/utils/SettingConfig.cpp +++ b/common/utils/SettingConfig.cpp @@ -18,7 +18,6 @@ } void SettingConfig::init() { - NET_TYPE = getProperty("net", "type").toString(); DEVICE_HOST = getProperty("net", "deviceHost").toString(); DEVICE_PORT = getProperty("net", "devicePort").toUInt(); LISTEN_PORT = getProperty("net", "listenPort").toUInt(); @@ -26,6 +25,7 @@ PORT_NAME = getProperty("com", "portName").toString(); BAUD_RATE = getProperty("com", "baudRate").toInt(); + NET_TYPE = getProperty("dev", "type").toInt(); CHANNEL_COUNT = getProperty("dev", "channelCount").toUInt(); SKIP_HEADER = getProperty("dev", "skipHeader").toUInt(); MAX_COUNT = getProperty("dev", "maxCount").toUInt(); diff --git a/common/utils/SettingConfig.h b/common/utils/SettingConfig.h index ab36884..cb9c75b 100644 --- a/common/utils/SettingConfig.h +++ b/common/utils/SettingConfig.h @@ -28,7 +28,7 @@ void setConProperty(QString nodeName, QString keyName, QString value); void init(); /******** 以下为需要的各类参数 ********/ - QString NET_TYPE; + int NET_TYPE; QString DEVICE_HOST; quint16 DEVICE_PORT; quint16 LISTEN_PORT; diff --git a/common/utils/UDPClientUtil.cpp b/common/utils/UDPClientUtil.cpp index 4fb50ab..d772c3b 100644 --- a/common/utils/UDPClientUtil.cpp +++ b/common/utils/UDPClientUtil.cpp @@ -1,14 +1,12 @@ #include "UDPClientUtil.h" #include "SettingConfig.h" #include "QByteUtil.h" -#include UDPClientUtil::UDPClientUtil(QObject *parent) : QObject(parent) { client = new QUdpSocket(this); - connect(client, &QUdpSocket::readyRead, - this, &UDPClientUtil::readData); + connect(client, &QUdpSocket::readyRead, this, &UDPClientUtil::readData); } UDPClientUtil::~UDPClientUtil() @@ -21,7 +19,7 @@ client->writeDatagram(data, QHostAddress(SettingConfig::getInstance().DEVICE_HOST), SettingConfig::getInstance().DEVICE_PORT); - std::cout << "[send]" << data.toStdString() << std::endl; + qDebug() << "[send]" << data; } void UDPClientUtil::readData() diff --git a/conf/config.ini b/conf/config.ini index 377091c..d840662 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,20 +1,20 @@ -[net] -type="serial" -deviceHost="192.168.1.20" +[net] +deviceHost=192.168.1.20 devicePort=233 -listenPort=243 +listenPort=24331 [com] -portName="COM1" +portName=COM3 baudRate=115200 [dev] +type=0 channelCount=16 skipHeader=5 maxCount=86400 [log] -basePath="/home/admin/Qt/ZXSSCJ-Release/PhaseCompAcq/logs/" +basePath=C:/casic/logs/ [delay] -delayArr="0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00" +delayArr="178,200,0.00,0.00,0.00,0.00,0.00,0.00,-26,0.00,0.00,0.00,0.00,0.00,0.00,0.00" diff --git a/images/phaseMeasure.png b/images/phaseMeasure.png index 184237b..18b96ff 100644 --- a/images/phaseMeasure.png +++ b/images/phaseMeasure.png Binary files differ diff --git a/protocol/PhaseProtocolBM.cpp b/protocol/PhaseProtocolBM.cpp index 0518f5a..93a2187 100644 --- a/protocol/PhaseProtocolBM.cpp +++ b/protocol/PhaseProtocolBM.cpp @@ -1,5 +1,4 @@ #include "PhaseProtocolBM.h" -#include PhaseProtocolBM::PhaseProtocolBM(QObject *parent) : QObject(parent) { diff --git a/qss/dlgdark.css b/qss/dlgdark.css index c28364f..4e8e406 100644 --- a/qss/dlgdark.css +++ b/qss/dlgdark.css @@ -4,13 +4,54 @@ border-radius: 0px; } -QWidget#inputWgt QLineEdit { +QWidget#configItemWgt QLineEdit { background: #2f3542; color: #e8eaee; border:1px solid #57606f; - border-radius: 4px; + border-radius: 8px; } QDialogButtonBox#buttonBox { background: #2f3542; -} \ No newline at end of file +} + +QDialogButtonBox#buttonBox QPushButton { + font-size: 16px; + min-height: 30px; + min-width: 100px; +} + +QComboBox { + background: #2f3542; + color: #e8eaee; + border:1px solid #57606f; + border-radius: 8px; + + font-size: 16px; + font-family: "Microsoft YaHei"; + padding: 6px; +} + +QComboBox::down-arrow { + image: url(":/css/images/add_bottom.png"); +} + +QComboBox::down-arrow::on { + image: url(":/css/images/add_top.png"); +} + +QComboBox::drop-down { + subcontrol-origin: padding; + subcontrol-position: top right; + width: 20px; + border: 0px; + padding-right: 15px; +} + +QComboBox QAbstractItemView { + color: #6868A6; + background-color: #E1E1ED; + selection-background-color: #A4A4CA; + selection-color: #FFFFFF; + font-family: "Microsoft YaHei"; +} diff --git a/qss/pmdark.css b/qss/pmdark.css index 8f29639..a7dc30f 100644 --- a/qss/pmdark.css +++ b/qss/pmdark.css @@ -1,4 +1,4 @@ -QPalette{background:#444444;}*{outline:0px;color:#DCDCDC;} +QPalette{background:#444444;}*{outline:0px;color:#DCDCDC;} QWidget[form="true"] { background: #444444;