diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.cpp b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp new file mode 100644 index 0000000..f7353ec --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp @@ -0,0 +1,73 @@ +#include "DeviceStatusProtocolBase.h" +//#include "SignalGeneratorProtocolBM.h" +//#include "FrequencyTuningProtocolBM.h" +//#include "TimeSwitcherProtocolBM.h" +//#include "FreqSwitcherProtocolBM.h" +//#include "TimeReplicatorProtocolBM.h" +//#include "FreqReplicatorProtocolTX.h" +//#include "BCodeTerminalProtocolBM.h" + +#include + +DeviceStatusProtocolBase::DeviceStatusProtocolBase(QObject *parent) : QObject(parent) +{ + +} + +DeviceStatusProtocolBase * DeviceStatusProtocolBase::deviceStatusProtocolFactory(QString deviceType) +{ + std::cout << deviceType.toStdString() << std::endl; +// if (deviceType.contains("SignalGenerator") == true) +// { +// return new SignalGeneratorProtocolBM(); +// } else if (deviceType.contains("FrequencyTuning") == true) +// { +// return new FrequencyTuningProtocolBM(); +// } else if (deviceType.contains("TimeSwitcher") == true) +// { +// return new TimeSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqSwitcher") == true) +// { +// return new FreqSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqReplicator") == true) +// { +// return new FreqReplicatorProtocolTX(); +// } else if (deviceType.contains("TimeReplicator") == true) +// { +// return new TimeReplicatorProtocolBM(); +// } else if (deviceType.contains("BCodeTerminal") == true) +// { +// return new BCodeTerminalProtocolBM(); +// } + + return nullptr; +} + +QByteArray DeviceStatusProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +{ + QByteArray commandBytes; + commandBytes.append(commandType).append(","); + commandBytes.append(valueSet); + + QString xorValue = this->calculateXOR(commandBytes); + + commandBytes.prepend("$"); + commandBytes.append("*"); + commandBytes.append(xorValue); + + return commandBytes; +} + +QString DeviceStatusProtocolBase::calculateXOR(QByteArray byteArray) +{ + quint8 xorValue = 0; + + for (int i =0; i < byteArray.size(); i++) + { + xorValue = xorValue ^ byteArray.at(i); + } + + QString str; + str.sprintf("%02X", xorValue); + return str; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.cpp b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp new file mode 100644 index 0000000..f7353ec --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp @@ -0,0 +1,73 @@ +#include "DeviceStatusProtocolBase.h" +//#include "SignalGeneratorProtocolBM.h" +//#include "FrequencyTuningProtocolBM.h" +//#include "TimeSwitcherProtocolBM.h" +//#include "FreqSwitcherProtocolBM.h" +//#include "TimeReplicatorProtocolBM.h" +//#include "FreqReplicatorProtocolTX.h" +//#include "BCodeTerminalProtocolBM.h" + +#include + +DeviceStatusProtocolBase::DeviceStatusProtocolBase(QObject *parent) : QObject(parent) +{ + +} + +DeviceStatusProtocolBase * DeviceStatusProtocolBase::deviceStatusProtocolFactory(QString deviceType) +{ + std::cout << deviceType.toStdString() << std::endl; +// if (deviceType.contains("SignalGenerator") == true) +// { +// return new SignalGeneratorProtocolBM(); +// } else if (deviceType.contains("FrequencyTuning") == true) +// { +// return new FrequencyTuningProtocolBM(); +// } else if (deviceType.contains("TimeSwitcher") == true) +// { +// return new TimeSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqSwitcher") == true) +// { +// return new FreqSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqReplicator") == true) +// { +// return new FreqReplicatorProtocolTX(); +// } else if (deviceType.contains("TimeReplicator") == true) +// { +// return new TimeReplicatorProtocolBM(); +// } else if (deviceType.contains("BCodeTerminal") == true) +// { +// return new BCodeTerminalProtocolBM(); +// } + + return nullptr; +} + +QByteArray DeviceStatusProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +{ + QByteArray commandBytes; + commandBytes.append(commandType).append(","); + commandBytes.append(valueSet); + + QString xorValue = this->calculateXOR(commandBytes); + + commandBytes.prepend("$"); + commandBytes.append("*"); + commandBytes.append(xorValue); + + return commandBytes; +} + +QString DeviceStatusProtocolBase::calculateXOR(QByteArray byteArray) +{ + quint8 xorValue = 0; + + for (int i =0; i < byteArray.size(); i++) + { + xorValue = xorValue ^ byteArray.at(i); + } + + QString str; + str.sprintf("%02X", xorValue); + return str; +} diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.h b/DeviceHub/protocol/DeviceStatusProtocolBase.h new file mode 100644 index 0000000..ae3d4cb --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.h @@ -0,0 +1,124 @@ +#ifndef DEVICESTATUSPROTOCOLBASE_H +#define DEVICESTATUSPROTOCOLBASE_H + +#include +#include "dto/DeviceFrameBaseDto.h" + +static const QString FRAME_TAIL = "\r\n"; // 帧尾 +static const QString FRAME_CONTENT_SEP = ","; // 帧内分隔符 +static const QString FRAME_SUM_SEP = "*"; // 异或和字段的分隔符 +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"; // 帧头 +static const QString SIGNAL_GENERATOR_ZDA_FRAME_HEAD = "$GPZDA"; // 帧头 + +static const QString TIME_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString TIME_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString FREQ_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_REPLICATOR_STAUTS_FRAME_HEAD = "AA55"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$"; +static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*"; + + +static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26; +static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5; + +static const int SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT = 2; +static const int SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT = 11; +static const int SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT = 6; +static const int SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT = 4; + +static const int TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +static const int TIME_SWITCHER_STATUS_FRAME_SUB_COUNT = 24; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +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; +static const int SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_ZDA_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_MJD_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = TIME_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH = TIME_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = FREQ_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH = FREQ_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + + +static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301"; +static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302"; + +static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401"; +static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402"; +static const QString SIGNAL_GENERATOR_MJD_FRAME_TYPE = "0403"; +static const QString SIGNAL_GENERATOR_ZDA_FRAME_TYPE = "0404"; + +static const QString TIME_SWITCHER_STATUS_FRAME_TYPE = "0501"; +static const QString TIME_SWITCHER_INTERFACE_FRAME_TYPE = "0502"; + +static const QString FREQ_SWITCHER_STATUS_FRAME_TYPE = "0601"; +static const QString FREQ_SWITCHER_INTERFACE_FRAME_TYPE = "0602"; + +static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; + +static const QString FREQ_REPLICATOR_STATUS_FRAME_TYPE = "1001"; + + +class DeviceStatusProtocolBase : public QObject +{ + Q_OBJECT +public: + explicit DeviceStatusProtocolBase(QObject *parent = nullptr); + + static DeviceStatusProtocolBase * deviceStatusProtocolFactory(QString deviceType); + + QString calculateXOR(QByteArray byteArray); + + virtual DeviceFrameBaseDto * frameFactory(int frameType) = 0; + virtual int checkFrame(QByteArray rawData) = 0; + virtual QList extractFrameList(QByteArray rawData) = 0; + virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType) = 0; + virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + +signals: + +}; + +#endif // DEVICESTATUSPROTOCOLBASE_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.cpp b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp new file mode 100644 index 0000000..f7353ec --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp @@ -0,0 +1,73 @@ +#include "DeviceStatusProtocolBase.h" +//#include "SignalGeneratorProtocolBM.h" +//#include "FrequencyTuningProtocolBM.h" +//#include "TimeSwitcherProtocolBM.h" +//#include "FreqSwitcherProtocolBM.h" +//#include "TimeReplicatorProtocolBM.h" +//#include "FreqReplicatorProtocolTX.h" +//#include "BCodeTerminalProtocolBM.h" + +#include + +DeviceStatusProtocolBase::DeviceStatusProtocolBase(QObject *parent) : QObject(parent) +{ + +} + +DeviceStatusProtocolBase * DeviceStatusProtocolBase::deviceStatusProtocolFactory(QString deviceType) +{ + std::cout << deviceType.toStdString() << std::endl; +// if (deviceType.contains("SignalGenerator") == true) +// { +// return new SignalGeneratorProtocolBM(); +// } else if (deviceType.contains("FrequencyTuning") == true) +// { +// return new FrequencyTuningProtocolBM(); +// } else if (deviceType.contains("TimeSwitcher") == true) +// { +// return new TimeSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqSwitcher") == true) +// { +// return new FreqSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqReplicator") == true) +// { +// return new FreqReplicatorProtocolTX(); +// } else if (deviceType.contains("TimeReplicator") == true) +// { +// return new TimeReplicatorProtocolBM(); +// } else if (deviceType.contains("BCodeTerminal") == true) +// { +// return new BCodeTerminalProtocolBM(); +// } + + return nullptr; +} + +QByteArray DeviceStatusProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +{ + QByteArray commandBytes; + commandBytes.append(commandType).append(","); + commandBytes.append(valueSet); + + QString xorValue = this->calculateXOR(commandBytes); + + commandBytes.prepend("$"); + commandBytes.append("*"); + commandBytes.append(xorValue); + + return commandBytes; +} + +QString DeviceStatusProtocolBase::calculateXOR(QByteArray byteArray) +{ + quint8 xorValue = 0; + + for (int i =0; i < byteArray.size(); i++) + { + xorValue = xorValue ^ byteArray.at(i); + } + + QString str; + str.sprintf("%02X", xorValue); + return str; +} diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.h b/DeviceHub/protocol/DeviceStatusProtocolBase.h new file mode 100644 index 0000000..ae3d4cb --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.h @@ -0,0 +1,124 @@ +#ifndef DEVICESTATUSPROTOCOLBASE_H +#define DEVICESTATUSPROTOCOLBASE_H + +#include +#include "dto/DeviceFrameBaseDto.h" + +static const QString FRAME_TAIL = "\r\n"; // 帧尾 +static const QString FRAME_CONTENT_SEP = ","; // 帧内分隔符 +static const QString FRAME_SUM_SEP = "*"; // 异或和字段的分隔符 +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"; // 帧头 +static const QString SIGNAL_GENERATOR_ZDA_FRAME_HEAD = "$GPZDA"; // 帧头 + +static const QString TIME_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString TIME_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString FREQ_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_REPLICATOR_STAUTS_FRAME_HEAD = "AA55"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$"; +static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*"; + + +static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26; +static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5; + +static const int SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT = 2; +static const int SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT = 11; +static const int SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT = 6; +static const int SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT = 4; + +static const int TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +static const int TIME_SWITCHER_STATUS_FRAME_SUB_COUNT = 24; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +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; +static const int SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_ZDA_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_MJD_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = TIME_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH = TIME_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = FREQ_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH = FREQ_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + + +static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301"; +static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302"; + +static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401"; +static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402"; +static const QString SIGNAL_GENERATOR_MJD_FRAME_TYPE = "0403"; +static const QString SIGNAL_GENERATOR_ZDA_FRAME_TYPE = "0404"; + +static const QString TIME_SWITCHER_STATUS_FRAME_TYPE = "0501"; +static const QString TIME_SWITCHER_INTERFACE_FRAME_TYPE = "0502"; + +static const QString FREQ_SWITCHER_STATUS_FRAME_TYPE = "0601"; +static const QString FREQ_SWITCHER_INTERFACE_FRAME_TYPE = "0602"; + +static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; + +static const QString FREQ_REPLICATOR_STATUS_FRAME_TYPE = "1001"; + + +class DeviceStatusProtocolBase : public QObject +{ + Q_OBJECT +public: + explicit DeviceStatusProtocolBase(QObject *parent = nullptr); + + static DeviceStatusProtocolBase * deviceStatusProtocolFactory(QString deviceType); + + QString calculateXOR(QByteArray byteArray); + + virtual DeviceFrameBaseDto * frameFactory(int frameType) = 0; + virtual int checkFrame(QByteArray rawData) = 0; + virtual QList extractFrameList(QByteArray rawData) = 0; + virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType) = 0; + virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + +signals: + +}; + +#endif // DEVICESTATUSPROTOCOLBASE_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h new file mode 100644 index 0000000..f14808f --- /dev/null +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -0,0 +1,28 @@ +#ifndef DEVICEFRAMEBASEDTO_H +#define DEVICEFRAMEBASEDTO_H + +#include +#include +#include +#include + +class DeviceFrameBaseDto : public QObject +{ + Q_OBJECT +public: + explicit DeviceFrameBaseDto(QObject *parent = nullptr) {} + + QByteArray rawFrame; // 原始帧字节数组 + + QString timestamp; // 时间戳字符串 + qlonglong milisecond; // 毫秒计数 + QString devCode; + QString frameType; // 帧类型 + + virtual QJsonObject toJSON() = 0; + +signals: + +}; + +#endif // DEVICEFRAMEBASEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.cpp b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp new file mode 100644 index 0000000..f7353ec --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp @@ -0,0 +1,73 @@ +#include "DeviceStatusProtocolBase.h" +//#include "SignalGeneratorProtocolBM.h" +//#include "FrequencyTuningProtocolBM.h" +//#include "TimeSwitcherProtocolBM.h" +//#include "FreqSwitcherProtocolBM.h" +//#include "TimeReplicatorProtocolBM.h" +//#include "FreqReplicatorProtocolTX.h" +//#include "BCodeTerminalProtocolBM.h" + +#include + +DeviceStatusProtocolBase::DeviceStatusProtocolBase(QObject *parent) : QObject(parent) +{ + +} + +DeviceStatusProtocolBase * DeviceStatusProtocolBase::deviceStatusProtocolFactory(QString deviceType) +{ + std::cout << deviceType.toStdString() << std::endl; +// if (deviceType.contains("SignalGenerator") == true) +// { +// return new SignalGeneratorProtocolBM(); +// } else if (deviceType.contains("FrequencyTuning") == true) +// { +// return new FrequencyTuningProtocolBM(); +// } else if (deviceType.contains("TimeSwitcher") == true) +// { +// return new TimeSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqSwitcher") == true) +// { +// return new FreqSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqReplicator") == true) +// { +// return new FreqReplicatorProtocolTX(); +// } else if (deviceType.contains("TimeReplicator") == true) +// { +// return new TimeReplicatorProtocolBM(); +// } else if (deviceType.contains("BCodeTerminal") == true) +// { +// return new BCodeTerminalProtocolBM(); +// } + + return nullptr; +} + +QByteArray DeviceStatusProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +{ + QByteArray commandBytes; + commandBytes.append(commandType).append(","); + commandBytes.append(valueSet); + + QString xorValue = this->calculateXOR(commandBytes); + + commandBytes.prepend("$"); + commandBytes.append("*"); + commandBytes.append(xorValue); + + return commandBytes; +} + +QString DeviceStatusProtocolBase::calculateXOR(QByteArray byteArray) +{ + quint8 xorValue = 0; + + for (int i =0; i < byteArray.size(); i++) + { + xorValue = xorValue ^ byteArray.at(i); + } + + QString str; + str.sprintf("%02X", xorValue); + return str; +} diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.h b/DeviceHub/protocol/DeviceStatusProtocolBase.h new file mode 100644 index 0000000..ae3d4cb --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.h @@ -0,0 +1,124 @@ +#ifndef DEVICESTATUSPROTOCOLBASE_H +#define DEVICESTATUSPROTOCOLBASE_H + +#include +#include "dto/DeviceFrameBaseDto.h" + +static const QString FRAME_TAIL = "\r\n"; // 帧尾 +static const QString FRAME_CONTENT_SEP = ","; // 帧内分隔符 +static const QString FRAME_SUM_SEP = "*"; // 异或和字段的分隔符 +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"; // 帧头 +static const QString SIGNAL_GENERATOR_ZDA_FRAME_HEAD = "$GPZDA"; // 帧头 + +static const QString TIME_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString TIME_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString FREQ_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_REPLICATOR_STAUTS_FRAME_HEAD = "AA55"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$"; +static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*"; + + +static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26; +static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5; + +static const int SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT = 2; +static const int SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT = 11; +static const int SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT = 6; +static const int SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT = 4; + +static const int TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +static const int TIME_SWITCHER_STATUS_FRAME_SUB_COUNT = 24; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +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; +static const int SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_ZDA_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_MJD_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = TIME_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH = TIME_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = FREQ_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH = FREQ_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + + +static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301"; +static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302"; + +static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401"; +static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402"; +static const QString SIGNAL_GENERATOR_MJD_FRAME_TYPE = "0403"; +static const QString SIGNAL_GENERATOR_ZDA_FRAME_TYPE = "0404"; + +static const QString TIME_SWITCHER_STATUS_FRAME_TYPE = "0501"; +static const QString TIME_SWITCHER_INTERFACE_FRAME_TYPE = "0502"; + +static const QString FREQ_SWITCHER_STATUS_FRAME_TYPE = "0601"; +static const QString FREQ_SWITCHER_INTERFACE_FRAME_TYPE = "0602"; + +static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; + +static const QString FREQ_REPLICATOR_STATUS_FRAME_TYPE = "1001"; + + +class DeviceStatusProtocolBase : public QObject +{ + Q_OBJECT +public: + explicit DeviceStatusProtocolBase(QObject *parent = nullptr); + + static DeviceStatusProtocolBase * deviceStatusProtocolFactory(QString deviceType); + + QString calculateXOR(QByteArray byteArray); + + virtual DeviceFrameBaseDto * frameFactory(int frameType) = 0; + virtual int checkFrame(QByteArray rawData) = 0; + virtual QList extractFrameList(QByteArray rawData) = 0; + virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType) = 0; + virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + +signals: + +}; + +#endif // DEVICESTATUSPROTOCOLBASE_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h new file mode 100644 index 0000000..f14808f --- /dev/null +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -0,0 +1,28 @@ +#ifndef DEVICEFRAMEBASEDTO_H +#define DEVICEFRAMEBASEDTO_H + +#include +#include +#include +#include + +class DeviceFrameBaseDto : public QObject +{ + Q_OBJECT +public: + explicit DeviceFrameBaseDto(QObject *parent = nullptr) {} + + QByteArray rawFrame; // 原始帧字节数组 + + QString timestamp; // 时间戳字符串 + qlonglong milisecond; // 毫秒计数 + QString devCode; + QString frameType; // 帧类型 + + virtual QJsonObject toJSON() = 0; + +signals: + +}; + +#endif // DEVICEFRAMEBASEDTO_H diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri new file mode 100644 index 0000000..671d58c --- /dev/null +++ b/DeviceHub/protocol/protocol.pri @@ -0,0 +1,49 @@ + +HEADERS += $$PWD/dto/DeviceFrameBaseDto.h +#HEADERS += $$PWD/dto/SignalGeneratorStatusDto.h +#HEADERS += $$PWD/dto/SignalGeneratorInterfaceDto.h +#HEADERS += $$PWD/dto/SignalGeneratorZDATimeDto.h +#HEADERS += $$PWD/dto/SignalGeneratorMJDTimeDto.h +#HEADERS += $$PWD/dto/SignalGeneratorSetting.h +#HEADERS += $$PWD/dto/FrequencyTuningStatusFreqDto.h +#HEADERS += $$PWD/dto/FrequencyTuningStatusPulseDto.h +#HEADERS += $$PWD/dto/FrequencyTuningSettingDto.h +#HEADERS += $$PWD/dto/TimeSwitcherStatusDto.h +#HEADERS += $$PWD/dto/TimeSwitcherInterfaceDto.h +#HEADERS += $$PWD/dto/FreqSwitcherInterfaceDto.h +#HEADERS += $$PWD/dto/FreqSwitcherStatusDto.h +#HEADERS += $$PWD/dto/TimeReplicatorStatusDto.h +#HEADERS += $$PWD/dto/FreqReplicatorStatusDto.h +#HEADERS += $$PWD/dto/BCodeTerminalStatusDto.h +HEADERS += $$PWD/DeviceStatusProtocolBase.h +#HEADERS += $$PWD/SignalGeneratorProtocolBM.h +#HEADERS += $$PWD/FrequencyTuningProtocolBM.h +#HEADERS += $$PWD/TimeSwitcherProtocolBM.h +#HEADERS += $$PWD/FreqSwitcherProtocolBM.h +#HEADERS += $$PWD/TimeReplicatorProtocolBM.h +#HEADERS += $$PWD/FreqReplicatorProtocolTX.h +#HEADERS += $$PWD/BCodeTerminalProtocolBM.h + +#SOURCES += $$PWD/dto/SignalGeneratorStatusDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorInterfaceDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorZDATimeDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorMJDTimeDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorSetting.cpp +#SOURCES += $$PWD/dto/FrequencyTuningStatusFreqDto.cpp +#SOURCES += $$PWD/dto/FrequencyTuningStatusPulseDto.cpp +#SOURCES += $$PWD/dto/FrequencyTuningSettingDto.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/DeviceStatusProtocolBase.cpp +#SOURCES += $$PWD/dto/FreqReplicatorStatusDto.cpp +#SOURCES += $$PWD/dto/BCodeTerminalStatusDto.cpp +#SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp +#SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp +#SOURCES += $$PWD/TimeSwitcherProtocolBM.cpp +#SOURCES += $$PWD/FreqSwitcherProtocolBM.cpp +#SOURCES += $$PWD/TimeReplicatorProtocolBM.cpp +#SOURCES += $$PWD/FreqReplicatorProtocolTX.cpp +#SOURCES += $$PWD/BCodeTerminalProtocolBM.cpp diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index 2211193..cdd570d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -17,15 +17,22 @@ SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp +SOURCES += FrequencyTuningForm.cpp +SOURCES += SignalGeneratorForm.cpp HEADERS += DeviceHubWindow.h +HEADERS += FrequencyTuningForm.h +HEADERS += SignalGeneratorForm.h FORMS += DeviceHubWindow.ui +FORMS += FrequencyTuningForm.ui +FORMS += SignalGeneratorForm.ui DISTFILES += conf/config.ini include(common/common.pri) include(device/device.pri) +include(protocol/protocol.pri) # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 3a7a74a..a9a51a7 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -1,11 +1,53 @@ #include "DeviceHubWindow.h" #include "ui_DeviceHubWindow.h" +#include +#include +#include +#include + DeviceHubWindow::DeviceHubWindow(QWidget *parent) : QWidget(parent) , ui(new Ui::DeviceHubWindow) { ui->setupUi(this); + + // 无边框 + this->setWindowFlags(Qt::FramelessWindowHint); + + // 窗口大小为占满一屏 + QRect screenRect = QApplication::desktop()->screenGeometry(); + resize(screenRect.width(), screenRect.height()); + + // 将窗口移动到左上角 + move(0, 0); + ui->exitButt->move(screenRect.width() - 80, 10); + ui->minButt->move(screenRect.width() - 140, 10); + ui->line->setGeometry(0, 59, screenRect.width(), 1); + + // 设置stackWidget的大小 + ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); + + // add forms + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + + + httpReq = new HttpRequestController(this); + // 1. 获取访问接口需要的token + int retCode = this->initHttpToken(); + if (retCode != 200) + { + QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + + QTimer::singleShot(1000, qApp, SLOT(quit())); + } + // 2. 获取字典值:设备类型 + retCode = this->initDictDeviceTypes(); + this->initAllDeviceList(); } DeviceHubWindow::~DeviceHubWindow() @@ -13,3 +55,84 @@ delete ui; } + +void DeviceHubWindow::on_minButt_clicked() +{ + setWindowState(Qt::WindowMinimized | windowState()); +} + +void DeviceHubWindow::on_exitButt_clicked() +{ + QApplication::exit(0); +} + +void DeviceHubWindow::on_devTypeSelect_currentIndexChanged(int index) +{ + ui->stackedWidget->setCurrentIndex(index); + + // + QList typeDevList = ConstCache::getInstance().deviceList.value(ui->devTypeSelect->currentData().toString()); + ui->devSelect->clear(); + for (int var = 0; var < typeDevList.size(); ++var) { + QJsonObject devItem = typeDevList.at(var); + ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } +} + +int DeviceHubWindow::initHttpToken() +{ + QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, + SettingConfig::getInstance().APP_KEY); + return response.find("code")->toInt(); +} + +int DeviceHubWindow::initDictDeviceTypes() +{ + QJsonObject response = httpReq->initDictDeviceType(); + QJsonArray typeArray = response.find("data")->toArray(); + for (int i = 3; i < typeArray.size(); i++) + { + QJsonObject typeItem = typeArray.at(i).toObject(); + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } + + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devTypeSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } + + // + ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); + + return response.find("code")->toInt(); +} + +void DeviceHubWindow::initAllDeviceList() +{ + QMapIterator it(ConstCache::getInstance().deviceTypes); + while (it.hasNext()) + { + it.next(); + QString devType = it.key(); + if (devType == "00" || devType == "01" || devType == "02") + { + continue; + } + httpReq->initDeviceList(devType); + } + + ui->devTypeSelect->setCurrentIndex(0); +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b914a7..8a31cbb 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -3,6 +3,10 @@ #include +#include "common/HttpRequestController.h" +#include "FrequencyTuningForm.h" +#include "SignalGeneratorForm.h" + QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } QT_END_NAMESPACE @@ -15,7 +19,23 @@ DeviceHubWindow(QWidget *parent = nullptr); ~DeviceHubWindow(); +private slots: + void on_minButt_clicked(); + void on_exitButt_clicked(); + void on_devTypeSelect_currentIndexChanged(int index); + private: Ui::DeviceHubWindow *ui; + + // private objects + HttpRequestController * httpReq; + + // forms + FrequencyTuningForm * freqTunForm; + SignalGeneratorForm * signGenForm; + + int initHttpToken(); + int initDictDeviceTypes(); + void initAllDeviceList(); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/DeviceHubWindow.ui b/DeviceHub/DeviceHubWindow.ui index 3558013..cc6ccd0 100644 --- a/DeviceHub/DeviceHubWindow.ui +++ b/DeviceHub/DeviceHubWindow.ui @@ -6,13 +6,135 @@ 0 0 - 800 + 1300 600 - DeviceHubWindow + 设备状态监控 + + + + 20 + 0 + 200 + 60 + + + + + 微软雅黑 + 14 + + + + 设备状态监控 + + + + + + 250 + 0 + 150 + 60 + + + + + 微软雅黑 + 12 + + + + Qt::LeftToRight + + + 请选择设备 + + + Qt::AlignCenter + + + + + + 400 + 10 + 250 + 40 + + + + + + + 700 + 10 + 250 + 40 + + + + + + + 1030 + 10 + 40 + 40 + + + + + + + 退出 + + + + + + 980 + 10 + 40 + 40 + + + + + + + 最小化 + + + + + + 0 + 59 + 1024 + 1 + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + 0 + 60 + 1300 + 640 + + + diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp new file mode 100644 index 0000000..ee7538a --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -0,0 +1,27 @@ +#include "FrequencyTuningForm.h" +#include "ui_FrequencyTuningForm.h" + +FrequencyTuningForm::FrequencyTuningForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FrequencyTuningForm) +{ + ui->setupUi(this); +} + +FrequencyTuningForm::~FrequencyTuningForm() +{ + delete ui; +} + +void FrequencyTuningForm::on_freqTunButt_clicked() +{ + // 获取设备对象 +// QJsonObject devItem = ui->devSelect->currentData().toJsonObject(); + +// freqTunDevice->setComName("FrequencyTuning"); +// freqTunDevice->setBaudRate(devItem.find("baudRate")->toString().toInt()); +// freqTunDevice->setDevCode(devItem.find("deviceNo")->toString()); +// freqTunDevice->setDeviceId(devItem.find("deviceId")->toString()); + +// freqTunDevice->initSerialPort(); +} diff --git a/DeviceHub/FrequencyTuningForm.h b/DeviceHub/FrequencyTuningForm.h new file mode 100644 index 0000000..70fd205 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.h @@ -0,0 +1,25 @@ +#ifndef FREQUENCYTUNINGFORM_H +#define FREQUENCYTUNINGFORM_H + +#include + +namespace Ui { +class FrequencyTuningForm; +} + +class FrequencyTuningForm : public QWidget +{ + Q_OBJECT + +public: + explicit FrequencyTuningForm(QWidget *parent = nullptr); + ~FrequencyTuningForm(); + +private slots: + void on_freqTunButt_clicked(); + +private: + Ui::FrequencyTuningForm *ui; +}; + +#endif // FREQUENCYTUNINGFORM_H diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui new file mode 100644 index 0000000..c440419 --- /dev/null +++ b/DeviceHub/FrequencyTuningForm.ui @@ -0,0 +1,709 @@ + + + FrequencyTuningForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + + 微软雅黑 + 10 + + + + Mock FrequencyTuning + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率输出状态 + + + + + + 120 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 频率调整累积值 + + + + + + 370 + 120 + 100 + 30 + + + + + 微软雅黑 + 10 + + + + 相位调整累积值 + + + + + + 620 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 770 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 输入时钟类别 + + + + + + 920 + 120 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 输入有效性 + + + + + + 220 + 120 + 120 + 30 + + + + + + + 470 + 120 + 120 + 30 + + + + + + + 700 + 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 + 120 + 30 + + + + + + + 420 + 160 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 参考有效 + + + + + + 480 + 160 + 50 + 30 + + + + + + + 550 + 160 + 70 + 30 + + + + + 微软雅黑 + 10 + + + + 移相累计值 + + + + + + 620 + 160 + 120 + 30 + + + + + + + 760 + 160 + 40 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽 + + + + + + 800 + 160 + 120 + 30 + + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率微调设置 + + + + + + 120 + 270 + 100 + 30 + + + + + + + 20 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 相位微调设置 + + + + + + 20 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 移相设置 + + + + + + 20 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步设置 + + + + + + 20 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 秒脉宽设置 + + + + + + 120 + 320 + 100 + 30 + + + + + + + 120 + 370 + 100 + 30 + + + + + + + 120 + 420 + 100 + 30 + + + + + + + 120 + 470 + 100 + 30 + + + + + + + 270 + 270 + 500 + 30 + + + + true + + + + + + 270 + 320 + 500 + 30 + + + + true + + + + + + 270 + 370 + 500 + 30 + + + + true + + + + + + 270 + 420 + 500 + 30 + + + + true + + + + + + 270 + 470 + 500 + 30 + + + + true + + + + + + 800 + 270 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 800 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp new file mode 100644 index 0000000..698ec36 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -0,0 +1,14 @@ +#include "SignalGeneratorForm.h" +#include "ui_SignalGeneratorForm.h" + +SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::SignalGeneratorForm) +{ + ui->setupUi(this); +} + +SignalGeneratorForm::~SignalGeneratorForm() +{ + delete ui; +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h new file mode 100644 index 0000000..0abdeec --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.h @@ -0,0 +1,22 @@ +#ifndef SIGNALGENERATORFORM_H +#define SIGNALGENERATORFORM_H + +#include + +namespace Ui { +class SignalGeneratorForm; +} + +class SignalGeneratorForm : public QWidget +{ + Q_OBJECT + +public: + explicit SignalGeneratorForm(QWidget *parent = nullptr); + ~SignalGeneratorForm(); + +private: + Ui::SignalGeneratorForm *ui; +}; + +#endif // SIGNALGENERATORFORM_H diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui new file mode 100644 index 0000000..e060a66 --- /dev/null +++ b/DeviceHub/SignalGeneratorForm.ui @@ -0,0 +1,1391 @@ + + + SignalGeneratorForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock SignalGenerator + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 300 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 360 + 120 + 120 + 30 + + + + + + + 500 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + 580 + 120 + 50 + 30 + + + + + + + 650 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号类别 + + + + + + 730 + 120 + 50 + 30 + + + + + + + 800 + 120 + 90 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS信号状态 + + + + + + 890 + 120 + 50 + 30 + + + + + + + 960 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS相差 + + + + + + 1020 + 120 + 100 + 30 + + + + + + + 20 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS脉宽 + + + + + + 80 + 170 + 120 + 30 + + + + + + + 220 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相量 + + + + + + 300 + 170 + 120 + 30 + + + + + + + 440 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC调制比 + + + + + + 520 + 170 + 50 + 30 + + + + + + + 590 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + B-AC幅度 + + + + + + 650 + 170 + 50 + 30 + + + + + + + 20 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA日期 + + + + + + 80 + 220 + 120 + 30 + + + + + + + 220 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + ZDA时刻 + + + + + + 280 + 220 + 120 + 30 + + + + + + + 420 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 480 + 220 + 50 + 30 + + + + + + + 550 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 640 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD日期 + + + + + + 700 + 220 + 120 + 30 + + + + + + + 840 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + MJD时刻 + + + + + + 900 + 220 + 120 + 30 + + + + + + + 1040 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 1100 + 220 + 50 + 30 + + + + + + + 1170 + 220 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 有效 + + + + + + 800 + 170 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 键盘控制 + + + + + + 860 + 170 + 50 + 30 + + + + + + + 930 + 170 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示类别 + + + + + + 1010 + 170 + 50 + 30 + + + + + + + 20 + 280 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒设置 + + + + + + 100 + 320 + 100 + 30 + + + + + + + 230 + 320 + 200 + 30 + + + + true + + + + + + 460 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 20 + 370 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 单次同步 + + + + + + 230 + 370 + 200 + 30 + + + + true + + + + + + 460 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 370 + 100 + 30 + + + + + + + 20 + 420 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 年月日 + + + + + + 230 + 420 + 200 + 30 + + + + true + + + + + + 460 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 420 + 100 + 30 + + + + + + + 460 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 470 + 100 + 30 + + + + + + + 20 + 470 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 脉宽设置 + + + + + + 230 + 470 + 200 + 30 + + + + true + + + + + + 460 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 100 + 520 + 100 + 30 + + + + + + + 20 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + AC码调制比 + + + + + + 230 + 520 + 200 + 30 + + + + true + + + + + + 20 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 控制状态 + + + + + + 100 + 590 + 100 + 30 + + + + + + + 230 + 590 + 200 + 30 + + + + true + + + + + + 460 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 时分秒设置 + + + + + + 610 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 1PPS移相 + + + + + + 1050 + 590 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 420 + 100 + 30 + + + + + + + 820 + 590 + 200 + 30 + + + + true + + + + + + 690 + 590 + 100 + 30 + + + + + + + 1050 + 320 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 1050 + 370 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 690 + 320 + 100 + 30 + + + + + + + 820 + 520 + 200 + 30 + + + + true + + + + + + 690 + 520 + 100 + 30 + + + + + + + 820 + 370 + 200 + 30 + + + + true + + + + + + 820 + 420 + 200 + 30 + + + + true + + + + + + 1050 + 520 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 320 + 200 + 30 + + + + true + + + + + + 610 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 儒略日设置 + + + + + + 1050 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 820 + 470 + 200 + 30 + + + + true + + + + + + 1050 + 470 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + send + + + + + + 610 + 320 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + AC码幅度 + + + + + + 690 + 370 + 100 + 30 + + + + + + + 610 + 420 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒时刻设置 + + + + + + 610 + 590 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 时间显示 + + + + + + 690 + 470 + 100 + 30 + + + + + + + diff --git a/DeviceHub/common/ConstCache.h b/DeviceHub/common/ConstCache.h index 6cc831b..6eda79c 100644 --- a/DeviceHub/common/ConstCache.h +++ b/DeviceHub/common/ConstCache.h @@ -20,7 +20,7 @@ } QMap deviceTypes; - QList deviceList; + QMap> deviceList; private: ConstCache() {}; diff --git a/DeviceHub/common/HttpRequestController.cpp b/DeviceHub/common/HttpRequestController.cpp index 7b905b7..d821a33 100644 --- a/DeviceHub/common/HttpRequestController.cpp +++ b/DeviceHub/common/HttpRequestController.cpp @@ -102,22 +102,10 @@ { QJsonObject resultObj; - QString counterDevType = ""; - QMapIterator it(ConstCache::getInstance().deviceTypes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(devType) == true) - { - counterDevType = it.key(); - break; - } - } - // 获取设备列表的接口地址 QUrl url = baseUrl + "/device/list"; QUrlQuery query; - query.addQueryItem("type", counterDevType); + query.addQueryItem("type", devType); url.setQuery(query); QNetworkRequest request; @@ -136,15 +124,17 @@ if (resultObj.find("code")->toInt() == 200) { - ConstCache::getInstance().deviceList.clear(); + QList typeDevList; QJsonArray data = resultObj.find("data")->toArray(); for (int i = 0; i < data.size(); i++) { QJsonObject item = data.at(i).toObject(); - ConstCache::getInstance().deviceList.append(item); + typeDevList.append(item); } + + ConstCache::getInstance().deviceList.insert(devType, typeDevList); } } else { diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8cd10d6..3d52a3d 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" +#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -37,7 +37,7 @@ int baudRate; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; + QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 8e36d3a..e605b15 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -7,9 +7,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } @@ -89,7 +89,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 50e171a..606a985 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/FrequencyTuningProtocolBM.h" +//#include "protocol/FrequencyTuningProtocolBM.h" class FrequencyTuning : public DeviceBase { diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 577db52..b6be288 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,9 +8,9 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 839f22b..6bae208 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,7 @@ #include #include "device/DeviceBase.h" -#include "protocol/SignalGeneratorProtocolBM.h" +//#include "protocol/SignalGeneratorProtocolBM.h" class SignalGenerator : public DeviceBase { diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index c9cc393..bf56460 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/SignalGenerator.h HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h -HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FreqReplicator.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/SignalGenerator.cpp SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp -SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FreqReplicator.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.cpp b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp new file mode 100644 index 0000000..f7353ec --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.cpp @@ -0,0 +1,73 @@ +#include "DeviceStatusProtocolBase.h" +//#include "SignalGeneratorProtocolBM.h" +//#include "FrequencyTuningProtocolBM.h" +//#include "TimeSwitcherProtocolBM.h" +//#include "FreqSwitcherProtocolBM.h" +//#include "TimeReplicatorProtocolBM.h" +//#include "FreqReplicatorProtocolTX.h" +//#include "BCodeTerminalProtocolBM.h" + +#include + +DeviceStatusProtocolBase::DeviceStatusProtocolBase(QObject *parent) : QObject(parent) +{ + +} + +DeviceStatusProtocolBase * DeviceStatusProtocolBase::deviceStatusProtocolFactory(QString deviceType) +{ + std::cout << deviceType.toStdString() << std::endl; +// if (deviceType.contains("SignalGenerator") == true) +// { +// return new SignalGeneratorProtocolBM(); +// } else if (deviceType.contains("FrequencyTuning") == true) +// { +// return new FrequencyTuningProtocolBM(); +// } else if (deviceType.contains("TimeSwitcher") == true) +// { +// return new TimeSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqSwitcher") == true) +// { +// return new FreqSwitcherProtocolBM(); +// } else if (deviceType.contains("FreqReplicator") == true) +// { +// return new FreqReplicatorProtocolTX(); +// } else if (deviceType.contains("TimeReplicator") == true) +// { +// return new TimeReplicatorProtocolBM(); +// } else if (deviceType.contains("BCodeTerminal") == true) +// { +// return new BCodeTerminalProtocolBM(); +// } + + return nullptr; +} + +QByteArray DeviceStatusProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +{ + QByteArray commandBytes; + commandBytes.append(commandType).append(","); + commandBytes.append(valueSet); + + QString xorValue = this->calculateXOR(commandBytes); + + commandBytes.prepend("$"); + commandBytes.append("*"); + commandBytes.append(xorValue); + + return commandBytes; +} + +QString DeviceStatusProtocolBase::calculateXOR(QByteArray byteArray) +{ + quint8 xorValue = 0; + + for (int i =0; i < byteArray.size(); i++) + { + xorValue = xorValue ^ byteArray.at(i); + } + + QString str; + str.sprintf("%02X", xorValue); + return str; +} diff --git a/DeviceHub/protocol/DeviceStatusProtocolBase.h b/DeviceHub/protocol/DeviceStatusProtocolBase.h new file mode 100644 index 0000000..ae3d4cb --- /dev/null +++ b/DeviceHub/protocol/DeviceStatusProtocolBase.h @@ -0,0 +1,124 @@ +#ifndef DEVICESTATUSPROTOCOLBASE_H +#define DEVICESTATUSPROTOCOLBASE_H + +#include +#include "dto/DeviceFrameBaseDto.h" + +static const QString FRAME_TAIL = "\r\n"; // 帧尾 +static const QString FRAME_CONTENT_SEP = ","; // 帧内分隔符 +static const QString FRAME_SUM_SEP = "*"; // 异或和字段的分隔符 +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"; // 帧头 +static const QString SIGNAL_GENERATOR_ZDA_FRAME_HEAD = "$GPZDA"; // 帧头 + +static const QString TIME_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString TIME_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_SWITCHER_INTERFACE_FRAME_HEAD = "$GLC"; // 帧头 +static const QString FREQ_SWITCHER_STATUS_FRAME_HEAD = "$GLF"; // 帧头 + +static const QString FREQ_REPLICATOR_STAUTS_FRAME_HEAD = "AA55"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_HEAD = "$"; +static const QString TIME_REPLICATOR_STATUS_FRAME_TAIL = "*"; + + +static const int FREQUENCY_TUNING_FREQ_FRAME_SUB_COUNT = 26; +static const int FREQUENCY_TUNING_PULSE_FRAME_SUB_COUNT = 5; + +static const int SIGNAL_GENERATOR_INTERFACE_FRAME_SUB_COUNT = 2; +static const int SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT = 11; +static const int SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT = 6; +static const int SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT = 4; + +static const int TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +static const int TIME_SWITCHER_STATUS_FRAME_SUB_COUNT = 24; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT = 1; +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; +static const int SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_ZDA_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_ZDA_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH = SIGNAL_GENERATOR_MJD_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + SIGNAL_GENERATOR_MJD_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = TIME_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH = TIME_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + TIME_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + +static const int FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH = FREQ_SWITCHER_INTERFACE_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_INTERFACE_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; +static const int FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH = FREQ_SWITCHER_STATUS_FRAME_HEAD.length() + + FRAME_TAIL.length() + 1 + FRAME_SUB_MIN_SIZE + + FREQ_SWITCHER_STATUS_FRAME_SUB_COUNT * FRAME_SUB_MIN_SIZE; + + +static const QString FREQUENCY_TUNING_FREQ_FRAME_TYPE = "0301"; +static const QString FREQUENCY_TUNING_PULSE_FRAME_TYPE = "0302"; + +static const QString SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE = "0401"; +static const QString SIGNAL_GENERATOR_STATUS_FRAME_TYPE = "0402"; +static const QString SIGNAL_GENERATOR_MJD_FRAME_TYPE = "0403"; +static const QString SIGNAL_GENERATOR_ZDA_FRAME_TYPE = "0404"; + +static const QString TIME_SWITCHER_STATUS_FRAME_TYPE = "0501"; +static const QString TIME_SWITCHER_INTERFACE_FRAME_TYPE = "0502"; + +static const QString FREQ_SWITCHER_STATUS_FRAME_TYPE = "0601"; +static const QString FREQ_SWITCHER_INTERFACE_FRAME_TYPE = "0602"; + +static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; + +static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; + +static const QString FREQ_REPLICATOR_STATUS_FRAME_TYPE = "1001"; + + +class DeviceStatusProtocolBase : public QObject +{ + Q_OBJECT +public: + explicit DeviceStatusProtocolBase(QObject *parent = nullptr); + + static DeviceStatusProtocolBase * deviceStatusProtocolFactory(QString deviceType); + + QString calculateXOR(QByteArray byteArray); + + virtual DeviceFrameBaseDto * frameFactory(int frameType) = 0; + virtual int checkFrame(QByteArray rawData) = 0; + virtual QList extractFrameList(QByteArray rawData) = 0; + virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * ftFrameData, int frameType) = 0; + virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + +signals: + +}; + +#endif // DEVICESTATUSPROTOCOLBASE_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h new file mode 100644 index 0000000..f14808f --- /dev/null +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -0,0 +1,28 @@ +#ifndef DEVICEFRAMEBASEDTO_H +#define DEVICEFRAMEBASEDTO_H + +#include +#include +#include +#include + +class DeviceFrameBaseDto : public QObject +{ + Q_OBJECT +public: + explicit DeviceFrameBaseDto(QObject *parent = nullptr) {} + + QByteArray rawFrame; // 原始帧字节数组 + + QString timestamp; // 时间戳字符串 + qlonglong milisecond; // 毫秒计数 + QString devCode; + QString frameType; // 帧类型 + + virtual QJsonObject toJSON() = 0; + +signals: + +}; + +#endif // DEVICEFRAMEBASEDTO_H diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri new file mode 100644 index 0000000..671d58c --- /dev/null +++ b/DeviceHub/protocol/protocol.pri @@ -0,0 +1,49 @@ + +HEADERS += $$PWD/dto/DeviceFrameBaseDto.h +#HEADERS += $$PWD/dto/SignalGeneratorStatusDto.h +#HEADERS += $$PWD/dto/SignalGeneratorInterfaceDto.h +#HEADERS += $$PWD/dto/SignalGeneratorZDATimeDto.h +#HEADERS += $$PWD/dto/SignalGeneratorMJDTimeDto.h +#HEADERS += $$PWD/dto/SignalGeneratorSetting.h +#HEADERS += $$PWD/dto/FrequencyTuningStatusFreqDto.h +#HEADERS += $$PWD/dto/FrequencyTuningStatusPulseDto.h +#HEADERS += $$PWD/dto/FrequencyTuningSettingDto.h +#HEADERS += $$PWD/dto/TimeSwitcherStatusDto.h +#HEADERS += $$PWD/dto/TimeSwitcherInterfaceDto.h +#HEADERS += $$PWD/dto/FreqSwitcherInterfaceDto.h +#HEADERS += $$PWD/dto/FreqSwitcherStatusDto.h +#HEADERS += $$PWD/dto/TimeReplicatorStatusDto.h +#HEADERS += $$PWD/dto/FreqReplicatorStatusDto.h +#HEADERS += $$PWD/dto/BCodeTerminalStatusDto.h +HEADERS += $$PWD/DeviceStatusProtocolBase.h +#HEADERS += $$PWD/SignalGeneratorProtocolBM.h +#HEADERS += $$PWD/FrequencyTuningProtocolBM.h +#HEADERS += $$PWD/TimeSwitcherProtocolBM.h +#HEADERS += $$PWD/FreqSwitcherProtocolBM.h +#HEADERS += $$PWD/TimeReplicatorProtocolBM.h +#HEADERS += $$PWD/FreqReplicatorProtocolTX.h +#HEADERS += $$PWD/BCodeTerminalProtocolBM.h + +#SOURCES += $$PWD/dto/SignalGeneratorStatusDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorInterfaceDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorZDATimeDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorMJDTimeDto.cpp +#SOURCES += $$PWD/dto/SignalGeneratorSetting.cpp +#SOURCES += $$PWD/dto/FrequencyTuningStatusFreqDto.cpp +#SOURCES += $$PWD/dto/FrequencyTuningStatusPulseDto.cpp +#SOURCES += $$PWD/dto/FrequencyTuningSettingDto.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/DeviceStatusProtocolBase.cpp +#SOURCES += $$PWD/dto/FreqReplicatorStatusDto.cpp +#SOURCES += $$PWD/dto/BCodeTerminalStatusDto.cpp +#SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp +#SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp +#SOURCES += $$PWD/TimeSwitcherProtocolBM.cpp +#SOURCES += $$PWD/FreqSwitcherProtocolBM.cpp +#SOURCES += $$PWD/TimeReplicatorProtocolBM.cpp +#SOURCES += $$PWD/FreqReplicatorProtocolTX.cpp +#SOURCES += $$PWD/BCodeTerminalProtocolBM.cpp diff --git a/ZXSSCJ.pro b/ZXSSCJ.pro index 6e384bc..0ae1660 100644 --- a/ZXSSCJ.pro +++ b/ZXSSCJ.pro @@ -5,6 +5,6 @@ #SUBDIRS += CounterAcq #计数器数据采集 #SUBDIRS += PhaseCompAcq #比相仪数据采集 -SUBDIRS += DevStatusAcq -SUBDIRS += DeviceHub +#SUBDIRS += DevStatusAcq +SUBDIRS += DeviceHub # #SUBDIRS += HClockAcq #氢钟状态数据采集