diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/ChannelItem.cpp b/ChannelItem.cpp index 93ef844..f3af9d8 100644 --- a/ChannelItem.cpp +++ b/ChannelItem.cpp @@ -19,16 +19,39 @@ { return channelDelay; } - -double ChannelItem::updatePhaseMeasureData(double raw) +void ChannelItem::setChannelDelay(double value) { - ui->rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()<rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()<rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()<rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()<rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()<rawValue->setText(QString::number(raw, 'f', 15)); - ui->channelValue->setText(QString::number(raw + channelDelay * 1e-9, 'f', 15)); + channelDelay = value; + ui->delay->setValue(value); +} +void ChannelItem::setIndex(int value) +{ + index = value; +} + +double ChannelItem::updatePhaseMeasureData(double raw,QVector vec,int size) +{ + double ps = raw * 1e-3; + ui->rawValue->setText(QString::number(ps, 'f', 15) + "ps"); + ui->channelValue->setText(QString::number(ps + channelDelay * 1e-12, 'f', 15) + "ps"); + ui->samplingOne->setText(QString::number(size)); + ui->samplingTen->setText(QString::number((int)size/10)); + ui->samplingHund->setText(QString::number((int)size/100)); + ui->samplingThou->setText(QString::number((int)size/1000)); + ui->samplingTT->setText(QString::number((int)size/10000)); + ui->stabilityOne->setText(QString::number(vec.at(0), 'f', 15)); + ui->stabilityTen->setText(QString::number(vec.at(1), 'f', 15)); + ui->stabilityHund->setText(QString::number(vec.at(2), 'f', 15)); + ui->stabilityThou->setText(QString::number(vec.at(3), 'f', 15)); + ui->stabilityTT->setText(QString::number(vec.at(4), 'f', 15)); return raw + channelDelay * 1e-9; } void ChannelItem::on_delay_valueChanged(double value) { channelDelay = value; + SettingConfig::getInstance().DELAY_ARR.replace(index, QString("%1").arg(value)); + QString str = SettingConfig::getInstance().DELAY_ARR.join(","); + SettingConfig::getInstance().setConProperty("delay", "delayArr", str); } diff --git a/ChannelItem.h b/ChannelItem.h index 94ca1ba..b3ac948 100644 --- a/ChannelItem.h +++ b/ChannelItem.h @@ -2,6 +2,7 @@ #define CHANNELITEM_H #include +#include "common/utils/SettingConfig.h" namespace Ui { class ChannelItem; @@ -16,14 +17,15 @@ ~ChannelItem(); double getChannelDelay(); - double updatePhaseMeasureData(double channelValue); - + void setIndex(int value); + double updatePhaseMeasureData(double channelValue,QVector vec,int size); + void setChannelDelay(double value); private slots: void on_delay_valueChanged(double value); private: Ui::ChannelItem *ui; - + int index; double channelDelay = 0.0; }; diff --git a/DataProcessAlgorithm.cpp b/DataProcessAlgorithm.cpp index 95ce0e2..4a85549 100644 --- a/DataProcessAlgorithm.cpp +++ b/DataProcessAlgorithm.cpp @@ -6,18 +6,18 @@ } -double DataProcessAlgorithm::allan(double x[], int d, int aN, int ai) +double DataProcessAlgorithm::allan(int index,int d, int aN, int ai) { int j = 0; int i = 0; - double tau0; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s + double tau0 = 1; //tau0是基本采样间隔,由计数器或比相仪的最小采样间隔决定,最小为1s double sum = 0.0; double allan[2] = {0.0}; double *y = new double[aN]; double tau_2 = pow(d * tau0, 2); //pow是计算x的y次幂 for (i = 0; i < aN - 2 * d; i = i+1) { - y[i] = pow(x[i+2*d] - 2 * x[i+d] + x[i], 2); + y[i] = pow(phaseVector[index][i+2*d] - 2 * phaseVector[index][i+d] + phaseVector[index][i], 2); sum=sum+y[i]; j+=1; } diff --git a/DataProcessAlgorithm.h b/DataProcessAlgorithm.h index 055df83..138880f 100644 --- a/DataProcessAlgorithm.h +++ b/DataProcessAlgorithm.h @@ -2,6 +2,7 @@ #define DATAPROCESSALGORITHM_H #include +#include class DataProcessAlgorithm : public QObject { @@ -9,7 +10,7 @@ public: explicit DataProcessAlgorithm(QObject *parent = nullptr); - double allan(double x[], int d, int aN, int ai); + static double allan(int index,int d, int aN, int ai); //double x[], signals: diff --git a/PhaseDevice.cpp b/PhaseDevice.cpp index cbf7709..afe8d3e 100644 --- a/PhaseDevice.cpp +++ b/PhaseDevice.cpp @@ -2,7 +2,7 @@ #include "common/utils/QLogUtil.h" #include #include - +QVector> phaseVector(PHASE_MESSURE_CHANNEL,QVector(0,0)); PhaseDevice::PhaseDevice(QObject *parent) : QObject(parent) { clientUtil = new UDPClientUtil(this); @@ -73,6 +73,29 @@ QString content = phaseData->timestamp + " " + QByteUtil::binToHexString(phaseData->rawFrame); QLogUtil::writeRawDataLogByDate(date, filename, content); + QVector vectorZero(5); + QVector vector(5); + // 3.存+allen + for (int i = 0; i < phaseData->channelActive.size(); i++) + { + + if (phaseData->channelActive.at(i) == "1") + { + phaseVector[i].append(phaseData->channelData.at(i)); // 存 + int size = phaseVector[i].size(); + if(size>=5) vector[0] = DataProcessAlgorithm::allan(i, 1, size, 1); else vector[0] = 0; + if(size>=50) vector[1] = DataProcessAlgorithm::allan(i, 10, size, 1); else vector[1] = 0; + if(size>=500) vector[2] = DataProcessAlgorithm::allan(i, 100, size, 1); else vector[2] = 0; + if(size>=5000) vector[3] = DataProcessAlgorithm::allan(i, 1000, size, 1); else vector[3] = 0; + if(size>=50000) vector[4] = DataProcessAlgorithm::allan(i, 10000, size, 1); else vector[4] = 0; + phaseData->channelAllan.append(vector); + } + else + { + phaseData->channelAllan.append(vectorZero); + } + + } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(phaseData); } diff --git a/PhaseDevice.h b/PhaseDevice.h index 963d983..f1abf14 100644 --- a/PhaseDevice.h +++ b/PhaseDevice.h @@ -5,6 +5,8 @@ #include "common/utils/SettingConfig.h" #include "common/utils/UDPClientUtil.h" #include "protocol/PhaseProtocolBM.h" +#include "DataProcessAlgorithm.h" +extern QVector> phaseVector; class PhaseDevice : public QObject { diff --git a/PhaseWindow.cpp b/PhaseWindow.cpp index 5debd5a..581cb7a 100644 --- a/PhaseWindow.cpp +++ b/PhaseWindow.cpp @@ -12,9 +12,13 @@ #include #include #include +#include +#include #include "common/utils/SettingConfig.h" #include "common/utils/QLogUtil.h" +QString currentFileName = ""; + PhaseWindow::PhaseWindow(QWidget *parent) : QWidget(parent), ui(new Ui::PhaseWindow) @@ -69,8 +73,12 @@ if (phaseData->channelActive.at(i) == "1") { ChannelItem * channel = channelItemList.at(i); - double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i)); + // 存 + phaseVector[i].append(phaseData->channelData.at(i)); + int size = phaseVector.at(i).size(); + double phaseValue = channel->updatePhaseMeasureData(phaseData->channelData.at(i),phaseData->channelAllan.at(i),size); + // 写日志 QString chFilename = QString("CH_%1.log").arg(i + 1, 2, 10, QLatin1Char('0')); QString channelDataStr = QString("%1 [%2] %3 %4 %5") .arg(phaseData->timestamp) @@ -112,8 +120,9 @@ QHBoxLayout * vbox = new QHBoxLayout(group); ChannelItem * channelItem = new ChannelItem(); channelItem->setGeometry(10, 0, screenRect.width() - 60, 160); + channelItem->setIndex(i); + channelItem->setChannelDelay(SettingConfig::getInstance().DELAY_ARR.at(i).toDouble()); this->channelItemList.append(channelItem); - vbox->addWidget(channelItem); group->setLayout(vbox); layout->addWidget(group); @@ -157,10 +166,33 @@ { //发送开始指令 device->startWork(); + createFolder(); } +void PhaseWindow::createFolder() +{ + QDir *folder = new QDir; + bool exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH); + if(!exist) //生成base文件夹 + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH); + } + //生成当前时间文件夹 + QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"); + exist = folder->exists(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(!exist) + { + bool ok = folder->mkdir(SettingConfig::getInstance().BASE_LOG_PATH +fileName); + if(ok) { + currentFileName = fileName; + QMessageBox::warning(this, tr("开始"), tr("开始成功")); + } + } + +} void PhaseWindow::on_endButt_clicked() { + currentFileName = ""; //发送结束指令 device->stopWork(); } diff --git a/PhaseWindow.h b/PhaseWindow.h index 3321d15..bfb44b6 100644 --- a/PhaseWindow.h +++ b/PhaseWindow.h @@ -6,6 +6,8 @@ #include "PhaseDevice.h" #include "ChannelItem.h" +#include "protocol/PhaseProtocolBM.h" +extern QString currentFileName; namespace Ui { class PhaseWindow; @@ -37,6 +39,8 @@ PhaseDevice * device; + + void createFolder(); void generateWidgetForDevice(); void updateChannelActive(QList channelActive); }; diff --git a/SetConfig.cpp b/SetConfig.cpp index 128a3b0..964bc9e 100644 --- a/SetConfig.cpp +++ b/SetConfig.cpp @@ -27,5 +27,4 @@ SettingConfig::getInstance().setConProperty("net", "listenPort", ui->listenInput->text()); SettingConfig::getInstance().setConProperty("log", "basePath", ui->logInput->text()); SettingConfig::getInstance().init(); - qDebug()< channelActive; QList channelData; QList channelDataStr; - + QVector> channelAllan; QJsonObject toJSON(int i); signals: