diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
deleted file mode 100644
index aefae50..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "FrequencyTuningStatusPulseDto.h"
-
-FrequencyTuningStatusPulseDto::FrequencyTuningStatusPulseDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject FrequencyTuningStatusPulseDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("synchStatus", synchStatus);
- dataObj.insert("secondDiff", secondDiff);
- dataObj.insert("refValid", refValid);
- dataObj.insert("phaseShiftAcc", phaseShiftAcc);
- dataObj.insert("pulseWidth", pulseWidth);
-
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("frameType", this->frameType);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
deleted file mode 100644
index aefae50..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "FrequencyTuningStatusPulseDto.h"
-
-FrequencyTuningStatusPulseDto::FrequencyTuningStatusPulseDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject FrequencyTuningStatusPulseDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("synchStatus", synchStatus);
- dataObj.insert("secondDiff", secondDiff);
- dataObj.insert("refValid", refValid);
- dataObj.insert("phaseShiftAcc", phaseShiftAcc);
- dataObj.insert("pulseWidth", pulseWidth);
-
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("frameType", this->frameType);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
deleted file mode 100644
index 2745f8d..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef FREQUENCYTUNINGSTATUSPULSEDTO_H
-#define FREQUENCYTUNINGSTATUSPULSEDTO_H
-
-#include
-#include "protocol/dto/DeviceFrameBaseDto.h"
-
-/**
- * @brief The FrequencyTuningStatusPulseDto class
- * 频率微调设备工作状态:秒脉冲状态
- */
-class FrequencyTuningStatusPulseDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit FrequencyTuningStatusPulseDto(QObject *parent = nullptr);
-
- QString synchStatus; // <1> 同步状态:1=正常;0=异常
- qlonglong secondDiff; // <2> 秒差,单位1ns,范围-500ms~500ms
- QString refValid; // <3> 参考有效:1=有效;0=无效
- qlonglong phaseShiftAcc; // <4> 移相累计值,单位1ps,范围-500ms~500ms
- qlonglong pulseWidth; // <5> 移脉宽,单位1ns,范围10us~500ms
-
- QJsonObject toJSON();
-};
-
-#endif // FREQUENCYTUNINGSTATUSPULSEDTO_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
deleted file mode 100644
index aefae50..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "FrequencyTuningStatusPulseDto.h"
-
-FrequencyTuningStatusPulseDto::FrequencyTuningStatusPulseDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject FrequencyTuningStatusPulseDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("synchStatus", synchStatus);
- dataObj.insert("secondDiff", secondDiff);
- dataObj.insert("refValid", refValid);
- dataObj.insert("phaseShiftAcc", phaseShiftAcc);
- dataObj.insert("pulseWidth", pulseWidth);
-
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("frameType", this->frameType);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
deleted file mode 100644
index 2745f8d..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef FREQUENCYTUNINGSTATUSPULSEDTO_H
-#define FREQUENCYTUNINGSTATUSPULSEDTO_H
-
-#include
-#include "protocol/dto/DeviceFrameBaseDto.h"
-
-/**
- * @brief The FrequencyTuningStatusPulseDto class
- * 频率微调设备工作状态:秒脉冲状态
- */
-class FrequencyTuningStatusPulseDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit FrequencyTuningStatusPulseDto(QObject *parent = nullptr);
-
- QString synchStatus; // <1> 同步状态:1=正常;0=异常
- qlonglong secondDiff; // <2> 秒差,单位1ns,范围-500ms~500ms
- QString refValid; // <3> 参考有效:1=有效;0=无效
- qlonglong phaseShiftAcc; // <4> 移相累计值,单位1ps,范围-500ms~500ms
- qlonglong pulseWidth; // <5> 移脉宽,单位1ns,范围10us~500ms
-
- QJsonObject toJSON();
-};
-
-#endif // FREQUENCYTUNINGSTATUSPULSEDTO_H
diff --git a/DeviceHub/protocol/dto/NtpServerStatusDto.cpp b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
new file mode 100644
index 0000000..ad9fccc
--- /dev/null
+++ b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
@@ -0,0 +1,171 @@
+#include "NtpServerStatusDto.h"
+
+NtpServerStatusDto::NtpServerStatusDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+
+QJsonObject NtpServerStatusDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("devStatus", devStatus);
+ dataObj.insert("freqInType", freqInType);
+ dataObj.insert("freqInTypeStr", freqInType == "1" ? "5M" : (freqInType == "2" ? "10M" : "无信号"));
+ dataObj.insert("oppsValid", oppsValid);
+ dataObj.insert("bdcValid", bdcValid);
+ dataObj.insert("dclsValid", dclsValid);
+ dataObj.insert("dclsInType", dclsInType);
+ dataObj.insert("dclsOutType", dclsOutType);
+ dataObj.insert("refType", refType);
+ dataObj.insert("refStatus", refStatus);
+ dataObj.insert("sysTime", sysTime);
+
+ QJsonArray outValidArray;
+ for (int i = 0; i < outValid.size(); i++)
+ {
+ outValidArray.append(outValid.at(i));
+ }
+ dataObj.insert("outValid", outValidArray);
+
+ QJsonArray tmSrcPrioArray;
+ QJsonArray tmSrcPrioStrArray;
+ for (int i = 0; i < tmSrcPrio.size(); i++)
+ {
+ tmSrcPrioArray.append(tmSrcPrio.at(i));
+
+ QString tmSrcStr = "";
+ switch (tmSrcPrio.at(i).toInt()) {
+ case 0 :
+ tmSrcStr = "BDC";
+ break;
+ case 1:
+ tmSrcStr = "1PPS";
+ break;
+ case 2:
+ tmSrcStr = "Freq(5M/10M)";
+ break;
+ case 3:
+ tmSrcStr = "AM";
+ break;
+ case 4:
+ tmSrcStr = "DCLS";
+ break;
+ }
+ tmSrcPrioStrArray.append(tmSrcStr);
+ }
+ dataObj.insert("tmSrcPrio", tmSrcPrioArray);
+
+ switch (dclsInType.toInt()) {
+ case 0 :
+ dclsInTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsInTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsInTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsInTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsInTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsInTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsInTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch(dclsOutType.toInt())
+ {
+ case 0 :
+ dclsOutTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsOutTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsOutTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsOutTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsOutTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsOutTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsOutTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refType.toInt()) {
+ case 0 :
+ refTypeStr = "BDC";
+ break;
+ case 1:
+ refTypeStr = "1PPS";
+ break;
+ case 2:
+ refTypeStr = "10M/5M";
+ break;
+ case 3:
+ refTypeStr = "IRIG-A";
+ break;
+ case 4:
+ refTypeStr = "IRIG-B";
+ break;
+ case 5:
+ refTypeStr = "IRIG-E";
+ break;
+ case 6:
+ refTypeStr = "IRIG-G";
+ break;
+ case 7:
+ refTypeStr = "IRIG-NASA36";
+ break;
+ case 8:
+ refTypeStr = "IRIG-XR3";
+ break;
+ case 9:
+ refTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refStatus.toInt()) {
+ case 0 :
+ refStatusStr = "自由";
+ break;
+ case 1:
+ refStatusStr = "跟踪";
+ break;
+ case 2:
+ refStatusStr = "锁定";
+ break;
+ case 3:
+ refStatusStr = "守时";
+ break;
+ case 4:
+ refStatusStr = "预热";
+ break;
+ }
+
+// dataObj.insert("dclsInTypeStr", dclsInTypeStr);
+// dataObj.insert("dclsOutTypeStr", dclsOutTypeStr);
+// dataObj.insert("refTypeStr", refTypeStr);
+// dataObj.insert("refStatusStr", refStatusStr);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
deleted file mode 100644
index aefae50..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "FrequencyTuningStatusPulseDto.h"
-
-FrequencyTuningStatusPulseDto::FrequencyTuningStatusPulseDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject FrequencyTuningStatusPulseDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("synchStatus", synchStatus);
- dataObj.insert("secondDiff", secondDiff);
- dataObj.insert("refValid", refValid);
- dataObj.insert("phaseShiftAcc", phaseShiftAcc);
- dataObj.insert("pulseWidth", pulseWidth);
-
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("frameType", this->frameType);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
deleted file mode 100644
index 2745f8d..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef FREQUENCYTUNINGSTATUSPULSEDTO_H
-#define FREQUENCYTUNINGSTATUSPULSEDTO_H
-
-#include
-#include "protocol/dto/DeviceFrameBaseDto.h"
-
-/**
- * @brief The FrequencyTuningStatusPulseDto class
- * 频率微调设备工作状态:秒脉冲状态
- */
-class FrequencyTuningStatusPulseDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit FrequencyTuningStatusPulseDto(QObject *parent = nullptr);
-
- QString synchStatus; // <1> 同步状态:1=正常;0=异常
- qlonglong secondDiff; // <2> 秒差,单位1ns,范围-500ms~500ms
- QString refValid; // <3> 参考有效:1=有效;0=无效
- qlonglong phaseShiftAcc; // <4> 移相累计值,单位1ps,范围-500ms~500ms
- qlonglong pulseWidth; // <5> 移脉宽,单位1ns,范围10us~500ms
-
- QJsonObject toJSON();
-};
-
-#endif // FREQUENCYTUNINGSTATUSPULSEDTO_H
diff --git a/DeviceHub/protocol/dto/NtpServerStatusDto.cpp b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
new file mode 100644
index 0000000..ad9fccc
--- /dev/null
+++ b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
@@ -0,0 +1,171 @@
+#include "NtpServerStatusDto.h"
+
+NtpServerStatusDto::NtpServerStatusDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+
+QJsonObject NtpServerStatusDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("devStatus", devStatus);
+ dataObj.insert("freqInType", freqInType);
+ dataObj.insert("freqInTypeStr", freqInType == "1" ? "5M" : (freqInType == "2" ? "10M" : "无信号"));
+ dataObj.insert("oppsValid", oppsValid);
+ dataObj.insert("bdcValid", bdcValid);
+ dataObj.insert("dclsValid", dclsValid);
+ dataObj.insert("dclsInType", dclsInType);
+ dataObj.insert("dclsOutType", dclsOutType);
+ dataObj.insert("refType", refType);
+ dataObj.insert("refStatus", refStatus);
+ dataObj.insert("sysTime", sysTime);
+
+ QJsonArray outValidArray;
+ for (int i = 0; i < outValid.size(); i++)
+ {
+ outValidArray.append(outValid.at(i));
+ }
+ dataObj.insert("outValid", outValidArray);
+
+ QJsonArray tmSrcPrioArray;
+ QJsonArray tmSrcPrioStrArray;
+ for (int i = 0; i < tmSrcPrio.size(); i++)
+ {
+ tmSrcPrioArray.append(tmSrcPrio.at(i));
+
+ QString tmSrcStr = "";
+ switch (tmSrcPrio.at(i).toInt()) {
+ case 0 :
+ tmSrcStr = "BDC";
+ break;
+ case 1:
+ tmSrcStr = "1PPS";
+ break;
+ case 2:
+ tmSrcStr = "Freq(5M/10M)";
+ break;
+ case 3:
+ tmSrcStr = "AM";
+ break;
+ case 4:
+ tmSrcStr = "DCLS";
+ break;
+ }
+ tmSrcPrioStrArray.append(tmSrcStr);
+ }
+ dataObj.insert("tmSrcPrio", tmSrcPrioArray);
+
+ switch (dclsInType.toInt()) {
+ case 0 :
+ dclsInTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsInTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsInTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsInTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsInTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsInTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsInTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch(dclsOutType.toInt())
+ {
+ case 0 :
+ dclsOutTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsOutTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsOutTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsOutTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsOutTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsOutTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsOutTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refType.toInt()) {
+ case 0 :
+ refTypeStr = "BDC";
+ break;
+ case 1:
+ refTypeStr = "1PPS";
+ break;
+ case 2:
+ refTypeStr = "10M/5M";
+ break;
+ case 3:
+ refTypeStr = "IRIG-A";
+ break;
+ case 4:
+ refTypeStr = "IRIG-B";
+ break;
+ case 5:
+ refTypeStr = "IRIG-E";
+ break;
+ case 6:
+ refTypeStr = "IRIG-G";
+ break;
+ case 7:
+ refTypeStr = "IRIG-NASA36";
+ break;
+ case 8:
+ refTypeStr = "IRIG-XR3";
+ break;
+ case 9:
+ refTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refStatus.toInt()) {
+ case 0 :
+ refStatusStr = "自由";
+ break;
+ case 1:
+ refStatusStr = "跟踪";
+ break;
+ case 2:
+ refStatusStr = "锁定";
+ break;
+ case 3:
+ refStatusStr = "守时";
+ break;
+ case 4:
+ refStatusStr = "预热";
+ break;
+ }
+
+// dataObj.insert("dclsInTypeStr", dclsInTypeStr);
+// dataObj.insert("dclsOutTypeStr", dclsOutTypeStr);
+// dataObj.insert("refTypeStr", refTypeStr);
+// dataObj.insert("refStatusStr", refStatusStr);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/NtpServerStatusDto.h b/DeviceHub/protocol/dto/NtpServerStatusDto.h
new file mode 100644
index 0000000..a9b8a9c
--- /dev/null
+++ b/DeviceHub/protocol/dto/NtpServerStatusDto.h
@@ -0,0 +1,35 @@
+#ifndef NTPSERVERSTATUSDTO_H
+#define NTPSERVERSTATUSDTO_H
+
+#include
+#include "DeviceFrameBaseDto.h"
+
+class NtpServerStatusDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit NtpServerStatusDto(QObject * parent = nullptr);
+
+ QString devStatus;
+ QString freqInType;
+ QString oppsValid;
+ QString bdcValid;
+ QString dclsValid;
+ QString dclsInType;
+ QString dclsOutType;
+ QString refType;
+ QString refStatus;
+ QString sysTime;
+ QList outValid;
+ QList tmSrcPrio;
+
+ QString freqInTypeStr;
+ QString dclsInTypeStr;
+ QString dclsOutTypeStr;
+ QString refTypeStr;
+ QString refStatusStr;
+
+ QJsonObject toJSON() override;
+};
+
+#endif // NTPSERVERSTATUSDTO_H
diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro
index 5d0706d..e54f759 100644
--- a/DeviceHub/DeviceHub.pro
+++ b/DeviceHub/DeviceHub.pro
@@ -24,6 +24,7 @@
SOURCES += BCodeTerminalForm.cpp
SOURCES += FreqReplicatorForm.cpp
SOURCES += TimeReplicatorForm.cpp
+SOURCES += NtpServerForm.cpp
HEADERS += DeviceHubWindow.h
HEADERS += FrequencyTuningForm.h
@@ -33,6 +34,7 @@
HEADERS += BCodeTerminalForm.h
HEADERS += FreqReplicatorForm.h
HEADERS += TimeReplicatorForm.h
+HEADERS += NtpServerForm.h
FORMS += DeviceHubWindow.ui
FORMS += FrequencyTuningForm.ui
@@ -42,6 +44,7 @@
FORMS += BCodeTerminalForm.ui
FORMS += FreqReplicatorForm.ui
FORMS += TimeReplicatorForm.ui
+FORMS += NtpServerForm.ui
DISTFILES += conf/config.ini
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index fc8a915..ff2ceed 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -120,6 +120,8 @@
{
QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID,
SettingConfig::getInstance().APP_KEY);
+
+ std::cout << SettingConfig::getInstance().CLIENT_ID.toStdString() << " - " << SettingConfig::getInstance().APP_KEY.toStdString() << std::endl;
return response.find("code")->toInt();
}
@@ -253,4 +255,10 @@
freqRepForm = new FreqReplicatorForm(this);
ui->stackedWidget->addWidget(freqRepForm);
}
+
+ if (devType == "11")
+ {
+ ntpServForm = new NtpServerForm(this);
+ ui->stackedWidget->addWidget(ntpServForm);
+ }
}
diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h
index 900835b..39443a8 100644
--- a/DeviceHub/DeviceHubWindow.h
+++ b/DeviceHub/DeviceHubWindow.h
@@ -15,6 +15,7 @@
#include "BCodeTerminalForm.h"
#include "TimeReplicatorForm.h"
#include "FreqReplicatorForm.h"
+#include "NtpServerForm.h"
QT_BEGIN_NAMESPACE
namespace Ui { class DeviceHubWindow; }
@@ -45,6 +46,7 @@
BCodeTerminalForm * bCodeTermForm;
TimeReplicatorForm * timeRepForm;
FreqReplicatorForm * freqRepForm;
+ NtpServerForm * ntpServForm;
private slots:
void on_minButt_clicked();
diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp
index 193d7d2..1fa5289 100644
--- a/DeviceHub/FrequencyTuningForm.cpp
+++ b/DeviceHub/FrequencyTuningForm.cpp
@@ -42,19 +42,16 @@
{
FrequencyTuningStatusFreqDto * freqFrameDto = (FrequencyTuningStatusFreqDto *) frameData;
ui->ftDevStatus->setText(freqFrameDto->devStatus == "1" ? "正常" : "异常");
- ui->ftInputValid->setText(freqFrameDto->inputValid == "1" ? "有效" : "无效");
- ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz");
- ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc));
- ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1));
+ ui->ftFreqAdjust->setText(QString::number(freqFrameDto->freqAdjust, 'g', 3));
+ ui->ftFreqAdjustAcc->setText(QString::number(freqFrameDto->freqAdjustAcc, 'g', 3));
+ ui->ftPhaseShift->setText(QString::number(freqFrameDto->phaseShift));
+ ui->ftPhaseAdjust->setText(QString::number(freqFrameDto->phaseAdjust, 'f', 3));
+ ui->ftPulseWidth->setText(QString::number(freqFrameDto->pulseWidth));
ui->label_ts->setText(freqFrameDto->timestamp);
} else if (frameData->frameType == "0302")
{
- FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData;
- ui->ftSynchStatus->setText(pulseFrameDto->synchStatus == "1" ? "正常" : "异常");
- ui->ftRefValid->setText(pulseFrameDto->refValid == "1" ? "有效" : "无效");
- ui->ftSecondDiff->setText(QString("%1 ns").arg(pulseFrameDto->secondDiff));
- ui->ftPhaseShiftAcc->setText(QString("%1 ps").arg(pulseFrameDto->phaseShiftAcc));
- ui->ftPulseWidth->setText(QString("%1 ns").arg(pulseFrameDto->pulseWidth));
+ FrequencyTuningStatusLockDto * lockFrameDto = (FrequencyTuningStatusLockDto *) frameData;
+ ui->ftLockStatus->setText(lockFrameDto->lockStatus == "1" ? "锁定" : "失锁");
}
}
diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui
index 8f01816..edd4d2b 100644
--- a/DeviceHub/FrequencyTuningForm.ui
+++ b/DeviceHub/FrequencyTuningForm.ui
@@ -45,30 +45,11 @@
工作状态
-
-
-
- 20
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 频率输出状态
-
-
- 120
- 120
+ 240
+ 170
100
30
@@ -80,15 +61,15 @@
- 频率调整累积值
+ 频率累计偏移量
- 370
- 120
- 100
+ 490
+ 170
+ 71
30
@@ -99,13 +80,13 @@
- 相位调整累积值
+ 相位步进量
- 620
+ 190
120
80
30
@@ -118,33 +99,14 @@
- 设备工作状态
-
-
-
-
-
- 770
- 120
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 输入时钟类别
+ 锁相环状态
- 920
- 120
+ 20
+ 170
70
30
@@ -156,170 +118,54 @@
- 输入有效性
+ 频率步进量
- 220
- 120
+ 340
+ 170
120
30
-
+
- 470
- 120
+ 570
+ 170
120
30
-
+
- 700
+ 270
120
50
30
-
+
- 850
- 120
- 50
- 30
-
-
-
-
-
-
- 990
- 120
- 50
- 30
-
-
-
-
-
-
- 20
- 160
- 80
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒脉冲状态
-
-
-
-
-
- 120
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 同步状态
-
-
-
-
-
- 180
- 160
- 50
- 30
-
-
-
-
-
-
- 250
- 160
- 30
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 秒差
-
-
-
-
-
- 280
- 160
+ 100
+ 170
120
30
-
-
-
- 420
- 160
- 60
- 30
-
-
-
-
- 微软雅黑
- 10
-
-
-
- 参考有效
-
-
-
-
-
- 480
- 160
- 50
- 30
-
-
-
- 550
- 160
+ 720
+ 170
70
30
@@ -331,14 +177,14 @@
- 移相累计值
+ PPS移相量
-
+
- 620
- 160
+ 790
+ 170
120
30
@@ -347,9 +193,9 @@
- 760
- 160
- 40
+ 940
+ 170
+ 91
30
@@ -360,14 +206,14 @@
- 秒脉宽
+ PPS脉冲宽度
- 800
- 160
+ 1030
+ 170
120
30
@@ -716,6 +562,35 @@
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
diff --git a/DeviceHub/NtpServerForm.cpp b/DeviceHub/NtpServerForm.cpp
new file mode 100644
index 0000000..da437fc
--- /dev/null
+++ b/DeviceHub/NtpServerForm.cpp
@@ -0,0 +1,79 @@
+#include "NtpServerForm.h"
+#include "ui_NtpServerForm.h"
+#include "DeviceHubWindow.h"
+
+NtpServerForm::NtpServerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::NtpServerForm)
+{
+ ui->setupUi(this);
+}
+
+NtpServerForm::~NtpServerForm()
+{
+ delete ui;
+}
+
+void NtpServerForm::on_ntpServButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ NtpServer * device = (NtpServer *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("11").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivData();
+ }
+}
+
+void NtpServerForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
+{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+ if (currentDevCode != frameData->devCode)
+ {
+ return;
+ }
+
+ if (frameData->frameType == NTP_SERVER_STATUS_FRAME_TYPE)
+ {
+ ui->label_ts->setText(frameData->timestamp);
+ ui->ntpDevStatus->setText(((NtpServerStatusDto *) frameData)->devStatus);
+ ui->ntpSystime->setText(((NtpServerStatusDto *) frameData)->sysTime);
+ ui->ntpDevStatusJson->setText(QJsonDocument(frameData->toJSON()).toJson(QJsonDocument::Compact));
+ }
+}
+void NtpServerForm::displayDeviceCommandOnForm(QJsonObject command)
+{
+ QString deviceId = command.value("deviceId").toString();
+ QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09");
+ for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++)
+ {
+ if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "09")
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i);
+ }
+ }
+ for (int i = 0; i < typeDevList.size(); i++)
+ {
+ if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString())
+ {
+ ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i);
+ }
+ }
+
+ QString commandType = command.value("command").toString();
+ if (commandType == "1")
+ {
+
+ } else if (commandType == "2")
+ {
+
+ } else if (commandType == "3")
+ {
+
+ } else if (commandType == "4")
+ {
+
+ }
+}
diff --git a/DeviceHub/NtpServerForm.h b/DeviceHub/NtpServerForm.h
new file mode 100644
index 0000000..d3fc17c
--- /dev/null
+++ b/DeviceHub/NtpServerForm.h
@@ -0,0 +1,30 @@
+#ifndef NTPSERVERFORM_H
+#define NTPSERVERFORM_H
+
+#include
+#include "device/NtpServer.h"
+
+namespace Ui {
+class NtpServerForm;
+}
+
+class NtpServerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit NtpServerForm(QWidget *parent = nullptr);
+ ~NtpServerForm();
+
+public slots:
+ void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData);
+ void displayDeviceCommandOnForm(QJsonObject command);
+
+private slots:
+ void on_ntpServButt_clicked();
+
+private:
+ Ui::NtpServerForm *ui;
+};
+
+#endif // NTPSERVERFORM_H
diff --git a/DeviceHub/NtpServerForm.ui b/DeviceHub/NtpServerForm.ui
new file mode 100644
index 0000000..db69e05
--- /dev/null
+++ b/DeviceHub/NtpServerForm.ui
@@ -0,0 +1,157 @@
+
+
+ NtpServerForm
+
+
+
+ 0
+ 0
+ 1200
+ 600
+
+
+
+ Form
+
+
+
+
+ 50
+ 20
+ 180
+ 40
+
+
+
+ Mock NtpServ
+
+
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
+
+
+
+ 20
+ 120
+ 80
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态
+
+
+
+
+
+ 100
+ 120
+ 50
+ 30
+
+
+
+
+
+
+ 20
+ 80
+ 100
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+ 工作状态
+
+
+
+
+
+ 20
+ 170
+ 121
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 设备工作状态JSON
+
+
+
+
+
+ 140
+ 170
+ 1000
+ 30
+
+
+
+
+
+
+ 180
+ 120
+ 61
+ 30
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+ 系统I时间
+
+
+
+
+
+ 240
+ 120
+ 200
+ 30
+
+
+
+
+
+
+
diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp
index 9c7a9bd..8a94d04 100644
--- a/DeviceHub/device/DeviceBase.cpp
+++ b/DeviceHub/device/DeviceBase.cpp
@@ -6,6 +6,7 @@
#include "BCodeTerminal.h"
#include "TimeReplicator.h"
#include "FreqReplicator.h"
+#include "NtpServer.h"
#include
@@ -60,10 +61,12 @@
} else if (deviceType == "09")
{
base = new TimeReplicator(parent);
- } else
- if (deviceType == "10")
+ } else if (deviceType == "10")
{
base = new FreqReplicator(parent);
+ } else if (deviceType == "11")
+ {
+ base = new NtpServer(parent);
}
return base;
diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp
index 72f8340..4b0eceb 100644
--- a/DeviceHub/device/FreqReplicator.cpp
+++ b/DeviceHub/device/FreqReplicator.cpp
@@ -32,9 +32,9 @@
QByteArray buffer;
// 频率信号放大器
- buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
- buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
-// buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"));
+// buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8"));
+ buffer.append(QByteUtil::hexStringToBytes("AA55000B0100010101010101010101F4AA55000B0200010101010101010101F7"));
this->dataReceivedHandler(buffer);
}
diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp
index d836753..c63bc84 100644
--- a/DeviceHub/device/FrequencyTuning.cpp
+++ b/DeviceHub/device/FrequencyTuning.cpp
@@ -8,8 +8,6 @@
this->devType = "03";
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &FrequencyTuning::dataReceivedHandler);
- connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
- this, &FrequencyTuning::dataBReceivedHandler);
connect(this, &FrequencyTuning::sendDataToDraw,
((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm);
@@ -37,9 +35,10 @@
QByteArray buffer;
// frequency tuning
- buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
- buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
- buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+// buffer.append("$GLN,0,192.168.1.126,255.255.255.0,192.168.1.1,255.255.255.255,3000,2000,2001*71").append("\r\n");
+// buffer.append("$GLF,0,0,0,0,00000,0,0,0,0,0,0,0,0,0,0,0,1900,2355,0,0,0,0,0,1,1,1*4C").append("\r\n");
+// buffer.append("$GLP,0,1000,0,100,20000*45").append("\r\n");
+ buffer.append("$1C2BM1304-3021010071204312*$572BM1304-30210100713 -2.52E-10 +3.02E-14 -000000002000 000008000 +0000000027.6007BAF*");
this->dataReceivedHandler(buffer);
}
@@ -54,16 +53,6 @@
frameParse(frameList);
}
}
-void FrequencyTuning::dataBReceivedHandler(QByteArray data)
-{
- this->dataBuffB.append(data);
- QList frameListB = protocol->extractFrameList(this->dataBuffB);
- if (frameListB.size() > 0)
- {
- this->dataBuffB.clear();
- frameParse(frameListB);
- }
-}
void FrequencyTuning::frameParse(QList frameList)
{
@@ -142,9 +131,6 @@
if (serialUtil.isOpen() == true)
{
this->serialUtil.sendData(data);
- } else if (serialUtilB.isOpen() == true)
- {
- this->serialUtilB.sendData(data);
} else
{
replyDto.cmdStatus = 0;
diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h
index cdfa1fa..f65e9f7 100644
--- a/DeviceHub/device/FrequencyTuning.h
+++ b/DeviceHub/device/FrequencyTuning.h
@@ -5,7 +5,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FrequencyTuningStatusFreqDto.h"
-#include "protocol/dto/FrequencyTuningStatusPulseDto.h"
+#include "protocol/dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuning : public DeviceBase
{
@@ -29,7 +29,6 @@
public slots:
void dataReceivedHandler(QByteArray data);
- void dataBReceivedHandler(QByteArray data);
void commandReceivedHandler(QJsonObject command);
};
diff --git a/DeviceHub/device/NtpServer.cpp b/DeviceHub/device/NtpServer.cpp
new file mode 100644
index 0000000..891d055
--- /dev/null
+++ b/DeviceHub/device/NtpServer.cpp
@@ -0,0 +1,246 @@
+#include "NtpServer.h"
+#include "DeviceHubWindow.h"
+
+NtpServer::NtpServer(QObject *parent) : DeviceBase(parent)
+{
+ this->devType = "11";
+ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+
+ connect(this, &NtpServer::sendDataToDraw,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::drawDeviceFrameOnForm);
+ connect(this, &NtpServer::sendCommandToDisplay,
+ ((DeviceHubWindow *)this->parent())->ntpServForm, &NtpServerForm::displayDeviceCommandOnForm);
+
+ connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved,
+ this, &NtpServer::commandReceivedHandler);
+
+ kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaProducer.createProducer();
+
+ this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType);
+}
+
+NtpServer::~NtpServer()
+{
+ disconnect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataReceivedHandler);
+ disconnect(&this->serialUtilB, &QSerialPortUtil::dataRecieved,
+ this, &NtpServer::dataBReceivedHandler);
+}
+
+void NtpServer::mockReceivData()
+{
+ QByteArray buffer;
+
+ QDateTime now = QDateTime::currentDateTime();
+ now = now.addSecs(-3600 * 8);
+ QByteArray nowStr = now.toString("yyMMddHHmmss").toLocal8Bit();
+
+ // ntp server
+ buffer.append("$3521308-07 21010021211100002").append(nowStr).append("ff041205d14*");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // time replicator
+ buffer.append("$1941308-07 21010021eb4a*").append("\r\n");
+ this->dataReceivedHandler(buffer);
+}
+
+void NtpServer::dataReceivedHandler(QByteArray data)
+{
+ this->dataBuff.append(data);
+ QList frameList = protocol->extractFrameList(this->dataBuff);
+ if (frameList.size() > 0)
+ {
+ this->dataBuff.clear();
+ frameParse(frameList);
+ }
+}
+void NtpServer::dataBReceivedHandler(QByteArray data)
+{
+ this->dataBuffB.append(data);
+ QList frameListB = protocol->extractFrameList(this->dataBuffB);
+ if (frameListB.size() > 0)
+ {
+ this->dataBuffB.clear();
+ frameParse(frameListB);
+ }
+}
+
+void NtpServer::frameParse(QList frameList)
+{
+ for (int i = 0; i < frameList.size(); i++)
+ {
+ QByteArray frameByte = frameList.at(i);
+
+ int frameType = protocol->checkFrame(frameByte);
+ DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType);
+ if (frameDto != nullptr)
+ {
+ // ★解析成数据对象
+ bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType);
+
+ // 解析成功
+ if (parse == true)
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz");
+ frameDto->milisecond = now.toMSecsSinceEpoch();
+ frameDto->rawFrame = frameByte;
+ frameDto->devCode = devCode;
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
+ }
+
+ // 在此处释放内存,不影响后续显示
+ // 不在此处释放内存则会导致内存持续增加
+ // 具体原因不明
+ delete frameDto;
+ }
+ }
+}
+void NtpServer::afterFrameParse(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame;
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("deviceId", deviceId);
+ kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(frameDto);
+}
+
+void NtpServer::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
+void NtpServer::sendDataToSerial(QByteArray data)
+{
+ data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ std::cout << content.toStdString() << std::endl;
+}
+
+void NtpServer::commandReceivedHandler(QJsonObject command)
+{
+ if (command.contains("deviceType") == false || command.value("deviceType").toString() != "11")
+ {
+ return;
+ }
+
+ if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
+ {
+ return;
+ }
+
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
+ // 记录日志
+ // 0. 输出到日志文件中
+ QDateTime now = QDateTime::currentDateTime();
+ QString date = now.toString("yyyy-MM-dd");
+
+ // 1. 原始字节数组数据
+ QString filename = "frame_" + devCode + ".log";
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
+ QLogUtil::writeChannelDataLogByDate(date, filename, content);
+
+ QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
+ this->sendDataToSerial(commandBytes);
+ command.insert("rawCommand", QString::fromUtf8(commandBytes));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+
+ // display on page
+ emit sendCommandToDisplay(command);
+}
diff --git a/DeviceHub/device/NtpServer.h b/DeviceHub/device/NtpServer.h
new file mode 100644
index 0000000..09ffa6d
--- /dev/null
+++ b/DeviceHub/device/NtpServer.h
@@ -0,0 +1,36 @@
+#ifndef NTPSERVER_H
+#define NTPSERVER_H
+
+#include
+
+#include "device/DeviceBase.h"
+#include "protocol/NtpServerProtocolBM.h"
+#include "protocol/dto/CommandReplyDto.h"
+
+class NtpServer : public DeviceBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServer(QObject *parent = nullptr);
+ ~NtpServer();
+
+ void frameParse(QList frameList);
+
+ void mockReceivData();
+ void mockReceivCmdReply();
+
+ void afterFrameParse(DeviceFrameBaseDto * frameDto);
+ void afterCommandReply(DeviceFrameBaseDto * frameDto);
+ void sendDataToSerial(QByteArray data);
+
+signals:
+ void sendDataToDraw(DeviceFrameBaseDto * frameData);
+ void sendCommandToDisplay(QJsonObject command);
+
+public slots:
+ void dataReceivedHandler(QByteArray data);
+ void dataBReceivedHandler(QByteArray data);
+ void commandReceivedHandler(QJsonObject command);
+};
+
+#endif // NTPSERVER_H
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 92a1433..b2476f6 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -38,15 +38,16 @@
QByteArray buffer;
// time replicator
- buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n");
+ buffer.append("$2B21308-13 21010011231111111111111111faf0*").append("\r\n");
+// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
this->dataReceivedHandler(buffer);
- QTimer::singleShot(1000, this, [=](){
- QByteArray buffer;
- buffer.clear();
- buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n");
- this->dataReceivedHandler(buffer);
- });
+// QTimer::singleShot(1000, this, [=](){
+// QByteArray buffer;
+// buffer.clear();
+// buffer.append("$3C21308-13 21010052207111111111111111111111101000000005984*").append("\r\n");
+// this->dataReceivedHandler(buffer);
+// });
// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*");
// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n");
diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri
index fedab85..47dff39 100644
--- a/DeviceHub/device/device.pri
+++ b/DeviceHub/device/device.pri
@@ -7,6 +7,7 @@
HEADERS += $$PWD/TimeReplicator.h
HEADERS += $$PWD/FreqReplicator.h
HEADERS += $$PWD/BCodeTerminal.h
+HEADERS += $$PWD/NtpServer.h
SOURCES += $$PWD/DeviceBase.cpp
SOURCES += $$PWD/FrequencyTuning.cpp
@@ -16,3 +17,4 @@
SOURCES += $$PWD/TimeReplicator.cpp
SOURCES += $$PWD/FreqReplicator.cpp
SOURCES += $$PWD/BCodeTerminal.cpp
+SOURCES += $$PWD/NtpServer.cpp
diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp
index f5195d4..ba9ef57 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.cpp
+++ b/DeviceHub/protocol/DeviceProtocolBase.cpp
@@ -1,11 +1,12 @@
#include "DeviceProtocolBase.h"
-#include "FrequencyTuningProtocolBM.h"
+#include "FrequencyTuningProtocolTX.h"
#include "SignalGeneratorProtocolBM.h"
#include "TimeSwitcherProtocolBM.h"
#include "FreqSwitcherProtocolBM.h"
#include "TimeReplicatorProtocolBM.h"
#include "FreqReplicatorProtocolTX.h"
#include "BCodeTerminalProtocolBM.h"
+#include "NtpServerProtocolBM.h"
#include
@@ -18,7 +19,7 @@
{
if (deviceType == "03" || deviceType.contains("FrequencyTuning") == true)
{
- return new FrequencyTuningProtocolBM();
+ return new FrequencyTuningProtocolTX();
} else if (deviceType == "04" || deviceType.contains("SignalGenerator") == true)
{
return new SignalGeneratorProtocolBM();
@@ -37,6 +38,9 @@
} else if (deviceType == "10" || deviceType.contains("FreqReplicator") == true)
{
return new FreqReplicatorProtocolTX();
+ } else if (deviceType == "11" || deviceType.contains("NtpServer") == true)
+ {
+ return new NtpServerProtocolBM();
}
return nullptr;
diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h
index 64955ad..5d8a47c 100644
--- a/DeviceHub/protocol/DeviceProtocolBase.h
+++ b/DeviceHub/protocol/DeviceProtocolBase.h
@@ -10,9 +10,6 @@
static const int FRAME_SUM_LENGTH = 2;
static const int FRAME_SUB_MIN_SIZE = 2;
-static const QString FREQUENCY_TUNING_FREQ_FRAME_HEAD = "$GLF"; // 帧头
-static const QString FREQUENCY_TUNING_PULSE_FRAME_HEAD = "$GLP"; // 帧头
-
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头
static const QString SIGNAL_GENERATOR_STATUS_FRAME_HEAD = "$GLF"; // 帧头
static const QString SIGNAL_GENERATOR_MJD_FRAME_HEAD = "$GPMJD"; // 帧头
@@ -29,6 +26,9 @@
static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$";
static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*";
+static const QString FREQ_TUNN_STATUS_FRAME_HEAD = "$";
+static const QString FREQ_TUNN_STATUS_FRAME_TAIL = "*";
+
static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26;
static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5;
@@ -45,13 +45,6 @@
static const int FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT = 21;
-static const int FREQUENCY_TUNING_FREQ_FRAME_MIN_LENGTH = FREQUENCY_TUNING_FREQ_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-static const int FREQUENCY_TUNING_PULSE_FRAME_MIN_LENGTH = FREQUENCY_TUNING_PULSE_FRAME_HEAD.length() +
- FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
- FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
-
static const int SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.length() +
FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE +
SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE;
@@ -81,7 +74,7 @@
static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301";
-static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302";
+static const QString FREQUENCY_TUNING_LOCK_FRAME_TYPE = "0302";
static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401";
static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402";
@@ -103,6 +96,9 @@
static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001";
static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002";
+static const QString NTP_SERVER_STATUS_FRAME_TYPE = "1101";
+static const QString NTP_SERVER_CMDREP_TYPE = "1111";
+
class DeviceProtocolBase : public QObject
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolBM.h b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
index 8c7f259..3926efe 100644
--- a/DeviceHub/protocol/FrequencyTuningProtocolBM.h
+++ b/DeviceHub/protocol/FrequencyTuningProtocolBM.h
@@ -6,7 +6,7 @@
#include "protocol/DeviceProtocolBase.h"
#include "dto/FrequencyTuningStatusFreqDto.h"
-#include "dto/FrequencyTuningStatusPulseDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
class FrequencyTuningProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
new file mode 100644
index 0000000..9c47b0e
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.cpp
@@ -0,0 +1,131 @@
+#include "FrequencyTuningProtocolTX.h"
+
+FrequencyTuningProtocolTX::FrequencyTuningProtocolTX(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+FrequencyTuningProtocolTX::~FrequencyTuningProtocolTX()
+{
+
+}
+
+DeviceFrameBaseDto * FrequencyTuningProtocolTX::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ frameData = new FrequencyTuningStatusFreqDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ frameData = new FrequencyTuningStatusLockDto();
+ break;
+
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME:
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+bool FrequencyTuningProtocolTX::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType)
+{
+ // get the raw data between ',' and '*'
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(20, length - 25);
+
+ switch (frameType) {
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME :
+ {
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->devStatus = content.at(0);
+ QList subValues = content.split(0x20);
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjust = subValues.at(1).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->freqAdjustAcc = subValues.at(2).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseShift = subValues.at(3).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->pulseWidth = subValues.at(4).toLongLong();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->phaseAdjust = subValues.at(5).toDouble();
+ ((FrequencyTuningStatusFreqDto *)ftFrameData)->frameType = FREQUENCY_TUNING_FREQ_FRAME_TYPE;
+ break;
+ }
+ case FrequencyTuningProtocolTX::FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME :
+ {
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->lockStatus = content.at(2);
+ ((FrequencyTuningStatusLockDto *)ftFrameData)->frameType = FREQUENCY_TUNING_LOCK_FRAME_TYPE;
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+}
+
+QList FrequencyTuningProtocolTX::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+
+ int start = rawData.indexOf("$");
+ if (start < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("*");
+ if (end < 0) {
+ return resultList;
+ }
+ rawData = rawData.left(end - start + 1);
+
+ QByteArray ba;
+ for (int i = 0; i < rawData.size(); i++)
+ {
+ ba.append(rawData.at(i));
+ if (rawData.at(i) == '*')
+ {
+ resultList.append(ba);
+ ba.clear();
+ }
+ }
+
+ return resultList;
+}
+
+int FrequencyTuningProtocolTX::checkFrame(QByteArray rawData)
+{
+ // 帧尾不是*
+ if (FREQ_TUNN_STATUS_FRAME_TAIL != rawData.at(rawData.size() - 1))
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+
+ // 帧头不是$
+ if (FREQ_TUNN_STATUS_FRAME_HEAD == rawData.at(0))
+ {
+ if (rawData.at(3) == '2')
+ {
+ if (rawData.at(1+2+1+9+7+1) == '2')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::LOCK_FRAME;
+ } else if (rawData.at(1+2+1+9+7+1) == '3')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::STATUS_FRAME;
+ }
+ } else if (rawData.at(3) == '4')
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::CMDREP_FRAME;
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+ } else
+ {
+ return FREQUENCY_TUNING_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
diff --git a/DeviceHub/protocol/FrequencyTuningProtocolTX.h b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
new file mode 100644
index 0000000..a914280
--- /dev/null
+++ b/DeviceHub/protocol/FrequencyTuningProtocolTX.h
@@ -0,0 +1,37 @@
+#ifndef FREQUENCYTUNINGPROTOCOLTX_H
+#define FREQUENCYTUNINGPROTOCOLTX_H
+
+#include
+#include
+
+#include "protocol/DeviceProtocolBase.h"
+#include "dto/FrequencyTuningStatusFreqDto.h"
+#include "dto/FrequencyTuningStatusLockDto.h"
+#include "dto/CommandReplyDto.h"
+
+class FrequencyTuningProtocolTX : public DeviceProtocolBase
+{
+public:
+ explicit FrequencyTuningProtocolTX(QObject *parent = nullptr);
+ ~FrequencyTuningProtocolTX();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum FREQUENCY_TUNING_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ LOCK_FRAME = 2,
+ CMDREP_FRAME = 3
+ };
+};
+
+#endif // FREQUENCYTUNINGPROTOCOLTX_H
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.cpp b/DeviceHub/protocol/NtpServerProtocolBM.cpp
new file mode 100644
index 0000000..9cbc71a
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.cpp
@@ -0,0 +1,172 @@
+#include "NtpServerProtocolBM.h"
+#include "common/utils/QByteUtil.h"
+#include
+
+NtpServerProtocolBM::NtpServerProtocolBM(QObject *parent) : DeviceProtocolBase(parent)
+{
+
+}
+
+NtpServerProtocolBM::~NtpServerProtocolBM()
+{
+
+}
+
+bool NtpServerProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType)
+{
+ if (frameType == NTP_SERVER_FRAME_TYPE::STATUS_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(19, length - 24);
+
+// 1 2 111000 02 220115072016 ff 04120
+ ((NtpServerStatusDto *) frameData)->devStatus = content.at(0);
+
+ ((NtpServerStatusDto *) frameData)->freqInType = content.at(2);
+ ((NtpServerStatusDto *) frameData)->oppsValid = content.at(3);
+ ((NtpServerStatusDto *) frameData)->bdcValid = content.at(4);
+ ((NtpServerStatusDto *) frameData)->dclsValid = content.at(5);
+ ((NtpServerStatusDto *) frameData)->dclsInType = content.at(6);
+ ((NtpServerStatusDto *) frameData)->dclsOutType = content.at(7);
+
+ ((NtpServerStatusDto *) frameData)->refType = content.at(8);
+ ((NtpServerStatusDto *) frameData)->refStatus = content.at(9);
+
+ QString dtStr = content.mid(10, 12);
+ QDateTime dtObj = QDateTime::fromString(dtStr, "yyMMddHHmmss");
+ dtObj = dtObj.addSecs(3600 * 8); // add 8 hours
+ ((NtpServerStatusDto *) frameData)->sysTime = "20" + dtObj.toString("yyMMddHHmmss");
+
+ QByteArray outArray = QByteUtil::hexStringToBytes(content.mid(22, 2));
+ quint8 outByte = outArray.at(0);
+ for (int i = 0; i < 8; i++)
+ {
+ ((NtpServerStatusDto *) frameData)->outValid.append(QString::number(outByte % 2));
+ outByte = outByte / 2;
+ }
+
+ for ( int i = 0; i < 5; i++ )
+ {
+ ((NtpServerStatusDto *) frameData)->tmSrcPrio.append(QString(content.at(24 + i)));
+ }
+
+ ((NtpServerStatusDto *)frameData)->frameType = NTP_SERVER_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == NTP_SERVER_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->frameType = NTP_SERVER_CMDREP_TYPE;
+
+ return true;
+ }
+}
+
+QByteArray NtpServerProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
+{
+ QByteArray commandBytes;
+
+ commandBytes.append("3");
+ commandBytes.append("1308-07").append(0x20);
+ commandBytes.append(devCode);
+ commandBytes.append(commandType);
+
+ if (commandType == "1")
+ {
+ // 4*8 or 2*8
+ QStringList valueList = valueSet.split(",");
+ for (int i = 0; i < valueList.size(); i++)
+ {
+ QString value = valueList.at(i);
+ while (value.size() < 6)
+ {
+ value.prepend("0");
+ }
+ commandBytes.append(value);
+ }
+ } else if (commandType == "2")
+ {
+ QStringList delayParams = valueSet.split(",");
+ if (delayParams.size() == 2)
+ {
+ commandBytes.append(delayParams.at(0));
+ QString delay = delayParams.at(1);
+ while(delay.size() < 11)
+ {
+ delay.insert(1, "0");
+ }
+ commandBytes.append(delay);
+ }
+ }
+
+ commandBytes.append(this->buildCRC16(commandBytes));
+ commandBytes.append("*");
+
+ commandBytes.prepend(QString::number(commandBytes.size() + 3, 16).toUpper().toLocal8Bit());
+ commandBytes.prepend("$");
+
+ return commandBytes;
+}
+
+int NtpServerProtocolBM::checkFrame(QByteArray rawData)
+{
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
+ rawData.size() == rawData.mid(1, 2).toInt(0, 16))
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return NTP_SERVER_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return NTP_SERVER_FRAME_TYPE::CMDREP_FRAME;
+ }
+ } else {
+ return NTP_SERVER_FRAME_TYPE::UNKNOW_FRAME;
+ }
+}
+
+DeviceFrameBaseDto * NtpServerProtocolBM::frameFactory(int frameType)
+{
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::STATUS_FRAME :
+ frameData = new NtpServerStatusDto();
+ break;
+
+ case NtpServerProtocolBM::NTP_SERVER_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
+
+ return frameData;
+}
+
+QList NtpServerProtocolBM::extractFrameList(QByteArray rawData)
+{
+ QList resultList;
+ while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) &&
+ rawData.startsWith("$") == true)
+ {
+ QByteArray ba;
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
+ {
+ ba.append(rawData.mid(0, length));
+ resultList.append(ba);
+ ba.clear();
+ rawData = rawData.mid(length, rawData.size() - length);
+ } else
+ {
+ break;
+ }
+ }
+
+ return resultList;
+}
diff --git a/DeviceHub/protocol/NtpServerProtocolBM.h b/DeviceHub/protocol/NtpServerProtocolBM.h
new file mode 100644
index 0000000..735e622
--- /dev/null
+++ b/DeviceHub/protocol/NtpServerProtocolBM.h
@@ -0,0 +1,34 @@
+#ifndef NTPSERVERPROTOCOLBM_H
+#define NTPSERVERPROTOCOLBM_H
+
+#include "DeviceProtocolBase.h"
+#include "dto/NtpServerStatusDto.h"
+#include "dto/CommandReplyDto.h"
+
+class NtpServerProtocolBM : public DeviceProtocolBase
+{
+ Q_OBJECT
+public:
+ explicit NtpServerProtocolBM(QObject *parent = nullptr);
+ ~NtpServerProtocolBM();
+
+ // 解析数据
+ bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType);
+ QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet);
+ DeviceFrameBaseDto * frameFactory(int frameType);
+
+ //
+ QList extractFrameList(QByteArray rawData);
+
+ // 检测帧格式,帧头帧尾
+ int checkFrame(QByteArray rawData);
+
+ enum NTP_SERVER_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
+};
+
+#endif // NTPSERVERPROTOCOLBM_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
index 9de0d94..406a141 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.cpp
@@ -11,10 +11,11 @@
QJsonObject dataObj;
dataObj.insert("devStatus", devStatus);
- dataObj.insert("inputTimeType", inputTimeType);
- dataObj.insert("inputValid", inputValid);
+ dataObj.insert("freqAdjust", freqAdjust);
dataObj.insert("freqAdjustAcc", freqAdjustAcc);
- dataObj.insert("pulseAdjustAcc", (float) pulseAdjustAcc * 0.1);
+ dataObj.insert("pulseWidth", pulseWidth);
+ dataObj.insert("phaseAdjust", phaseAdjust);
+ dataObj.insert("phaseShift", phaseShift);
jsonObj.insert("ts", this->milisecond);
jsonObj.insert("frameType", this->frameType);
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
index 83eb103..de9bc01 100644
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusFreqDto.h
@@ -6,7 +6,7 @@
/**
* @brief The FrequencyTuningStatusFreqDto class
- * 频率微调设备工作状态:频率输出状态
+ * 频率微调设备工作状态:设备值信息
*/
class FrequencyTuningStatusFreqDto : public DeviceFrameBaseDto
{
@@ -15,10 +15,11 @@
explicit FrequencyTuningStatusFreqDto(QObject *parent = nullptr);
QString devStatus; // <24> 设备工作状态:1=正常;0=异常
- QString inputTimeType; // <25> 输入时钟类别:1=5MHz;0=10MHz
- QString inputValid; // <26> 输入有效性:1=有效;0=无效
- qlonglong freqAdjustAcc; // <17> 频率调整累计值,单位1pHz
- qlonglong pulseAdjustAcc; // <18> 相位调整累计值,单位0.1fs
+ double freqAdjust; // <25> 频率步进量
+ double freqAdjustAcc; // <26> 频率累计偏移量
+ qlonglong phaseShift; // PPS移相量
+ qlonglong pulseWidth; // PPS脉冲宽度
+ double phaseAdjust; // 相位步进量
QJsonObject toJSON();
};
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
new file mode 100644
index 0000000..9a8e259
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.cpp
@@ -0,0 +1,20 @@
+#include "FrequencyTuningStatusLockDto.h"
+
+FrequencyTuningStatusLockDto::FrequencyTuningStatusLockDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject FrequencyTuningStatusLockDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("lockStatus", lockStatus);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
new file mode 100644
index 0000000..5088cd8
--- /dev/null
+++ b/DeviceHub/protocol/dto/FrequencyTuningStatusLockDto.h
@@ -0,0 +1,22 @@
+#ifndef FREQUENCYTUNINGSTATUSLOCKDTO_H
+#define FREQUENCYTUNINGSTATUSLOCKDTO_H
+
+#include
+#include "protocol/dto/DeviceFrameBaseDto.h"
+
+/**
+ * @brief The FrequencyTuningStatusLockDto class
+ * 频率微调设备工作状态:锁相环状态
+ */
+class FrequencyTuningStatusLockDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit FrequencyTuningStatusLockDto(QObject *parent = nullptr);
+
+ QString lockStatus; // <1> 锁相环状态:1=锁定;0=失锁
+
+ QJsonObject toJSON();
+};
+
+#endif // FREQUENCYTUNINGSTATUSLOCKDTO_H
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
deleted file mode 100644
index aefae50..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "FrequencyTuningStatusPulseDto.h"
-
-FrequencyTuningStatusPulseDto::FrequencyTuningStatusPulseDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject FrequencyTuningStatusPulseDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("synchStatus", synchStatus);
- dataObj.insert("secondDiff", secondDiff);
- dataObj.insert("refValid", refValid);
- dataObj.insert("phaseShiftAcc", phaseShiftAcc);
- dataObj.insert("pulseWidth", pulseWidth);
-
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("frameType", this->frameType);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h b/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
deleted file mode 100644
index 2745f8d..0000000
--- a/DeviceHub/protocol/dto/FrequencyTuningStatusPulseDto.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef FREQUENCYTUNINGSTATUSPULSEDTO_H
-#define FREQUENCYTUNINGSTATUSPULSEDTO_H
-
-#include
-#include "protocol/dto/DeviceFrameBaseDto.h"
-
-/**
- * @brief The FrequencyTuningStatusPulseDto class
- * 频率微调设备工作状态:秒脉冲状态
- */
-class FrequencyTuningStatusPulseDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit FrequencyTuningStatusPulseDto(QObject *parent = nullptr);
-
- QString synchStatus; // <1> 同步状态:1=正常;0=异常
- qlonglong secondDiff; // <2> 秒差,单位1ns,范围-500ms~500ms
- QString refValid; // <3> 参考有效:1=有效;0=无效
- qlonglong phaseShiftAcc; // <4> 移相累计值,单位1ps,范围-500ms~500ms
- qlonglong pulseWidth; // <5> 移脉宽,单位1ns,范围10us~500ms
-
- QJsonObject toJSON();
-};
-
-#endif // FREQUENCYTUNINGSTATUSPULSEDTO_H
diff --git a/DeviceHub/protocol/dto/NtpServerStatusDto.cpp b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
new file mode 100644
index 0000000..ad9fccc
--- /dev/null
+++ b/DeviceHub/protocol/dto/NtpServerStatusDto.cpp
@@ -0,0 +1,171 @@
+#include "NtpServerStatusDto.h"
+
+NtpServerStatusDto::NtpServerStatusDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+
+QJsonObject NtpServerStatusDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("devStatus", devStatus);
+ dataObj.insert("freqInType", freqInType);
+ dataObj.insert("freqInTypeStr", freqInType == "1" ? "5M" : (freqInType == "2" ? "10M" : "无信号"));
+ dataObj.insert("oppsValid", oppsValid);
+ dataObj.insert("bdcValid", bdcValid);
+ dataObj.insert("dclsValid", dclsValid);
+ dataObj.insert("dclsInType", dclsInType);
+ dataObj.insert("dclsOutType", dclsOutType);
+ dataObj.insert("refType", refType);
+ dataObj.insert("refStatus", refStatus);
+ dataObj.insert("sysTime", sysTime);
+
+ QJsonArray outValidArray;
+ for (int i = 0; i < outValid.size(); i++)
+ {
+ outValidArray.append(outValid.at(i));
+ }
+ dataObj.insert("outValid", outValidArray);
+
+ QJsonArray tmSrcPrioArray;
+ QJsonArray tmSrcPrioStrArray;
+ for (int i = 0; i < tmSrcPrio.size(); i++)
+ {
+ tmSrcPrioArray.append(tmSrcPrio.at(i));
+
+ QString tmSrcStr = "";
+ switch (tmSrcPrio.at(i).toInt()) {
+ case 0 :
+ tmSrcStr = "BDC";
+ break;
+ case 1:
+ tmSrcStr = "1PPS";
+ break;
+ case 2:
+ tmSrcStr = "Freq(5M/10M)";
+ break;
+ case 3:
+ tmSrcStr = "AM";
+ break;
+ case 4:
+ tmSrcStr = "DCLS";
+ break;
+ }
+ tmSrcPrioStrArray.append(tmSrcStr);
+ }
+ dataObj.insert("tmSrcPrio", tmSrcPrioArray);
+
+ switch (dclsInType.toInt()) {
+ case 0 :
+ dclsInTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsInTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsInTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsInTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsInTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsInTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsInTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch(dclsOutType.toInt())
+ {
+ case 0 :
+ dclsOutTypeStr = "IRIG-A";
+ break;
+ case 1:
+ dclsOutTypeStr = "IRIG-B";
+ break;
+ case 2:
+ dclsOutTypeStr = "IRIG-E";
+ break;
+ case 3:
+ dclsOutTypeStr = "IRIG-G";
+ break;
+ case 4:
+ dclsOutTypeStr = "IRIG-NASA36";
+ break;
+ case 5:
+ dclsOutTypeStr = "IRIG-XR3";
+ break;
+ case 6:
+ dclsOutTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refType.toInt()) {
+ case 0 :
+ refTypeStr = "BDC";
+ break;
+ case 1:
+ refTypeStr = "1PPS";
+ break;
+ case 2:
+ refTypeStr = "10M/5M";
+ break;
+ case 3:
+ refTypeStr = "IRIG-A";
+ break;
+ case 4:
+ refTypeStr = "IRIG-B";
+ break;
+ case 5:
+ refTypeStr = "IRIG-E";
+ break;
+ case 6:
+ refTypeStr = "IRIG-G";
+ break;
+ case 7:
+ refTypeStr = "IRIG-NASA36";
+ break;
+ case 8:
+ refTypeStr = "IRIG-XR3";
+ break;
+ case 9:
+ refTypeStr = "IRIG-2137";
+ break;
+ }
+
+ switch (refStatus.toInt()) {
+ case 0 :
+ refStatusStr = "自由";
+ break;
+ case 1:
+ refStatusStr = "跟踪";
+ break;
+ case 2:
+ refStatusStr = "锁定";
+ break;
+ case 3:
+ refStatusStr = "守时";
+ break;
+ case 4:
+ refStatusStr = "预热";
+ break;
+ }
+
+// dataObj.insert("dclsInTypeStr", dclsInTypeStr);
+// dataObj.insert("dclsOutTypeStr", dclsOutTypeStr);
+// dataObj.insert("refTypeStr", refTypeStr);
+// dataObj.insert("refStatusStr", refStatusStr);
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", this->frameType);
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/NtpServerStatusDto.h b/DeviceHub/protocol/dto/NtpServerStatusDto.h
new file mode 100644
index 0000000..a9b8a9c
--- /dev/null
+++ b/DeviceHub/protocol/dto/NtpServerStatusDto.h
@@ -0,0 +1,35 @@
+#ifndef NTPSERVERSTATUSDTO_H
+#define NTPSERVERSTATUSDTO_H
+
+#include
+#include "DeviceFrameBaseDto.h"
+
+class NtpServerStatusDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit NtpServerStatusDto(QObject * parent = nullptr);
+
+ QString devStatus;
+ QString freqInType;
+ QString oppsValid;
+ QString bdcValid;
+ QString dclsValid;
+ QString dclsInType;
+ QString dclsOutType;
+ QString refType;
+ QString refStatus;
+ QString sysTime;
+ QList outValid;
+ QList tmSrcPrio;
+
+ QString freqInTypeStr;
+ QString dclsInTypeStr;
+ QString dclsOutTypeStr;
+ QString refTypeStr;
+ QString refStatusStr;
+
+ QJsonObject toJSON() override;
+};
+
+#endif // NTPSERVERSTATUSDTO_H
diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri
index a792cf0..d0e9524 100644
--- a/DeviceHub/protocol/protocol.pri
+++ b/DeviceHub/protocol/protocol.pri
@@ -1,7 +1,7 @@
HEADERS += $$PWD/dto/DeviceFrameBaseDto.h
HEADERS += $$PWD/dto/FrequencyTuningStatusFreqDto.h
-HEADERS += $$PWD/dto/FrequencyTuningStatusPulseDto.h
+HEADERS += $$PWD/dto/FrequencyTuningStatusLockDto.h
HEADERS += $$PWD/dto/SignalGeneratorStatusDto.h
HEADERS += $$PWD/dto/SignalGeneratorInterfaceDto.h
HEADERS += $$PWD/dto/SignalGeneratorZDATimeDto.h
@@ -13,16 +13,18 @@
HEADERS += $$PWD/dto/BCodeTerminalStatusDto.h
HEADERS += $$PWD/dto/TimeReplicatorStatusDto.h
HEADERS += $$PWD/dto/FreqReplicatorStatusDto.h
+HEADERS += $$PWD/dto/NtpServerStatusDto.h
HEADERS += $$PWD/dto/CommandReplyDto.h
HEADERS += $$PWD/DeviceProtocolBase.h
-HEADERS += $$PWD/FrequencyTuningProtocolBM.h
+HEADERS += $$PWD/FrequencyTuningProtocolTX.h
HEADERS += $$PWD/SignalGeneratorProtocolBM.h
HEADERS += $$PWD/TimeSwitcherProtocolBM.h
HEADERS += $$PWD/FreqSwitcherProtocolBM.h
HEADERS += $$PWD/BCodeTerminalProtocolBM.h
HEADERS += $$PWD/TimeReplicatorProtocolBM.h
HEADERS += $$PWD/FreqReplicatorProtocolTX.h
+HEADERS += $$PWD/NtpServerProtocolBM.h
SOURCES += $$PWD/dto/SignalGeneratorStatusDto.cpp
@@ -30,20 +32,23 @@
SOURCES += $$PWD/dto/SignalGeneratorZDATimeDto.cpp
SOURCES += $$PWD/dto/SignalGeneratorMJDTimeDto.cpp
SOURCES += $$PWD/dto/FrequencyTuningStatusFreqDto.cpp
-SOURCES += $$PWD/dto/FrequencyTuningStatusPulseDto.cpp
+SOURCES += $$PWD/dto/FrequencyTuningStatusLockDto.cpp
SOURCES += $$PWD/dto/TimeSwitcherStatusDto.cpp
SOURCES += $$PWD/dto/TimeSwitcherInterfaceDto.cpp
SOURCES += $$PWD/dto/FreqSwitcherInterfaceDto.cpp
SOURCES += $$PWD/dto/TimeReplicatorStatusDto.cpp
SOURCES += $$PWD/dto/FreqSwitcherStatusDto.cpp
-SOURCES += $$PWD/dto/CommandReplyDto.cpp
-SOURCES += $$PWD/DeviceProtocolBase.cpp
-SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp
-SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp
SOURCES += $$PWD/dto/FreqReplicatorStatusDto.cpp
SOURCES += $$PWD/dto/BCodeTerminalStatusDto.cpp
+SOURCES += $$PWD/dto/NtpServerStatusDto.cpp
+SOURCES += $$PWD/dto/CommandReplyDto.cpp
+
+SOURCES += $$PWD/DeviceProtocolBase.cpp
+SOURCES += $$PWD/FrequencyTuningProtocolTX.cpp
+SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp
SOURCES += $$PWD/TimeSwitcherProtocolBM.cpp
SOURCES += $$PWD/FreqSwitcherProtocolBM.cpp
SOURCES += $$PWD/TimeReplicatorProtocolBM.cpp
SOURCES += $$PWD/FreqReplicatorProtocolTX.cpp
SOURCES += $$PWD/BCodeTerminalProtocolBM.cpp
+SOURCES += $$PWD/NtpServerProtocolBM.cpp